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 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 _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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); }
// Create leaflet map
function createMap(container, _ref) {
  var _window$L, _window$L$tileLayer, _window$L$tileLayer2, _window$L$tileLayer3, _window$L$tileLayer4, _window$L$tileLayer5;
  var center = _ref.center,
    minZoom = _ref.minZoom,
    maxZoom = _ref.maxZoom,
    zoom = _ref.zoom;
  if (!window.L) {
    return '请在Map组件需要使用APILoader包裹';
  }
  if (!((_window$L = window.L) !== null && _window$L !== void 0 && (_window$L = _window$L.tileLayer) !== null && _window$L !== void 0 && _window$L.currentTileLayer)) {
    return '缺少必要地图资源, 请检查APILoader参数是否正确, 或者key是否过期';
  }
  var centerPoint = [];
  if (center !== null && center !== void 0 && center.latitude && center !== null && center !== void 0 && center.longitude) {
    centerPoint = [center === null || center === void 0 ? void 0 : center.latitude, center === null || center === void 0 ? void 0 : center.longitude];
  }
  // Init leaflet map config
  var config = _objectSpread(_objectSpread({
    attributionControl: false,
    // 隐藏版权控件
    zoomControl: false,
    // 隐藏放大缩小控件
    center: centerPoint
  }, ((_window$L$tileLayer = window.L.tileLayer) === null || _window$L$tileLayer === void 0 || (_window$L$tileLayer = _window$L$tileLayer.currentTileLayer) === null || _window$L$tileLayer === void 0 ? void 0 : _window$L$tileLayer.config) || {}), {}, {
    maxZoom: maxZoom || ((_window$L$tileLayer2 = window.L.tileLayer) === null || _window$L$tileLayer2 === void 0 || (_window$L$tileLayer2 = _window$L$tileLayer2.currentTileLayer) === null || _window$L$tileLayer2 === void 0 || (_window$L$tileLayer2 = _window$L$tileLayer2.config) === null || _window$L$tileLayer2 === void 0 ? void 0 : _window$L$tileLayer2.maxZoom) || 18,
    minZoom: minZoom || ((_window$L$tileLayer3 = window.L.tileLayer) === null || _window$L$tileLayer3 === void 0 || (_window$L$tileLayer3 = _window$L$tileLayer3.currentTileLayer) === null || _window$L$tileLayer3 === void 0 || (_window$L$tileLayer3 = _window$L$tileLayer3.config) === null || _window$L$tileLayer3 === void 0 ? void 0 : _window$L$tileLayer3.minZoom) || 3,
    zoom: zoom || ((_window$L$tileLayer4 = window.L.tileLayer) === null || _window$L$tileLayer4 === void 0 || (_window$L$tileLayer4 = _window$L$tileLayer4.currentTileLayer) === null || _window$L$tileLayer4 === void 0 || (_window$L$tileLayer4 = _window$L$tileLayer4.config) === null || _window$L$tileLayer4 === void 0 ? void 0 : _window$L$tileLayer4.zoom) || 13
  });

  // Leaflet map
  var map = window.L.map(container, config);

  // TileLayer error
  if (!((_window$L$tileLayer5 = window.L.tileLayer) !== null && _window$L$tileLayer5 !== void 0 && _window$L$tileLayer5.currentTileLayer)) {
    return map;
  }

  // Add tileLayer
  var tileLayer = window.L.tileLayer.currentTileLayer();
  tileLayer.addTo(map);

  // Update tileLayer size
  // map.invalidateSize()

  return new Promise(function (resolve) {
    tileLayer.on('load', function () {
      resolve(map);
    });
  });
}
export default createMap;