"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 _style6 = 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 _stringToFun = _interopRequireDefault(require("../_util/stringToFun"));
var _convertCamelToCSS = _interopRequireDefault(require("../convertCamelToCSS"));
var _MyCluster = _interopRequireDefault(require("./MyCluster"));
var _Marker = require("../marker/Marker");
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", "alarmBg", "cancelPopup"],
  _excluded2 = ["color", "background", "backgroundStroke", "backgroundStrokeWidth"],
  _excluded3 = ["type", "iconSrc", "color", "scale"],
  _excluded4 = ["numberStyle", "iconOptions"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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 _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _superPropSet(t, e, o, r, p, f) { return _set(_getPrototypeOf(f ? t.prototype : t), e, o, r, p); }
function set(e, r, t, o) { return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function (e, r, t, o) { var f, i = _superPropBase(e, r); if (i) { if ((f = Object.getOwnPropertyDescriptor(i, r)).set) return f.set.call(o, t), !0; if (!f.writable) return !1; } if (f = Object.getOwnPropertyDescriptor(o, r)) { if (!f.writable) return !1; f.value = t, Object.defineProperty(o, r, f); } else _defineProperty(o, r, t); return !0; }, set(e, r, t, o); }
function _set(e, r, t, o, f) { if (!set(e, r, t, o || e) && f) throw new TypeError("failed to set property"); return t; }
function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var addOverlay = function addOverlay(feature, map, alarmBg) {
  if (alarmBg) {
    var itemVal = alarmBg.find(function (v) {
      return v.filter(feature.values_);
    });
    if (itemVal) {
      var image = itemVal.image,
        style = itemVal.style;
      var dom;
      if (image) {
        dom = document.createElement('img');
        dom.src = image;
      } else {
        dom = document.createElement('div');
        dom.className = "ol-map-icon-alarm";
      }
      if (style) {
        dom.style.cssText = style;
      }
      var overlay = new _ol.Overlay({
        element: dom,
        positioning: 'bottom-center',
        stopEvent: true,
        className: 'ol-overlay_container-stop_event'
      });
      map.addOverlay(overlay);
      overlay.setPosition(feature.getGeometry().getCoordinates());
      return overlay;
    }
  }
};
var FeatureLayer = /*#__PURE__*/function (_Vector) {
  function FeatureLayer(_options) {
    var _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,
      alarmBg = _options.alarmBg,
      cancelPopup = _options.cancelPopup,
      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;
          }

          // 将字符函数转化为可执行的函数
          f.filter = (0, _stringToFun["default"])(f.filter);
        });
      }
    }
    _this2 = _callSuper(this, FeatureLayer, [props]);
    _defineProperty(_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 _style6.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 _style6.Fill({
          color: background
        });
      }
      if (backgroundStroke) {
        style.backgroundStroke = new _style6.Stroke({
          color: '#FFFFFF',
          width: backgroundStrokeWidth || 2
        });
      }
      return new _style6.Text(style);
    });
    _defineProperty(_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 _style6.Text({
          text: feature.values_[labelField] || '-',
          font: '12px Calibri,sans-serif',
          fill: new _style6.Fill({
            color: color
          }),
          backgroundFill: new _style6.Fill({
            color: '#fff'
          }),
          backgroundStroke: new _style6.Stroke({
            color: color,
            width: 1
          }),
          padding: [4, 2, 2, 4],
          justify: 'center',
          textBaseline: 'middle',
          offsetY: 12
        });
      }
    });
    _superPropSet((_this2, FeatureLayer), "show", show, _this2, 1, 1);
    // 参数
    _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.cancelPopup = cancelPopup;

    // 报警背景
    if (alarmBg) {
      _this2.alarmBg = (Array.isArray(alarmBg) ? alarmBg : [alarmBg]).map(function (item) {
        var filter = item.filter,
          style = item.style;
        filter = (0, _stringToFun["default"])(filter);
        if (style) {
          style = item.style && _typeof(item.style) === 'object' ? style : {
            color: style
          };
          style = (0, _convertCamelToCSS["default"])(style);
        }
        return _objectSpread(_objectSpread({}, item), {}, {
          filter: filter,
          style: style
        });
      });
    }

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

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

  // 初始化数据
  _inherits(FeatureLayer, _Vector);
  return _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 _superPropGet(FeatureLayer, "show", this, 1);
    },
    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: "setClusterMode",
    value: function setClusterMode(val) {
      var _this3 = this;
      var _ref2 = (0, _isObject["default"])(val) ? val : {
          show: val
        },
        show = _ref2.show;
      this.setClusterSource(val);
      this.setStyle(this.getStyleByMode());
      if (this.map && show) {
        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: "getCustomClusterStyle",
    value: function getCustomClusterStyle(feature, clusterStyle) {
      var _feature$get2;
      var type = clusterStyle.type,
        iconSrc = clusterStyle.iconSrc,
        color = clusterStyle.color,
        _clusterStyle$scale = clusterStyle.scale,
        scale = _clusterStyle$scale === void 0 ? 1 : _clusterStyle$scale,
        iconOptions = _objectWithoutProperties(clusterStyle, _excluded3);
      var size = ((_feature$get2 = feature.get('features')) === null || _feature$get2 === void 0 ? void 0 : _feature$get2.length) || 0;
      return [new _renderer["default"].Marker({
        image: (0, _Marker.getImgUrl)(type || 'CommonIcon', {
          color: color || '#2491fc',
          hideFooter: true,
          info: {
            text: '',
            fontSize: 18
          }
        }),
        text: this.getClusterTextStyle(size)
      }), new _renderer["default"].Marker(_objectSpread({
        image: iconSrc,
        scale: scale || 1,
        anchor: [1.1, 1.25]
      }, iconOptions))];
    }
  }, {
    key: "getStyleByMode",
    value: function getStyleByMode() {
      var _this4 = this;
      return function (feature, resolution) {
        var _feature$get3, _this4$group, _cluster$style;
        var size = ((_feature$get3 = feature.get('features')) === null || _feature$get3 === void 0 ? void 0 : _feature$get3.length) || 0;
        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 || _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 (size > 1 && cluster !== null && cluster !== void 0 && (_cluster$style = cluster.style) !== null && _cluster$style !== void 0 && _cluster$style.iconSrc) {
          return _this4.getCustomClusterStyle(feature, cluster.style);
        }
        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 _style6.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') {
                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') {
                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 _style6.Style({
          image: new _style6.Circle({
            radius: 4,
            fill: new _style6.Fill({
              color: 'rgba(0,155,255, 0.8)'
            })
          }),
          fill: new _style6.Fill({
            color: 'rgba(255, 255, 255, 0.6)'
          }),
          stroke: new _style6.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 iconSize = (style === null || style === void 0 ? void 0 : style.size) || null;
      var hideFooter = (style === null || style === void 0 ? void 0 : style.hideFooter) || null;
      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, _data2, _data3, _data4, _data5, _data6, _data7, _data8, _data9, _data10;
        data = style(feature) || {};
        icon = ((_data = data) === null || _data === void 0 || (_data = _data.style) === null || _data === void 0 ? void 0 : _data.icon) || ((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.icon) || icon;
        color = ((_data3 = data) === null || _data3 === void 0 || (_data3 = _data3.style) === null || _data3 === void 0 ? void 0 : _data3.color) || ((_data4 = data) === null || _data4 === void 0 ? void 0 : _data4.color) || color;
        image = ((_data5 = data) === null || _data5 === void 0 || (_data5 = _data5.style) === null || _data5 === void 0 ? void 0 : _data5.image) || ((_data6 = data) === null || _data6 === void 0 ? void 0 : _data6.image) || image;
        iconSize = ((_data7 = data) === null || _data7 === void 0 || (_data7 = _data7.style) === null || _data7 === void 0 ? void 0 : _data7.size) || ((_data8 = data) === null || _data8 === void 0 ? void 0 : _data8.size) || iconSize;
        hideFooter = ((_data9 = data) === null || _data9 === void 0 || (_data9 = _data9.style) === null || _data9 === void 0 ? void 0 : _data9.hideFooter) || ((_data10 = data) === null || _data10 === void 0 ? void 0 : _data10.hideFooter) || hideFooter;
      }
      var size = ((_feature$get4 = feature.get('features')) === null || _feature$get4 === void 0 ? void 0 : _feature$get4.length) || 0;
      var iconOptions = {
        size: iconSize,
        hideFooter: hideFooter
      };
      var P = {
        marker: {
          // 图标
          icon: icon,
          image: image,
          iconOptions: iconOptions
        },
        point: {
          // 点位
          icon: icon,
          type: 'PointIcon',
          iconOptions: iconOptions
        },
        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 _data11;
          _style.text = (_data11 = data) === null || _data11 === void 0 ? void 0 : _data11.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;
      cluster = (0, _isObject["default"])(cluster) ? cluster : {
        show: cluster
      };
      var _cluster = cluster,
        show = _cluster.show,
        minDistance = _cluster.minDistance,
        distance = _cluster.distance,
        group = _cluster.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,
          clusterChange: function clusterChange(features) {
            _this6.setAlarmBgByFeatures(features);
          },
          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, _groupItem;
              var style, groupItem;
              var f = features[0];
              var size = features.length;
              (_group2 = group) === null || _group2 === 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;
                  groupItem = v;
                }
              });
              var markerStyle = _objectSpread({}, style.style);
              if (size > 1 && (_groupItem = groupItem) !== null && _groupItem !== void 0 && (_groupItem = _groupItem.clusterStyle) !== null && _groupItem !== void 0 && _groupItem.iconSrc) {
                var _style = _this6.getCustomClusterStyle(feature, groupItem.clusterStyle);
                feature.setStyle(_style);
              } else {
                if (size > 1) {
                  var _style4, _markerStyle2, _cluster2;
                  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, _excluded4);
                  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 || ((_cluster2 = cluster) === null || _cluster2 === void 0 ? void 0 : _cluster2.iconOptions) || {})
                  });
                }
                var _style5 = new _renderer["default"].Marker(markerStyle);
                feature.setStyle(_style5);
              }
            }

            // 增加聚合点位标识
            feature.isCluster = true;
            if (features.length === 1) {
              feature.setProperties(features[0].values_);
            }
            return feature;
          }
        }, cluster));
        this.setSource(clusterSource);
      } else {
        this.setSource(source);
      }
    }

    // 清除报警背景
  }, {
    key: "clearAlarmBg",
    value: function clearAlarmBg() {
      var _this$overlays,
        _this7 = this;
      if (this.map && (_this$overlays = this.overlays) !== null && _this$overlays !== void 0 && _this$overlays.length) {
        this.overlays.map(function (overlay) {
          return _this7.map.removeOverlay(overlay);
        });
        this.overlays = null;
      }
    }

    // 设置报警背景
  }, {
    key: "setAlarmBgByFeatures",
    value: function setAlarmBgByFeatures(features) {
      var _this8 = this;
      this.clearAlarmBg();
      this.overlays = [];
      if (this.map && this.alarmBg && features !== null && features !== void 0 && features.length) {
        features.map(function (feature) {
          var _feature = feature;
          var cluster = feature.get('features');
          if (cluster) {
            _feature = cluster.length < 2 ? cluster[0] : null;
          }
          if (_feature && (_feature.hasOwnProperty('show') ? _feature.show : true)) {
            var overlay = addOverlay(_feature, _this8.map, _this8.alarmBg);
            if (overlay) {
              _this8.overlays.push(overlay);
            }
          }
        });
      }
    }
  }, {
    key: "refresh",
    value: function refresh() {
      var _this9 = 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;
          _this9._features = new_features;
          var newFeatures = [];
          new_features.map(function (v) {
            var f = _this9.getFeatureByFieldValue('id', v.values_.id);
            if (f) {
              f.values_ = v.values_;
            } else {
              newFeatures.push(v);
            }
          });
          if (newFeatures.length) {
            _this9.getSource().addFeatures(newFeatures);
            _this9.setAlarmBgByFeatures(_this9.getSource().getFeatures());
          }
          _this9.getSource().changed();
        }
      });
    }
  }, {
    key: "loadData",
    value: function loadData(data) {
      this.getSource().clear();
      var features = (0, _createFeatureCollection.createGeoJson)(data);
      this.getSource().addFeatures(features);
      this.setAlarmBgByFeatures(this.getSource().getFeatures());
      this._features = features;
      if (this._options.cluster) {
        this.setClusterMode(this._options.cluster);
      }
    }
  }, {
    key: "loadUrlData",
    value: function loadUrlData(url, params, method) {
      var _this10 = 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) {
        _this10.getSource().clear();
        _this10._features = [];
        if (features !== null && features !== void 0 && features.length) {
          _this10._features = features;
          _this10.getSource().addFeatures(features);
          _this10.setAlarmBgByFeatures(_this10.getSource().getFeatures());
        }
        if (_this10._options.cluster) {
          _this10.setClusterMode(_this10._options.cluster);
        }
      });
    }
  }, {
    key: "loadFeatures",
    value: function loadFeatures(features) {
      this.getSource().clear();
      this.getSource().addFeatures(features);
      this.setAlarmBgByFeatures(this.getSource().getFeatures());
      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 _this11 = 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 || _this11.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;
              v.filter = (0, _stringToFun["default"])(v.filter);
              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());
        }
        this.setAlarmBgByFeatures(this._features);
      }
    }

    // 根据过滤条件组显示图层
  }, {
    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) {
      _superPropGet(FeatureLayer, "setVisible", this, 3)([visible]); // 将属性传递给父类

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

      // 判断是否完成过初始化，没有的话就加载一波数据
      if (!this.inited) {
        this.init();
      }
      if (!visible) {
        this.clearAlarmBg();
      } else {
        this.setAlarmBgByFeatures(this.getSource().getFeatures());
      }
    }
  }, {
    key: "clearMoveEnd",
    value: function clearMoveEnd() {
      var map = this.map;
      if (map && this.moveEnd) {
        map.un('moveend', this.moveEnd);
        this.moveEnd = null;
      }
    }
  }, {
    key: "destroy",
    value: function destroy() {
      this.clearMoveEnd();
      this.clearAlarmBg();
    }
  }]);
}(_layer.Vector);
var _default = exports["default"] = FeatureLayer;
//# sourceMappingURL=FeatureLayer.js.map
