"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _antd = require("antd");
var _source = require("ol/source");
var _layer = require("ol/layer");
var _style = require("ol/style");
var _Fill = _interopRequireDefault(require("../../renderer/Fill"));
var _ol = require("ol");
var _FeatureLayer = _interopRequireDefault(require("../../feature-layer/FeatureLayer"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 _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 _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 Highlight = exports["default"] = /*#__PURE__*/function () {
  function Highlight(_options) {
    var _this = this;
    _classCallCheck(this, Highlight);
    // 高亮图层增加feature
    _defineProperty(this, "addHighlightFeature", function (feature, options) {
      _this.feature = feature;
      _this.clearSelectFeature();
      _this.clearFeatures();
      if ((0, _lodash.isEmpty)(feature)) return;
      // 数组高亮的话， 就是默认的红色高亮
      if (Array.isArray(feature)) {
        feature.map(function (v) {
          _this.addFeature(v, true);
        });
      } else {
        _this.addFeature(feature);
      }
      if (!options || options !== null && options !== void 0 && options.autoView) {
        _this.map.fitView(feature, options || {});
      }

      // this.map.getView().fit(feature.values_.geometry.getExtent(), {
      //   maxZoom: 18,
      //   duration: 500,
      // });
    });
    _defineProperty(this, "addFeature", function (_feature, flag) {
      var feature = _feature.clone();
      feature.isHighLight = true;
      var geometry = feature === null || feature === void 0 ? void 0 : feature.getGeometry();
      var type = geometry === null || geometry === void 0 ? void 0 : geometry.getType();
      if (type === 'Point' && geometry && !flag) {
        _this.addPointHighlight(feature);
        var layer = _this.map.getLayerByFeature(_feature);
        if (layer && layer instanceof _FeatureLayer["default"]) {
          _this.markerLayer._options = layer._options;
          for (var i in layer._options) {
            _this.markerLayer[i] = layer._options[i];
          }
          feature.key = layer.key;
          _this.markerLayer.cluster = false;
          _this.markerLayer.key = 'Highlight';
          _this.markerLayer.setZIndex(Infinity);
          _this.markerLayer.getSource().addFeature(feature);
          _this.markerLayer.setStyle(_this.markerLayer.getStyleByMode());
        }
      } else {
        _this.source.addFeature(feature);
      }
    });
    // 点位高亮-扩散
    _defineProperty(this, "addPointHighlight", function (feature) {
      var _id = feature.get('id') || 'point_animation';
      _this.clearFeatures();
      var point_overlay = _this.map.getOverlayById(_id);
      if (feature) {
        var geometry = feature === null || feature === void 0 ? void 0 : feature.getGeometry();
        var type = geometry === null || geometry === void 0 ? void 0 : geometry.getType();
        if (type === 'Point' && geometry) {
          var ele = document.createElement('div');
          ele.className = 'ol-map-point_animation';
          if (!point_overlay) {
            point_overlay = new _ol.Overlay({
              id: _id,
              element: ele,
              positioning: 'center-center',
              stopEvent: true,
              className: 'ol-overlay_container-stop_event'
            });
            _this.pointOverlay = point_overlay;
          }
          _this.map.addOverlay(point_overlay);
          point_overlay.setPosition(geometry.getFlatCoordinates());
        }
      }
    });
    _defineProperty(this, "setCenter", function (field, fieldName) {
      var filterField = fieldName || 'code';
      _this.clearSelectFeature();
      var newFeature;
      if (_this.feature && Array.isArray(_this.feature)) {
        newFeature = _this.feature.find(function (v) {
          return v.get(filterField) === field;
        });
      } else if (_this.feature && _this.feature.get(filterField) === field) {
        newFeature = _this.feature;
      }
      _this.selectFeature = newFeature;
      if (newFeature) {
        newFeature.setStyle();
        _this.map.getView(newFeature);
        _this.setSelectFeature(newFeature);
      } else {
        _antd.message.warning(_this.TextEnum.dataNotFoundOnMap);
      }
    });
    this.highStyle = new _style.Style({
      // 高亮样式
      image: new _style.Circle({
        radius: 7,
        fill: new _Fill["default"]({
          color: '#ff4d4f'
        }),
        stroke: new _style.Stroke({
          color: '#FFFFFF',
          width: 2
        })
      }),
      fill: new _Fill["default"]({
        color: '#ff4d4f',
        opacity: 0.5
      }),
      stroke: new _style.Stroke({
        color: '#ff4d4f',
        width: 5
      })
    });
    this.map = _options.map;
    this.TextEnum = _options.TextEnum;
    this.feature = _options.feature;
    this.selectFeature = null;
    this.pointOverlay = null;
    this.source = new _source.Vector();
    this.layer = new _layer.Vector(_objectSpread({
      source: this.source,
      zIndex: 999,
      style: this.highStyle
    }, _options.parmas || {}));
    this.layer.key = 'Highlight';
    this.map.addLayer(this.layer);
    this.markerLayer = new _FeatureLayer["default"]({
      key: 'Highlight',
      zIndex: Infinity
    });
    this.map.addLayer(this.markerLayer);
  }
  return _createClass(Highlight, [{
    key: "clearSelectFeature",
    value: function clearSelectFeature() {
      if (this.selectFeature) {
        this.selectFeature.setStyle();
        this.selectFeature = null;
      }
    }
  }, {
    key: "clearFeatures",
    value: function clearFeatures() {
      this.markerLayer && this.markerLayer.getSource().clear();
      this.source && this.source.clear();
      this.pointOverlay && this.map.removeOverlay(this.pointOverlay);
    }
  }, {
    key: "setSelectFeature",
    value: function setSelectFeature(feature) {
      if (feature) {
        this.selectFeature = feature;
        this.selectFeature.setStyle(new _style.Style({
          image: new _style.Circle({
            radius: 7,
            fill: new _Fill["default"]({
              color: '#2491fc'
            }),
            stroke: new _style.Stroke({
              color: '#FFFFFF',
              width: 2
            })
          }),
          fill: new _Fill["default"]({
            color: '#2491fc'
          }),
          stroke: new _style.Stroke({
            color: '#2491fc',
            width: 4
          })
        }));
      }
    }
  }, {
    key: "destroy",
    value: function destroy() {
      this.map.removeLayer(this.layer);
    }
  }]);
}();
//# sourceMappingURL=HighLayer.js.map
