"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.OPTIONS = exports.Imagery = exports.BaseMap = void 0;
var _GeoQImageryProvider = _interopRequireDefault(require("./imagery/geoq/GeoQImageryProvider"));
var _BaiduImageryProvider = _interopRequireDefault(require("./imagery/baidu/BaiduImageryProvider"));
var _AmapImageryProvider = _interopRequireDefault(require("./imagery/amap/AmapImageryProvider"));
var _TencentImageryProvider = _interopRequireDefault(require("./imagery/tencent/TencentImageryProvider"));
var _TdtImageryProvider = _interopRequireDefault(require("./imagery/tdt/TdtImageryProvider"));
var _GoogleImageryProvider = _interopRequireDefault(require("./imagery/google/GoogleImageryProvider"));
var _baseImg = _interopRequireDefault(require("../../assets/base-img.png"));
var _baseImg2 = _interopRequireDefault(require("../../assets/base-img-1.png"));
var _baseImg3 = _interopRequireDefault(require("../../assets/base-img-2.png"));
var _baseImg4 = _interopRequireDefault(require("../../assets/base-img-3.png"));
var _baseImg5 = _interopRequireDefault(require("../../assets/base-img-4.png"));
var _baseImg6 = _interopRequireDefault(require("../../assets/base-img-5.png"));
var _EventEmitter2 = _interopRequireDefault(require("../../_util/EventEmitter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 _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 _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 Imagery = {
  GeoQImageryProvider: _GeoQImageryProvider["default"],
  AmapImageryProvider: _AmapImageryProvider["default"],
  BaiduImageryProvider: _BaiduImageryProvider["default"],
  TencentImageryProvider: _TencentImageryProvider["default"],
  TdtImageryProvider: _TdtImageryProvider["default"],
  GoogleImageryProvider: _GoogleImageryProvider["default"]
};
exports.Imagery = Imagery;
var OPTIONS = [{
  label: '地图风格',
  value: 'GeoQImageryProvider',
  children: [{
    label: '蓝黑版',
    value: 'Blue',
    img: _baseImg6["default"]
  }, {
    label: '彩色版',
    value: 'Community',
    img: _baseImg3["default"]
  }, {
    label: '暖色版',
    value: 'StreetWarm',
    img: _baseImg4["default"]
  }, {
    label: '灰色版',
    value: 'ChinaOnlineStreetGray',
    img: _baseImg5["default"]
  }]
}, {
  label: '天地图',
  value: 'TdtImageryProvider',
  children: [{
    label: '影像图',
    value: 'img',
    img: _baseImg["default"]
  }, {
    label: '矢量图',
    value: 'vec',
    img: _baseImg2["default"]
  }]
}, {
  label: '高德地图',
  value: 'AmapImageryProvider',
  children: [{
    label: '影像图',
    value: 'IMG',
    img: _baseImg["default"]
  }, {
    label: '矢量图',
    value: 'ELEC',
    img: _baseImg2["default"]
  }]
}, {
  label: '腾讯地图',
  value: 'TencentImageryProvider',
  children: [{
    label: '影像图',
    value: 'IMG',
    img: _baseImg["default"]
  }, {
    label: '矢量图',
    value: 'ELEC',
    img: _baseImg2["default"]
  }]
}, {
  label: '百度地图',
  value: 'BaiduImageryProvider',
  children: [{
    label: '影像图',
    value: 'IMG',
    img: _baseImg["default"]
  }, {
    label: '矢量图',
    value: 'CUSTOM',
    img: _baseImg2["default"]
  }]
}];
exports.OPTIONS = OPTIONS;
var BaseMap = /*#__PURE__*/function (_EventEmitter) {
  _inherits(BaseMap, _EventEmitter);
  var _super = _createSuper(BaseMap);
  function BaseMap(options) {
    var _this;
    _classCallCheck(this, BaseMap);
    _this = _super.call(this);
    _this.map = options.map;
    _this.options = options.options || OPTIONS;
    _this.imageryProvider = options.imageryProvider || '';
    _this.style = options.style || '';
    _this.layer = options.layer || _this.addLayer();
    return _this;
  }
  _createClass(BaseMap, [{
    key: "getValue",
    value: function getValue() {
      var imageryProvider = this.imageryProvider;
      var style = this.style;
      var options = this.options;
      var value = {};
      options.map(function (v) {
        if (v.value === imageryProvider) {
          v.children.map(function (c) {
            if (c.value === style) {
              value = _objectSpread(_objectSpread({}, c), {}, {
                value: "".concat(v.value, "_").concat(c.value)
              });
            }
          });
        }
      });
      return value;
    }
  }, {
    key: "setValue",
    value: function setValue(imageryProvider, style) {
      this.removeLayer(); // 删除老的底图

      this.imageryProvider = imageryProvider;
      this.style = style;
      this.layer = this.addLayer();
    }
  }, {
    key: "addLayer",
    value: function addLayer() {
      var map = this.map;
      var imageryProvider = this.imageryProvider;
      var style = this.style;
      var options = this.options;
      var layer;
      if (imageryProvider) {
        if (options !== null && options !== void 0 && options.length) {
          options.map(function (v) {
            var children = v.children,
              value = v.value;
            if (value === imageryProvider && Imagery[value]) {
              var child = children.find(function (c) {
                return c.value === style;
              });
              var ImageryProvider = Imagery[value];
              layer = new ImageryProvider({
                style: child.value,
                crs: 'WGS84'
              });
            }
          });
        }
      }
      if (layer && map) {
        this.layer = map.imageryLayers.addImageryProvider(layer, 0);
      }
      return layer;
    }
  }, {
    key: "removeLayer",
    value: function removeLayer() {
      var map = this.map;
      var layers = map.imageryLayers._layers;
      layers.map(function (layer) {
        if (layer.imageryProvider) {
          if (layer.imageryProvider instanceof _GeoQImageryProvider["default"] || layer.imageryProvider instanceof _AmapImageryProvider["default"] || layer.imageryProvider instanceof _BaiduImageryProvider["default"] || layer.imageryProvider instanceof _TencentImageryProvider["default"] || layer.imageryProvider instanceof _TdtImageryProvider["default"] || layer.imageryProvider instanceof _GoogleImageryProvider["default"]) {
            map.imageryLayers.remove(layer);
          }
        }
      });
    }
  }]);
  return BaseMap;
}(_EventEmitter2["default"]);
exports.BaseMap = BaseMap;
//# sourceMappingURL=index.js.map
