"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _ImageLayer = _interopRequireDefault(require("../image-layer/ImageLayer"));
var _FeatureLayer = _interopRequireDefault(require("../feature-layer/FeatureLayer"));
var _lodash = require("lodash");
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 _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,
  CustomDataSource = _Cesium.CustomDataSource;
;
var GroupLayer = /*#__PURE__*/function () {
  function GroupLayer(opt_options) {
    var _this = this;
    _classCallCheck(this, GroupLayer);
    // 获取图层最后一个 index 值
    _defineProperty(this, "getLastIndex", function (_index) {
      var index = 0;
      var layers = _this.layers;
      if (layers !== null && layers !== void 0 && layers.length) {
        if (_index && layers.findIndex(function (v) {
          return _index < v.zIndex;
        }) !== -1) {
          index = layers.findIndex(function (v) {
            return _index < v.zIndex;
          });
        } else {
          index = layers.length - 1;
        }
      }
      return index;
    });
    var _ref = opt_options || {},
      map = _ref.map,
      key = _ref.key,
      name = _ref.name,
      legend = _ref.legend,
      _ref$layerControl = _ref.layerControl,
      layerControl = _ref$layerControl === void 0 ? true : _ref$layerControl,
      _ref$layers = _ref.layers,
      _layers = _ref$layers === void 0 ? [] : _ref$layers;
    this.map = map;
    this.key = key;
    this.name = name;
    this.legend = legend;
    this.layerControl = layerControl;
    this.layers = _layers;
  }
  _createClass(GroupLayer, [{
    key: "addLayer",
    value: function addLayer(layer, groupIndex, mapIndex) {
      if (this.hasLayer(layer)) {
        return;
      }
      if (layer instanceof CustomDataSource || layer instanceof _FeatureLayer["default"]) {
        this.map.dataSources.add(layer);
      } else if (layer instanceof _ImageLayer["default"]) {
        this.map.scene.imageryLayers.add(layer, mapIndex);
      }
      if (layer.layerControl) {
        if ((0, _lodash.isNumber)(groupIndex)) {
          this.layers.splice(groupIndex, 0, layer);
        } else {
          this.layers.push(layer);
        }
        this.map.layers.onChange();
      }
    }
  }, {
    key: "removeLayer",
    value: function removeLayer(layer) {
      if (!this.hasLayer(layer)) {
        return;
      }
      if (layer instanceof CustomDataSource || layer instanceof _FeatureLayer["default"]) {
        this.map.dataSources.remove(layer);
      } else if (layer instanceof _ImageLayer["default"]) {
        this.map.scene.imageryLayers.remove(layer);
      }
      if (layer.layerControl) {
        this.layers = this.layers.filter(function (v) {
          return v !== layer;
        });
        this.map.layers.onChange();
      }
    }
  }, {
    key: "hasLayer",
    value: function hasLayer(layer) {
      return this.layers.findIndex(function (v) {
        return v === layer;
      }) !== -1;
    }
  }, {
    key: "getLayers",
    value: function getLayers() {
      return this.layers;
    }
  }, {
    key: "setLayers",
    value: function setLayers(layers) {
      this.layers = layers;
    }
  }, {
    key: "indexOf",
    value: function indexOf(layer) {
      return this.layers.findIndex(function (v) {
        return v === layer;
      });
    }
  }, {
    key: "setVisible",
    value: function setVisible(visible) {
      this.show = visible;
      this.layers.map(function (v) {
        v.show = visible;
      });
      this.map.layers.onChange();
    }
  }]);
  return GroupLayer;
}();
var _default = GroupLayer;
exports["default"] = _default;
//# sourceMappingURL=GroupLayer.js.map
