"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _FeatureLayer = _interopRequireDefault(require("../feature-layer/FeatureLayer"));
var _CircleRippleMaterialProperty = _interopRequireDefault(require("../map/material/CircleRippleMaterialProperty"));
var _LineFlowLayer = _interopRequireDefault(require("../line-flow-layer/LineFlowLayer"));
var _transformRgb = _interopRequireDefault(require("../_util/transformRgb"));
var _excluded = ["fill", "stroke"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 _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 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 _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 _Cesium = Cesium,
  Cartesian2 = _Cesium.Cartesian2,
  Cartographic = _Cesium.Cartographic,
  Math = _Cesium.Math,
  ImageryLayerFeatureInfo = _Cesium.ImageryLayerFeatureInfo,
  Color = _Cesium.Color;
;
/**
 * @description:  wms图层点击获取的数据处理
 * @param {*} data
 * @return {*}
 */
var handleData = function handleData(data, map) {
  var _data = [];
  var datas = Array.isArray(data) ? data : [data];
  datas.map(function (v) {
    var _v$data;
    // 影像图层的数据
    if (v instanceof ImageryLayerFeatureInfo || v !== null && v !== void 0 && (_v$data = v.data) !== null && _v$data !== void 0 && (_v$data = _v$data.geometry) !== null && _v$data !== void 0 && _v$data.coordinates) {
      var item = v.data || {};
      var geometry = item.geometry;
      var _ref = geometry || {},
        _ref$coordinates = _ref.coordinates,
        coordinates = _ref$coordinates === void 0 ? [] : _ref$coordinates;
      _data.push(_objectSpread(_objectSpread({}, item), {}, {
        geometryInfo: _objectSpread(_objectSpread({}, geometry), {}, {
          lngLats: coordinates
        })
      }));
    } else {
      var _v$position, _v$_polyline, _v$_polygon;
      if (v !== null && v !== void 0 && (_v$position = v.position) !== null && _v$position !== void 0 && _v$position._value) {
        var _v$position2;
        handlePositionData({
          data: _data,
          position: v === null || v === void 0 || (_v$position2 = v.position) === null || _v$position2 === void 0 ? void 0 : _v$position2._value,
          map: map,
          feature: v
        });
      } else if (v !== null && v !== void 0 && (_v$_polyline = v._polyline) !== null && _v$_polyline !== void 0 && (_v$_polyline = _v$_polyline._positions) !== null && _v$_polyline !== void 0 && _v$_polyline._value) {
        var _v$_polyline2;
        handlePositionData({
          data: _data,
          position: v === null || v === void 0 || (_v$_polyline2 = v._polyline) === null || _v$_polyline2 === void 0 || (_v$_polyline2 = _v$_polyline2._positions) === null || _v$_polyline2 === void 0 ? void 0 : _v$_polyline2._value,
          map: map,
          feature: v,
          type: 'Polyline'
        });
      } else if (v !== null && v !== void 0 && (_v$_polygon = v._polygon) !== null && _v$_polygon !== void 0 && (_v$_polygon = _v$_polygon._hierarchy) !== null && _v$_polygon !== void 0 && (_v$_polygon = _v$_polygon._value) !== null && _v$_polygon !== void 0 && _v$_polygon.positions) {
        var _v$_polygon2;
        handlePositionData({
          data: _data,
          position: v === null || v === void 0 || (_v$_polygon2 = v._polygon) === null || _v$_polygon2 === void 0 || (_v$_polygon2 = _v$_polygon2._hierarchy) === null || _v$_polygon2 === void 0 || (_v$_polygon2 = _v$_polygon2._value) === null || _v$_polygon2 === void 0 ? void 0 : _v$_polygon2.positions,
          map: map,
          feature: v,
          type: 'Polygon'
        });
      }
    }
  });
  return _data;
};
var handlePositionData = function handlePositionData(_ref2) {
  var data = _ref2.data,
    position = _ref2.position,
    map = _ref2.map,
    feature = _ref2.feature,
    _ref2$type = _ref2.type,
    type = _ref2$type === void 0 ? 'point' : _ref2$type;
  var lngLats = [];
  if (Array.isArray(position)) {
    position.map(function (v) {
      lngLats.push(getLngLats(v));
    });
  } else {
    // 点
    lngLats = getLngLats(position);
  }
  data.push(_objectSpread(_objectSpread({}, map.getProperties(feature)), {}, {
    geometryInfo: {
      type: type,
      lngLats: lngLats
    }
  }));
};
var getLngLats = function getLngLats(position) {
  var lngLats = [];
  var cartographic = Cartographic.fromCartesian(position);
  var lng = Math.toDegrees(cartographic === null || cartographic === void 0 ? void 0 : cartographic.longitude);
  lngLats.push(lng);
  var lat = Math.toDegrees(cartographic === null || cartographic === void 0 ? void 0 : cartographic.latitude);
  lngLats.push(lat);
  return lngLats;
};
var getPolygonStyle = function getPolygonStyle(style) {
  var _ref3 = style || {},
    _ref3$fill = _ref3.fill,
    fill = _ref3$fill === void 0 ? {} : _ref3$fill,
    _ref3$stroke = _ref3.stroke,
    stroke = _ref3$stroke === void 0 ? {} : _ref3$stroke,
    otherStyle = _objectWithoutProperties(_ref3, _excluded);
  return _objectSpread({
    type: 'Polygon',
    style: {
      stroke: _objectSpread({
        color: '#f7ff01',
        opacity: 1,
        width: 2
      }, stroke),
      fill: _objectSpread({
        color: '#f7ff01',
        opacity: 0.35
      }, fill)
    }
  }, otherStyle);
};
var getLineStyle = function getLineStyle(dark) {
  return {
    type: 'Polyline',
    style: {
      stroke: {
        color: dark ? '#f7ff01' : '#e600ff',
        opacity: 1,
        width: 2
      }
    }
  };
};
var pointStyle = {
  style: {
    type: 'PointIcon',
    color: '#f7ff01',
    size: 10,
    pixelOffset: new Cartesian2(0, 10),
    ellipse: {
      semiMinorAxis: 50.0,
      semiMajorAxis: 50.0,
      material: new _CircleRippleMaterialProperty["default"]({
        color: Color.fromCssColorString((0, _transformRgb["default"])('#f7ff01', 0.7)),
        speed: 12.0,
        count: 3,
        gradient: 0.2
      })
    }
  }
};
var HighlightLayer = /*#__PURE__*/function () {
  function HighlightLayer(options) {
    var _this = this;
    _classCallCheck(this, HighlightLayer);
    // 高亮图层增加feature
    _defineProperty(this, "addHighlightFeature", function (feature, style) {
      if (feature) {
        var _feature$data, _feature$_polyline, _feature$_polygon;
        if (feature.primitive) {
          return _this.addHighlightPrimitive(feature);
        }
        var type = feature === null || feature === void 0 || (_feature$data = feature.data) === null || _feature$data === void 0 || (_feature$data = _feature$data.geometry) === null || _feature$data === void 0 ? void 0 : _feature$data.type;
        if (['LineString', 'MultiLineString'].includes(type)) {
          _this.layer.style = getLineStyle(_this.map.dark);
        } else if (['Polygon', 'MultiPolygon'].includes(type)) {
          _this.layer.style = getPolygonStyle(style);
        } else if (['Point'].includes(type)) {
          _this.layer.style = pointStyle;
        } else if (feature !== null && feature !== void 0 && (_feature$_polyline = feature._polyline) !== null && _feature$_polyline !== void 0 && (_feature$_polyline = _feature$_polyline._positions) !== null && _feature$_polyline !== void 0 && _feature$_polyline._value) {
          _this.layer.style = getLineStyle(_this.map.dark);
        } else if (feature !== null && feature !== void 0 && (_feature$_polygon = feature._polygon) !== null && _feature$_polygon !== void 0 && (_feature$_polygon = _feature$_polygon._hierarchy) !== null && _feature$_polygon !== void 0 && (_feature$_polygon = _feature$_polygon._value) !== null && _feature$_polygon !== void 0 && _feature$_polygon.positions) {
          _this.layer.style = getPolygonStyle(style);
        } else {
          _this.layer.style = pointStyle;
        }
        var data = handleData(feature, _this.map, _this.layer);
        _this.layer.data = data;
        _this.layer.loadData(data);
      }
    });
    _defineProperty(this, "addHighlightPrimitive", function (feature) {
      if (feature.primitive instanceof _LineFlowLayer["default"]) {
        _this.clearPrimitive();
        var data = [feature.values_];
        _this.primitiveLayer = new _LineFlowLayer["default"]({
          fadeOutColor: '#f7ff01',
          data: [feature.values_]
        });
        _this.map.scene.primitives.add(_this.primitiveLayer);
        _this.map.scene.primitives.raiseToTop(_this.primitiveLayer);
        _this.layer.data = data;
        _this.layer.loadData(data);
      }
    });
    var _options$isFit = options.isFit,
      isFit = _options$isFit === void 0 ? true : _options$isFit;
    this.map = options.map;
    this.layer = new _FeatureLayer["default"]({
      style: getLineStyle(this.map.dark)
    });
    this.map.addLayer(this.layer);
    this.primitiveLayer = null;
  }
  _createClass(HighlightLayer, [{
    key: "clearPrimitive",
    value: function clearPrimitive() {
      if (this.primitiveLayer) {
        if (this.map.scene.primitives.contains(this.primitiveLayer)) {
          this.map.scene.primitives.remove(this.primitiveLayer);
        }
        this.primitiveLayer = null;
      }
    }
  }, {
    key: "clearFeatures",
    value: function clearFeatures() {
      this.layer.entities.removeAll();
      this.clearPrimitive();
    }
  }, {
    key: "destroy",
    value: function destroy() {
      this.map.dataSources.remove(this.layer);
      this.clearPrimitive();
    }
  }]);
  return HighlightLayer;
}();
exports["default"] = HighlightLayer;
//# sourceMappingURL=HighlightLayer.js.map
