"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.getCqlFilterByGroup = exports["default"] = void 0;
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 _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 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(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); }
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 _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _Cesium = Cesium,
  ImageryLayer = _Cesium.ImageryLayer,
  WebMapServiceImageryProvider = _Cesium.WebMapServiceImageryProvider;
;
var getCqlFilterByGroup = function getCqlFilterByGroup(group) {
  var cql_filter = "";
  if (group !== null && group !== void 0 && group.length) {
    group.map(function (v) {
      if (!v.hasOwnProperty('show') || v.show) {
        cql_filter = cql_filter ? "".concat(cql_filter, " or ").concat(v.filter) : v.filter;
      }
    });
  }
  return cql_filter;
};
exports.getCqlFilterByGroup = getCqlFilterByGroup;
var ImageLayer = /*#__PURE__*/function (_ImageryLayer) {
  _inherits(ImageLayer, _ImageryLayer);
  var _super = _createSuper(ImageLayer);
  function ImageLayer(options) {
    var _this;
    _classCallCheck(this, ImageLayer);
    var url = options.url,
      _options$params = options.params,
      params = _options$params === void 0 ? {} : _options$params,
      _options$geoserverPar = options.geoserverParams,
      geoserverParams = _options$geoserverPar === void 0 ? {} : _options$geoserverPar,
      key = options.key,
      modalType = options.modalType,
      name = options.name,
      labelField = options.labelField,
      template = options.template,
      autoRefresh = options.autoRefresh,
      style = options.style,
      codeField = options.codeField,
      _options$show = options.show,
      show = _options$show === void 0 ? true : _options$show,
      _options$layerControl = options.layerControl,
      layerControl = _options$layerControl === void 0 ? true : _options$layerControl,
      legend = options.legend,
      map = options.map,
      group = options.group,
      zIndex = options.zIndex,
      groupLayer = options.groupLayer;
    var _params = _objectSpread({}, params);
    if (group !== null && group !== void 0 && group.length) {
      var _group = JSON.parse(JSON.stringify(group));
      if (!show) {
        _group.map(function (f) {
          f.show = false;
        });
      } else {
        _group.map(function (f) {
          var _f$show;
          f.show = (_f$show = f.show) !== null && _f$show !== void 0 ? _f$show : true;
        });
      }
      var _cql_filter = getCqlFilterByGroup(_group);
      if (_cql_filter) {
        _params.cql_filter = _params.cql_filter ? "".concat(_params.cql_filter, " or ").concat(_cql_filter) : _cql_filter;
      } else {
        show = false;
      }
    }
    var imageryProvider = new WebMapServiceImageryProvider(_objectSpread({
      url: url,
      enablePickFeatures: true,
      getFeatureInfoParameters: _params,
      parameters: _objectSpread({
        service: 'WMS',
        format: 'image/png',
        transparent: true
      }, _params),
      layers: _params.typeName || _params.QUERY_LAYERS
    }, geoserverParams));
    _this = _super.call(this, imageryProvider, {
      show: show
    });

    // 接口地址
    _this.url = url;
    _this.style = style;

    // 图层标识
    _this.key = key;

    // 弹窗类型
    _this.modalType = modalType;

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

    // 设施类型
    _this.codeField = codeField;

    // 图例
    _this.legend = legend;

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

    // 自动刷新标识
    _this.autoRefresh = autoRefresh;

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

    // 地图
    _this.map = map;

    // 图层组
    _this.groupLayer = groupLayer;

    // 过滤
    _this.group = group;

    // 查询条件
    _this.params = params;

    // 图层层级
    _this.zIndex = zIndex;

    // 图层控制
    _this.layerControl = layerControl;
    return _this;
  }

  // 重写父类的属性访问器
  _createClass(ImageLayer, [{
    key: "show",
    get: function get() {
      return _get(_getPrototypeOf(ImageLayer.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(ImageLayer.prototype), "show", visible, this, true); // 将属性传递给父类

      var map = this.getMap && this.getMap();
      if (map) {
        map.layers.emit('visible', this, visible);
      }
    }

    // 设置过滤条件
  }, {
    key: "setGroup",
    value: function setGroup(group) {
      if (group !== null && group !== void 0 && group.length) {
        var params = _objectSpread({}, this.params);
        group.map(function (v) {
          if (!v.hasOwnProperty('show') || v.show) {
            params.cql_filter = params.cql_filter ? "".concat(params.cql_filter, " or ").concat(v.filter) : v.filter;
          }
        });
        this.group = group;
        this.setParams(params);
        this.setVisibleByGroup();
      }
    }

    // 根据过滤条件组显示图层
  }, {
    key: "setVisibleByGroup",
    value: function setVisibleByGroup() {
      var group = this.group;
      if (group !== null && group !== void 0 && group.length) {
        var visible = false;
        group.map(function (v) {
          if (!v.hasOwnProperty('show') || v.show) {
            visible = true;
          }
        });
        this.setVisible(visible);
      }
    }

    // 设置查询条件
  }, {
    key: "setParams",
    value: function setParams(params) {
      // 下面的方法无效，暂时没有好的方式，只能通过替换图层达到效果
      // this.imageryProvider = new WebMapServiceImageryProvider({
      //     url: this.url,
      //     enablePickFeatures: true,
      //     getFeatureInfoParameters: params,
      //     parameters: { service: 'WMS', format: 'image/png', transparent: true, ...params },
      //     layers: params.typeName || params.QUERY_LAYERS,
      // })
    }
  }, {
    key: "getGroupIndex",
    value: function getGroupIndex() {
      return this.groupLayer.indexOf(this);
    }
  }, {
    key: "getMapIndex",
    value: function getMapIndex() {
      return this.map.scene.imageryLayers.indexOf(this);
    }
  }]);
  return ImageLayer;
}(ImageryLayer);
var _default = ImageLayer;
exports["default"] = _default;
//# sourceMappingURL=ImageLayer.js.map
