"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(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 _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 _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); }
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); }
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]);
    _superPropSet((_this, FenceLayer), "show", show, _this, 1, 1);
    // 图层标识
    _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 _superPropGet(FenceLayer, "show", this, 1);
    },
    set: function set(value) {
      this.setVisible(value);
    }

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

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

      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
