"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _layer = require("ol/layer");
var _ol = require("ol");
var _source = require("ol/source");
var _renderer = _interopRequireDefault(require("../renderer"));
var _style5 = require("ol/style");
var _isFunction = _interopRequireDefault(require("../_util/isFunction"));
var _createFeatureCollection = require("./createFeatureCollection");
var _isObject = _interopRequireDefault(require("../_util/isObject"));
var _encryptParams = _interopRequireDefault(require("../_util/encryptParams"));
var _MyCluster = _interopRequireDefault(require("./MyCluster"));
var _excluded = ["url", "params", "data", "dataField", "features", "sourceOptions", "key", "name", "label", "labelField", "point", "cluster", "template", "autoRefresh", "method", "layerControl", "show", "style", "group", "iconOptions", "afterGetData", "legend", "viewOnly", "encrypt", "valueField", "map", "tipTemplate"],
  _excluded2 = ["color", "background", "backgroundStroke", "backgroundStrokeWidth"],
  _excluded3 = ["numberStyle", "iconOptions"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function set(target, property, value, receiver) { if (typeof Reflect !== "undefined" && Reflect.set) { set = Reflect.set; } else { set = function set(target, property, value, receiver) { var base = _superPropBase(target, property); var desc; if (base) { desc = Object.getOwnPropertyDescriptor(base, property); if (desc.set) { desc.set.call(receiver, value); return true; } else if (!desc.writable) { return false; } } desc = Object.getOwnPropertyDescriptor(receiver, property); if (desc) { if (!desc.writable) { return false; } desc.value = value; Object.defineProperty(receiver, property, desc); } else { _defineProperty(receiver, property, value); } return true; }; } return set(target, property, value, receiver); }
function _set(target, property, value, receiver, isStrict) { var s = set(target, property, value, receiver || target); if (!s && isStrict) { throw new TypeError('failed to set property'); } return value; }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var FeatureLayer = /*#__PURE__*/function (_Vector) {
  _inherits(FeatureLayer, _Vector);
  var _super = _createSuper(FeatureLayer);
  function FeatureLayer(_options) {
    var _thisSuper, _this2;
    _classCallCheck(this, FeatureLayer);
    var url = _options.url,
      params = _options.params,
      data = _options.data,
      dataField = _options.dataField,
      features = _options.features,
      sourceOptions = _options.sourceOptions,
      key = _options.key,
      name = _options.name,
      label = _options.label,
      _labelField = _options.labelField,
      point = _options.point,
      cluster = _options.cluster,
      template = _options.template,
      autoRefresh = _options.autoRefresh,
      method = _options.method,
      layerControl = _options.layerControl,
      show = _options.show,
      _style2 = _options.style,
      group = _options.group,
      iconOptions = _options.iconOptions,
      afterGetData = _options.afterGetData,
      legend = _options.legend,
      viewOnly = _options.viewOnly,
      encrypt = _options.encrypt,
      valueField = _options.valueField,
      map = _options.map,
      tipTemplate = _options.tipTemplate,
      other = _objectWithoutProperties(_options, _excluded);
    var props = _objectSpread({}, other);
    props.source = props.source || new _source.Vector(_objectSpread({
      features: features
    }, sourceOptions));
    var defaultShow = show;
    if (group !== null && group !== void 0 && group.length) {
      defaultShow = false;
      if (show) {
        group.map(function (f) {
          if (f.show) {
            defaultShow = true;
          }

          // 将字符函数转化为可执行的函数
          if (f.filter && typeof f.filter === 'string' && f.filter.indexOf('=>') !== -1) {
            f.filter = f.filter.replaceAll(' ', '');
            var _f$filter$split = f.filter.split('=>'),
              _f$filter$split2 = _slicedToArray(_f$filter$split, 2),
              a = _f$filter$split2[0],
              c = _f$filter$split2[1];
            f.filter = new Function(a, "return ".concat(c));
          }
        });
      }
    }
    _this2 = _super.call(this, props);
    _defineProperty(_assertThisInitialized(_this2), "getClusterTextStyle", function (size, options) {
      var _ref = options && _typeof(options) === 'object' ? options : {},
        color = _ref.color,
        background = _ref.background,
        backgroundStroke = _ref.backgroundStroke,
        backgroundStrokeWidth = _ref.backgroundStrokeWidth,
        otherVal = _objectWithoutProperties(_ref, _excluded2);
      var style = _objectSpread({
        text: String(size),
        font: '18px Calibri,sans-serif',
        fill: new _style5.Fill({
          color: color || '#fff'
        }),
        padding: [0, 0, 0, 0],
        justify: 'center',
        textAlign: 'center',
        textBaseline: 'middle',
        offsetY: -22,
        offsetX: 16
      }, otherVal);
      if (background) {
        style.backgroundFill = new _style5.Fill({
          color: background
        });
      }
      if (backgroundStroke) {
        style.backgroundStroke = new _style5.Stroke({
          color: '#FFFFFF',
          width: backgroundStrokeWidth || 2
        });
      }
      return new _style5.Text(style);
    });
    _defineProperty(_assertThisInitialized(_this2), "getLabelStyle", function (feature, color) {
      var labelField = _this2._options.labelField;

      // 判断是否是聚合点位
      if (feature.isCluster) {
        var _feature$get;
        var size = ((_feature$get = feature.get('features')) === null || _feature$get === void 0 ? void 0 : _feature$get.length) || 0;
        if (size !== 1) {
          return;
        }
      }
      if (labelField) {
        return new _style5.Text({
          text: feature.values_[labelField] || '-',
          font: '12px Calibri,sans-serif',
          fill: new _style5.Fill({
            color: color
          }),
          backgroundFill: new _style5.Fill({
            color: '#fff'
          }),
          backgroundStroke: new _style5.Stroke({
            color: color,
            width: 1
          }),
          padding: [4, 2, 2, 4],
          justify: 'center',
          textBaseline: 'middle',
          offsetY: 12
        });
      }
    });
    _set((_thisSuper = _assertThisInitialized(_this2), _getPrototypeOf(FeatureLayer.prototype)), "show", show, _thisSuper, true);
    // 参数
    _this2._options = _options;

    // 地图
    _this2.map = map;

    // 接口地址
    _this2.url = url;

    // 接口地址请求类型
    _this2.method = method;

    // 接口查询参数
    _this2.params = params;

    // 图层标识
    _this2.key = key;

    // 图层名称
    _this2.name = name;

    // 标签
    _this2.label = label;

    // 标签字段
    _this2.labelField = _labelField;

    // 聚合
    _this2.cluster = cluster;

    // 聚合距离
    _this2.distance = (cluster === null || cluster === void 0 ? void 0 : cluster.distance) || 80;

    // 海量点
    _this2.point = point;

    // 自动刷新标识
    _this2.autoRefresh = autoRefresh;

    // 模版内容
    _this2.template = template;

    // 图层控制
    _this2.layerControl = layerControl;

    // 过滤
    _this2.group = group;

    // 处理获取的数据
    _this2.afterGetData = afterGetData;

    // 数据查询字段
    _this2.valueField = valueField;

    // 图例
    _this2.legend = legend;

    // 样式
    _this2.style = _style2;

    // 数据
    _this2.data = data;

    // 数据取值字段
    _this2.dataField = dataField || 'geometryInfo';

    // 仅展示
    _this2.viewOnly = viewOnly;

    // 是否初始化
    _this2.inited = false;

    // 加密
    _this2.encrypt = encrypt;

    // 气泡模板
    _this2.tipTemplate = tipTemplate;

    // 临时数据
    _this2._features = [];

    // 默认是否展示
    if (defaultShow) {
      _this2.init();
    }
    return _this2;
  }

  // 初始化数据
  _createClass(FeatureLayer, [{
    key: "init",
    value: function init() {
      // 是否存在地址
      if (this.url) {
        // 执行
        this.loadUrlData(this.url, this.params, this.method);
      }

      // 直接加载数据
      if (this.data) {
        // 执行
        this.loadData(this.data);
      }
      this.inited = true;
    }

    // 重写父类的属性访问器
  }, {
    key: "show",
    get: function get() {
      return _get(_getPrototypeOf(FeatureLayer.prototype), "show", this);
    },
    set: function set(value) {
      this.setVisible(value);
    }
  }, {
    key: "label",
    set: function set(val) {
      this._options.label = val;
      this.setStyle(this.getStyleByMode());
    }
  }, {
    key: "point",
    set: function set(val) {
      this._options.point = val;
      this.setStyle(this.getStyleByMode());
    }
  }, {
    key: "cluster",
    set: function set(val) {
      this.setClusterMode(val);
    }
  }, {
    key: "setShow",
    value: function setShow(value) {
      this.show = value;
      this.setVisible(value);
    }
  }, {
    key: "destroy",
    value: function destroy() {
      var map = this.map;
      if (this.moveEnd) {
        map.un("moveend", this.moveEnd);
        this.moveEnd = null;
      }
    }
  }, {
    key: "setClusterMode",
    value: function setClusterMode(val) {
      var _this3 = this;
      this._options.cluster = val;
      this.setClusterSource(val);
      this.setStyle(this.getStyleByMode());
      var map = this.map;
      this.destroy();

      // 监听地图缩放大于阈值时取消聚合
      var oldZoom = map.getView().getZoom();
      this.moveEnd = map.on("moveend", function () {
        var zoom = map.getView().getZoom(); //获取当前地图的缩放级别
        if (oldZoom !== zoom) {
          var _this3$_options$clust;
          oldZoom = zoom;
          if (zoom >= (((_this3$_options$clust = _this3._options.cluster) === null || _this3$_options$clust === void 0 ? void 0 : _this3$_options$clust.zoomThreshold) || 14)) {
            _this3.setClusterSource();
          } else {
            _this3.setClusterSource(val);
          }
        }
      });
    }
  }, {
    key: "getStyleByMode",
    value: function getStyleByMode() {
      var _this4 = this;
      return function (feature, resolution) {
        var _this4$group;
        var _this4$_options = _this4._options,
          style = _this4$_options.style,
          cluster = _this4$_options.cluster,
          otherStyle = _this4$_options.otherStyle;
        var show = true;
        (_this4$group = _this4.group) === null || _this4$group === void 0 ? void 0 : _this4$group.map(function (v) {
          var _v$filter;
          if (v !== null && v !== void 0 && (_v$filter = v.filter) !== null && _v$filter !== void 0 && _v$filter.call(v, feature.values_)) {
            style = v.style || style;
            if (v.hasOwnProperty('show') && !v.show) {
              show = false;
            }
          }
        });
        feature.show = show;
        if (!show) {
          return null;
        }
        var styles = [];
        if (otherStyle) {
          if ((0, _isFunction["default"])(otherStyle)) {
            var _styles = otherStyle(feature, resolution);
            if (_styles) {
              if (Array.isArray(styles)) {
                styles.push.apply(styles, _toConsumableArray(_styles));
              } else {
                styles.push(_styles);
              }
            }
          }
        }
        if (style) {
          if (typeof style === 'string' || (0, _isFunction["default"])(style) && cluster) {
            styles.push(new _renderer["default"].Marker(_objectSpread({}, _this4.getMarkerOptions(feature, style))));
            return styles;
          } else if (style instanceof _style5.Style) {
            // 判断是否为 ol Style
            styles.push(style);
            return styles;
          } else if ((0, _isFunction["default"])(style)) {
            // 判断是否为自定义函数渲染

            var _style = style(feature);
            if (_style !== null && _style !== void 0 && _style.type && _style !== null && _style !== void 0 && _style.style) {
              var options = _this4.getSimpleStyle(feature, _style);
              styles.push(_renderer["default"].Simple(options));
              return styles;
            }
            styles.push(_style);
            return styles;
          } else if ((0, _isObject["default"])(style)) {
            var _style3 = style,
              mode = _style3.mode;
            if (mode) {
              if (mode === 'Simple') {
                var _options2 = _this4.getSimpleStyle(feature, style.render);
                styles.push(_renderer["default"].Simple(_options2));
                return styles;
              }
              if (mode === 'UniqueValue') {
                var _feature$get2;
                var size = ((_feature$get2 = feature.get('features')) === null || _feature$get2 === void 0 ? void 0 : _feature$get2.length) || 0;
                if (size > 1) {
                  var _options3 = _this4.getSimpleStyle(feature, style.render.render[0]);
                  styles.push(_renderer["default"].Simple(_options3));
                  return styles;
                }
                var _options4 = _this4.getMultipleStyle(feature, style.render);
                styles.push(_renderer["default"].UniqueValue(feature, _options4));
                return styles;
              }
              if (mode === 'ClassBreaks') {
                var _feature$get3;
                var _size = ((_feature$get3 = feature.get('features')) === null || _feature$get3 === void 0 ? void 0 : _feature$get3.length) || 0;
                if (_size > 1) {
                  var _options5 = _this4.getSimpleStyle(feature, style.render.render[0]);
                  styles.push(_renderer["default"].Simple(_options5));
                  return styles;
                }
                var _options6 = _this4.getMultipleStyle(feature, style.render);
                styles.push(_renderer["default"].ClassBreaks(feature, _options6));
                return styles;
              }
            } else if (style.style) {
              var _options7 = _this4.getSimpleStyle(feature, style);
              styles.push(_renderer["default"].Simple(_options7));
              return styles;
            }
          }
        }
        styles.push(new _style5.Style({
          image: new _style5.Circle({
            radius: 4,
            fill: new _style5.Fill({
              color: 'rgba(0,155,255, 0.8)'
            })
          }),
          fill: new _style5.Fill({
            color: 'rgba(255, 255, 255, 0.6)'
          }),
          stroke: new _style5.Stroke({
            color: '#009BFF',
            width: 2
          })
        }));
        return styles;
      };
    }
  }, {
    key: "getSimpleStyle",
    value: function getSimpleStyle(feature, _render) {
      var _render$style, _render$style2;
      var cluster = this._options.cluster;
      var render = _objectSpread({}, _render);
      if (render.type === 'Marker' && (render !== null && render !== void 0 && (_render$style = render.style) !== null && _render$style !== void 0 && _render$style.icon || cluster && render !== null && render !== void 0 && (_render$style2 = render.style) !== null && _render$style2 !== void 0 && _render$style2.image)) {
        render.style = _objectSpread(_objectSpread({}, render.style), this.getMarkerOptions(feature, render.style));
      }
      return render;
    }
  }, {
    key: "getMultipleStyle",
    value: function getMultipleStyle(feature, _render) {
      var _render$render,
        _this5 = this;
      var render = _objectSpread({}, _render);
      if (render !== null && render !== void 0 && (_render$render = render.render) !== null && _render$render !== void 0 && _render$render.length) {
        render.render = render.render.map(function (v) {
          return _this5.getSimpleStyle(feature, v);
        });
      }
      return render;
    }
  }, {
    key: "getMarkerOptions",
    value: function getMarkerOptions(feature, style) {
      var _feature$get4;
      var icon = (style === null || style === void 0 ? void 0 : style.icon) || style;
      var image = style === null || style === void 0 ? void 0 : style.image;
      var color = (style === null || style === void 0 ? void 0 : style.color) || '#2491fc';
      var _this$_options = this._options,
        cluster = _this$_options.cluster,
        point = _this$_options.point,
        label = _this$_options.label;

      // 判断是否为自定义函数渲染
      var isFun = (0, _isFunction["default"])(style);
      var data = {};
      if (isFun) {
        var _data, _data$style, _data2, _data3, _data3$style, _data4, _data5, _data5$style, _data6;
        data = style(feature) || {};
        icon = ((_data = data) === null || _data === void 0 ? void 0 : (_data$style = _data.style) === null || _data$style === void 0 ? void 0 : _data$style.icon) || ((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.icon) || icon;
        color = ((_data3 = data) === null || _data3 === void 0 ? void 0 : (_data3$style = _data3.style) === null || _data3$style === void 0 ? void 0 : _data3$style.color) || ((_data4 = data) === null || _data4 === void 0 ? void 0 : _data4.color) || color;
        image = ((_data5 = data) === null || _data5 === void 0 ? void 0 : (_data5$style = _data5.style) === null || _data5$style === void 0 ? void 0 : _data5$style.image) || ((_data6 = data) === null || _data6 === void 0 ? void 0 : _data6.image) || image;
      }
      var size = ((_feature$get4 = feature.get('features')) === null || _feature$get4 === void 0 ? void 0 : _feature$get4.length) || 0;
      var P = {
        marker: {
          // 图标
          icon: icon
        },
        point: {
          // 点位
          icon: icon,
          type: 'PointIcon'
        },
        marker_cluster: _objectSpread({
          // 聚合图标
          icon: icon,
          color: size > 1 ? '' : color,
          iconOptions: size > 1 ? _objectSpread({
            hideFooter: true,
            info: {
              text: '',
              fontSize: 18
            }
          }, (cluster === null || cluster === void 0 ? void 0 : cluster.iconOptions) || {}) : {}
        }, size > 1 ? cluster === null || cluster === void 0 ? void 0 : cluster.style : cluster === null || cluster === void 0 ? void 0 : cluster.commonStyle),
        point_cluster: _objectSpread({
          // 聚合点位
          icon: icon,
          type: 'PointIcon',
          iconOptions: size > 1 ? {
            text: size
          } : {}
        }, size > 1 && (cluster === null || cluster === void 0 ? void 0 : cluster.style))
      };
      var type = point ? 'point' : 'marker';
      if (cluster) {
        if ((0, _isObject["default"])(cluster)) {
          if (cluster.show) {
            type = 'marker_cluster';
            if (point) {
              type = 'point_cluster';
            }
          }
        } else {
          type = 'marker_cluster';
          if (point) {
            type = 'point_cluster';
          }
        }
      }
      var _style = P[type];
      if (label) {
        var _Object$keys;
        if ((_Object$keys = Object.keys(data)) !== null && _Object$keys !== void 0 && _Object$keys.includes('customText')) {
          var _data7;
          _style.text = (_data7 = data) === null || _data7 === void 0 ? void 0 : _data7.customText;
        } else {
          _style.text = this.getLabelStyle(feature, color);
        }
      }
      if (feature.isCluster && size > 1 && type === 'marker_cluster') {
        _style.text = this.getClusterTextStyle(size);
      }
      return _style;
    }
  }, {
    key: "setClusterSource",
    value: function setClusterSource(cluster) {
      var _this$_features,
        _this6 = this;
      var _this = this;
      var _ref2 = (0, _isObject["default"])(cluster) ? cluster : {
          show: cluster
        },
        show = _ref2.show,
        minDistance = _ref2.minDistance,
        distance = _ref2.distance,
        group = _ref2.group;
      var source = new _source.Vector({
        features: (_this$_features = this._features) === null || _this$_features === void 0 ? void 0 : _this$_features.filter(function (v) {
          return !v.hasOwnProperty('show') || v.show;
        })
      });
      if (show) {
        group = group || this.group;
        var clusterSource = new _MyCluster["default"](_objectSpread({
          distance: distance || 100,
          minDistance: minDistance || 50,
          source: source,
          group: group,
          createCluster: function createCluster(point, features) {
            var _group;
            var feature = new _ol.Feature({
              geometry: point,
              features: features.map(function (v) {
                v.layerKey = _this.key;
                return v;
              })
            });
            if ((_group = group) !== null && _group !== void 0 && _group.length) {
              var _group2;
              var style;
              var f = features[0];
              var size = features.length;
              (_group2 = group) === null || _group2 === void 0 ? void 0 : _group2.map(function (v) {
                var _v$filter2;
                if (v !== null && v !== void 0 && (_v$filter2 = v.filter) !== null && _v$filter2 !== void 0 && _v$filter2.call(v, f.values_)) {
                  style = v.style || style;
                }
              });
              var markerStyle = _objectSpread({}, style.style);
              if (size > 1) {
                var _style4, _markerStyle2;
                if ((_style4 = style) !== null && _style4 !== void 0 && _style4.clusterStyle) {
                  markerStyle = _objectSpread({}, style.clusterStyle);
                }
                var _markerStyle = markerStyle,
                  numberStyle = _markerStyle.numberStyle,
                  iconOptions = _markerStyle.iconOptions,
                  otherStyle = _objectWithoutProperties(_markerStyle, _excluded3);
                markerStyle = _objectSpread(_objectSpread({}, otherStyle), {}, {
                  text: _this6.getClusterTextStyle((_markerStyle2 = markerStyle) !== null && _markerStyle2 !== void 0 && _markerStyle2.image ? size : ' ', numberStyle),
                  iconOptions: _objectSpread({
                    hideFooter: true,
                    info: {
                      text: size,
                      fontSize: 18
                    }
                  }, iconOptions || (cluster === null || cluster === void 0 ? void 0 : cluster.iconOptions) || {})
                });
              }
              var _style = new _renderer["default"].Marker(markerStyle);
              feature.setStyle(_style);
            }

            // 增加聚合点位标识
            feature.isCluster = true;
            if (features.length === 1) {
              feature.setProperties(features[0].values_);
            }
            return feature;
          }
        }, cluster));
        this.setSource(clusterSource);
      } else {
        this.setSource(source);
      }
    }
  }, {
    key: "refresh",
    value: function refresh() {
      var _this7 = this;
      (0, _createFeatureCollection.getDataByHttpByParams)({
        url: this.url,
        params: this.params,
        method: this.method,
        afterGetData: this.afterGetData,
        field: this.dataField
      }).then(function (features) {
        if (features) {
          var new_features = features;
          _this7._features = new_features;
          var newFeatures = [];
          new_features.map(function (v) {
            var f = _this7.getFeatureByFieldValue('id', v.values_.id);
            if (f) {
              f.values_ = v.values_;
            } else {
              newFeatures.push(v);
            }
          });
          if (newFeatures.length) {
            _this7.getSource().addFeatures(newFeatures);
          }
          _this7.getSource().changed();
        }
      });
    }
  }, {
    key: "loadData",
    value: function loadData(data) {
      this.getSource().clear();
      var features = (0, _createFeatureCollection.createGeoJson)(data);
      this.getSource().addFeatures(features);
      this._features = features;
      if (this._options.cluster) {
        this.setClusterMode(this._options.cluster);
      }
    }
  }, {
    key: "loadUrlData",
    value: function loadUrlData(url, params, method) {
      var _this8 = this;
      var afterGetData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : this.afterGetData;
      this.getSource().clear();
      this._features = [];
      if (this.encrypt) {
        params = (0, _encryptParams["default"])(params, this.encrypt);
      }
      (0, _createFeatureCollection.getDataByHttpByParams)({
        url: url,
        params: params,
        method: method,
        afterGetData: afterGetData,
        field: this.dataField
      }).then(function (features) {
        if (features !== null && features !== void 0 && features.length) {
          _this8._features = features;
          _this8.getSource().addFeatures(features);
        }
        if (_this8._options.cluster) {
          _this8.setClusterMode(_this8._options.cluster);
        }
      });
    }
  }, {
    key: "loadFeatures",
    value: function loadFeatures(features) {
      this.getSource().clear();
      this.getSource().addFeatures(features);
      this._features = features;
      if (this._options.cluster) {
        this.setClusterMode(this._options.cluster);
      }
    }
  }, {
    key: "getFeatures",
    value: function getFeatures() {
      var source = this.getSource().source || this.getSource();
      return source.getFeatures();
    }
  }, {
    key: "getFeatureByFieldValue",
    value: function getFeatureByFieldValue(field, value) {
      return this.getFeatures().find(function (v) {
        return v.values_[field] === value;
      });
    }
  }, {
    key: "getFeaturesByFieldValueOpera",
    value: function getFeaturesByFieldValueOpera(_ref3) {
      var _this9 = this;
      var field = _ref3.field,
        value = _ref3.value,
        _ref3$operation = _ref3.operation,
        operation = _ref3$operation === void 0 ? '===' : _ref3$operation,
        features = _ref3.features,
        filter = _ref3.filter;
      return new Promise(function (resolve, reject) {
        var _features = features || _this9.getFeatures();
        if (filter) {
          _features = _features.filter(function (feature) {
            return filter(feature.values_);
          });
        }
        var result = _features;
        if (operation && value !== undefined) {
          if (['>', '>=', '<', '<=', '===', '!=='].includes(operation)) {
            try {
              // 通过动态创建方法自动传入操作符
              var fun = new Function('features', 'field', 'value', "return features.filter(v => v.values_[field] ".concat(operation, " value)"));
              result = fun(_features, field, value);
            } catch (err) {
              reject(err);
            }
          } else if (operation === 'like') {
            // 包含
            result = _features.filter(function (v) {
              var _v$values_$field;
              return ((_v$values_$field = v.values_[field]) === null || _v$values_$field === void 0 ? void 0 : _v$values_$field.indexOf(value)) !== -1;
            });
          } else if (operation === 'notLike') {
            // 不包含
            result = _features.filter(function (v) {
              var _v$values_$field2;
              return ((_v$values_$field2 = v.values_[field]) === null || _v$values_$field2 === void 0 ? void 0 : _v$values_$field2.indexOf(value)) === -1;
            });
          } else {
            result = _features.filter(function (v) {
              var _v$values_$field3;
              return ((_v$values_$field3 = v.values_[field]) === null || _v$values_$field3 === void 0 ? void 0 : _v$values_$field3.indexOf(value)) !== -1;
            });
          }
        }
        resolve(result);
      });
    }

    // 获取地图
  }, {
    key: "getMap",
    value: function getMap() {
      return this.map;
    }

    // 设置过滤条件
  }, {
    key: "setGroup",
    value: function setGroup(group) {
      if (group !== null && group !== void 0 && group.length) {
        var _this$_features2;
        if ((_this$_features2 = this._features) !== null && _this$_features2 !== void 0 && _this$_features2.length) {
          this._features.map(function (feature) {
            var show = true;
            group.map(function (v) {
              var _v$filter3;
              if (v !== null && v !== void 0 && (_v$filter3 = v.filter) !== null && _v$filter3 !== void 0 && _v$filter3.call(v, feature.values_)) {
                if (v.hasOwnProperty('show') && !v.show) {
                  show = false;
                }
              }
            });
            feature.show = show;
          });
        }
        this.group = group;
        this.setVisibleByGroup();
        if (this._options.cluster) {
          this.setClusterMode(this._options.cluster);
        } else {
          this.setStyle(this.getStyleByMode());
        }
      }
    }

    // 根据过滤条件组显示图层
  }, {
    key: "setVisibleByGroup",
    value: function setVisibleByGroup() {
      var group = this.group;
      if (group !== null && group !== void 0 && group.length) {
        var visible = false;
        group.map(function (v) {
          if (!v.hasOwnProperty('show') || v.show) {
            visible = true;
          }
        });
        this.setVisible(visible);
      }
    }

    // 设置图层显示隐藏
  }, {
    key: "setVisible",
    value: function setVisible(visible) {
      _get(_getPrototypeOf(FeatureLayer.prototype), "setVisible", this).call(this, visible); // 将属性传递给父类

      var map = this.getMap && this.getMap();
      if (map) {
        map.layers.onChange();
      }

      // 判断是否完成过初始化，没有的话就加载一波数据
      if (!this.inited) {
        this.init();
      }
    }
  }]);
  return FeatureLayer;
}(_layer.Vector);
var _default = FeatureLayer;
exports["default"] = _default;
//# sourceMappingURL=FeatureLayer.js.map
