"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 _ol = require("ol");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
var _format = require("ol/format");
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 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 _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 _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 HighLayer = /*#__PURE__*/function () {
  function HighLayer(options) {
    var _this = this;
    _classCallCheck(this, HighLayer);
    // 图层放大
    _defineProperty(this, "setHighlight", function (feature) {
      var fit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
      _this.isFit = fit;
      _this.feature = feature;
      _this.addHighlightFeature(feature);
    });
    // 点位加波浪
    _defineProperty(this, "setPointHighlight", function (feature) {
      _this.feature = feature;
      _this.addPointHighlight(feature);
    });
    // 高亮图层增加feature
    _defineProperty(this, "addHighlightFeature", function (feature) {
      _this.clearSelectFeature();
      _this.clearFeatures();
      if (feature && Array.isArray(feature) && feature !== null && feature !== void 0 && feature.length) {
        _this.source.addFeatures(feature);
        _this.isFit && _this.map.fitView(_this.source);
      }
    });
    // 点位高亮-扩散
    _defineProperty(this, "addPointHighlight", function (feature) {
      var point_overlay = _this.map.getOverlayById('POINT_ANIMATION');
      if (point_overlay) {
        _this.map.removeOverlay(point_overlay);
      }
      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 = 'point_animation';
          if (!point_overlay) {
            point_overlay = new _ol.Overlay({
              id: 'POINT_ANIMATION',
              element: ele,
              positioning: 'center-center',
              stopEvent: false
            });
          }
          _this.map.addOverlay(point_overlay);
          point_overlay.setPosition(geometry.getFlatCoordinates());
          _this.pointOverlay = point_overlay;
        }
        _this.isFit && _this.map.fitView(feature);
      }
    });
    _defineProperty(this, "setCenter", function (field, fieldName) {
      var filterField = fieldName || 'code';
      _this.clearSelectFeature();
      var newFeature;
      var features = _this.source.getFeatures();
      if (features !== null && features !== void 0 && features.length) {
        newFeature = features.find(function (v) {
          return (v.get(filterField) || v.get('CODE')) === field;
        });
      } else if (features && features.get(filterField) === field) {
        newFeature = features;
      }
      _this.selectFeature = newFeature;
      if (newFeature) {
        newFeature.setStyle();
        _this.isFit && _this.map.fitView(newFeature);
        if (_this.isHighLight) _this.setSelectFeature(newFeature);
      } else {
        _antd.message.warning('地图上未查询到该数据，请检查是否配置坐标信息！');
      }
    });
    _defineProperty(this, "addHighlightData", function (data, key, fit) {
      if (data) {
        var geoJsonFormat = new _format.GeoJSON();
        var res = (0, _createFeatureCollection.createFeatureCollection)(Array.isArray(data) ? data : [data]);
        var features = geoJsonFormat.readFeatures(res);
        if (features !== null && features !== void 0 && features.length) {
          features.map(function (v) {
            v.key = key;
          });
          _this.setHighlight(features, fit);
        }
      }
    });
    var _options$isFit = options.isFit,
      isFit = _options$isFit === void 0 ? true : _options$isFit,
      _options$isHighLight = options.isHighLight,
      isHighLight = _options$isHighLight === void 0 ? true : _options$isHighLight,
      style = options.style,
      _key = options.key;
    this.highStyle = style || new _style.Style({
      // 高亮样式
      image: new _style.Circle({
        radius: 7,
        fill: new _style.Fill({
          color: '#ff4d4f'
        }),
        stroke: new _style.Stroke({
          color: '#FFFFFF',
          width: 2
        })
      }),
      fill: new _style.Fill({
        color: '#ff4d4f'
      }),
      stroke: new _style.Stroke({
        color: '#ff4d4f',
        width: 4
      })
    });
    this.isHighLight = isHighLight;
    this.map = options.map;
    this.feature = options.feature;
    this.selectFeature = null;
    this.pointOverlay = null;
    this.isFit = isFit;
    this.source = new _source.Vector();
    this.layer = new _layer.Vector(_objectSpread({
      source: this.source,
      zIndex: 9999,
      style: this.highStyle
    }, options.parmas || options.params || {}));
    this.layer.key = _key || 'Highlight';
    this.map.addLayer(this.layer);
  }
  _createClass(HighLayer, [{
    key: "clearSelectFeature",
    value: function clearSelectFeature() {
      if (this.selectFeature) {
        this.selectFeature.setStyle();
        this.selectFeature = null;
      }
    }
  }, {
    key: "clearFeatures",
    value: function clearFeatures() {
      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 _style.Fill({
              color: '#2491fc'
            }),
            stroke: new _style.Stroke({
              color: '#FFFFFF',
              width: 2
            })
          }),
          fill: new _style.Fill({
            color: '#2491fc'
          }),
          stroke: new _style.Stroke({
            color: '#2491fc',
            width: 4
          })
        }));
      }
    }
  }, {
    key: "destroy",
    value: function destroy() {
      this.map.removeLayer(this.layer);
    }
  }]);
  return HighLayer;
}();
exports["default"] = HighLayer;
//# sourceMappingURL=HighLayer.js.map
