"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _cesium = require("cesium");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
var _GradualLightRingMaterialProperty = _interopRequireDefault(require("./GradualLightRingMaterialProperty.js"));
var _transformRgb = _interopRequireDefault(require("../_util/transformRgb"));
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 _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 _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 _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 _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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
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() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
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 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 _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(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); }
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); }
var FenceLayer = exports["default"] = /*#__PURE__*/function (_CustomDataSource) {
  function FenceLayer(option) {
    var _this;
    _classCallCheck(this, FenceLayer);
    var data = option.data,
      key = option.key,
      labelField = option.labelField,
      template = option.template,
      height = option.height,
      color = option.color,
      speed = option.speed,
      repeatNum = option.repeatNum,
      opacity = option.opacity,
      name = option.name,
      layerControl = option.layerControl,
      _option$show = option.show,
      show = _option$show === void 0 ? true : _option$show,
      map = option.map,
      legend = option.legend;
    _this = _callSuper(this, FenceLayer, [option]);
    _set((_this, _getPrototypeOf(FenceLayer.prototype)), "show", show, _this, true);
    // 图层标识
    _this.key = key;

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

    // 标签字段
    _this.labelField = labelField;

    // 模版内容
    _this.template = template;
    _this.data = data;

    // 颜色
    _this.color = color || '#0080ff';

    // 高度
    _this.height = height || 1000;

    // 速度
    _this.speed = speed || 1;

    // 重复数量
    _this.repeatNum = repeatNum || 3;

    // 透明度
    _this.opacity = opacity || 1;
    _this.legend = legend;

    // 地图
    _this.map = map;
    _this.layerControl = layerControl;
    if (data !== null && data !== void 0 && data.length) {
      _this.loadData(data);
    }
    return _this;
  }
  // 重写父类的属性访问器
  _inherits(FenceLayer, _CustomDataSource);
  return _createClass(FenceLayer, [{
    key: "show",
    get: function get() {
      return _get(_getPrototypeOf(FenceLayer.prototype), "show", this);
    },
    set: function set(value) {
      this.setVisible(value);
    }

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

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

      var map = this.getMap && this.getMap();
      if (map) {
        map.layers.emit('visible', this, visible);
      }
    }
  }, {
    key: "loadData",
    value: function loadData(data) {
      var _this2 = this;
      this.entities.removeAll();
      var height = this.height;
      var color = this.color;
      var speed = this.speed;
      var repeatNum = this.repeatNum;
      var opacity = this.opacity;
      data.map(function (v, index) {
        var positions = [];
        var _v$geometryInfo = v.geometryInfo,
          geometryInfo = _v$geometryInfo === void 0 ? {} : _v$geometryInfo;
        var _transformGeometry = (0, _createFeatureCollection.transformGeometry)(geometryInfo),
          coordinates = _transformGeometry.coordinates;
        if (coordinates && coordinates.length) {
          var _coordinates$;
          coordinates === null || coordinates === void 0 || (_coordinates$ = coordinates[0]) === null || _coordinates$ === void 0 || _coordinates$.map(function (c) {
            positions.push.apply(positions, _toConsumableArray(c).concat([c.height || height]));
          });
        }
        var entity_fly = _this2.entities.add({
          wall: {
            positions: _cesium.Cartesian3.fromDegreesArrayHeights(positions),
            material: new _GradualLightRingMaterialProperty["default"]({
              color: _cesium.Color.fromCssColorString((0, _transformRgb["default"])(v.color || color, v.opacity || opacity)),
              speed: v.speed || speed,
              repeatNum: v.repeatNum || repeatNum
            }),
            outline: false,
            zIndex: v.zIndex || index
          }
        });
        entity_fly.type = _this2.modalType || _this2.key;
        entity_fly.key = _this2.key;
        entity_fly.properties = v.properties || {};
      });
    }

    // 根据条件获取图形数据
  }, {
    key: "getFeatureByFieldValue",
    value: function getFeatureByFieldValue(field, value) {
      return this.getFeatures().find(function (v) {
        var _v$properties;
        return String(v === null || v === void 0 || (_v$properties = v.properties) === null || _v$properties === void 0 || (_v$properties = _v$properties[field]) === null || _v$properties === void 0 ? void 0 : _v$properties._value) === String(value);
      });
    }

    // 获取当前图层的所有图形
  }, {
    key: "getFeatures",
    value: function getFeatures() {
      return this.entities.values;
    }
  }]);
}(_cesium.CustomDataSource);
//# sourceMappingURL=FenceLayer.js.map
