"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 _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _cesium = require("cesium");
var _ahooks = require("ahooks");
var _turf = require("@turf/turf");
var _HighlightLayer = _interopRequireDefault(require("../highlight-layer/HighlightLayer"));
var _base = require("./base");
require("./material");
var _getDefaultMapInfo2 = _interopRequireDefault(require("../_util/getDefaultMapInfo"));
require("cesium/Build/Cesium/Widgets/widgets.css");
var _classnames = _interopRequireDefault(require("classnames"));
var _events = require("../events");
var _Popup = _interopRequireDefault(require("./Popup"));
var _Provider = _interopRequireDefault(require("../_util/Provider"));
var _Layers = _interopRequireDefault(require("./Layers"));
var _EventEmitter = _interopRequireDefault(require("../_util/EventEmitter"));
var _useGetMapFeatureInfoByText = _interopRequireDefault(require("./hooks/useGetMapFeatureInfoByText"));
var _lodash = require("lodash");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
var _getBBoxFromGeojson = _interopRequireDefault(require("../_util/getBBoxFromGeojson.js"));
var _heightAndZoom = require("../_util/heightAndZoom.js");
var _TdtImageryProvider = require("./base/imagery/tdt/TdtImageryProvider");
var _IRSImageryProvider = require("./base/imagery/irs/IRSImageryProvider");
var _excluded = ["center", "fitViewHeight", "dark", "zoom", "createdMap", "defaultView"],
  _excluded2 = ["geoJson", "geometryInfo", "data", "entity", "lng", "lat", "height", "options"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (c = i[4] || 3, u = i[5] === e ? i[3] : i[5], i[4] = 3, i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
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 _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 _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
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(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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function Map(props) {
  var _props$width = props.width,
    width = _props$width === void 0 ? '100%' : _props$width,
    _props$height = props.height,
    height = _props$height === void 0 ? '100%' : _props$height,
    _props$dark = props.dark,
    dark = _props$dark === void 0 ? true : _props$dark,
    tk = props.tk,
    children = props.children,
    onCloseTemplateBefore = props.onCloseTemplateBefore,
    onZoom = props.onZoom,
    _props$defaultPitch = props.defaultPitch,
    defaultPitch = _props$defaultPitch === void 0 ? -88.0 : _props$defaultPitch,
    _props$onEvents = props.onEvents,
    onEvents = _props$onEvents === void 0 ? {} : _props$onEvents,
    baseMapUrl = props.baseMapUrl,
    _props$duration = props.duration,
    duration = _props$duration === void 0 ? 3 : _props$duration,
    _props$baseMapStyle = props.baseMapStyle,
    baseMapStyle = _props$baseMapStyle === void 0 ? {
      imageryProvider: 'TdtImageryProvider',
      style: 'dark'
    } : _props$baseMapStyle,
    _props$autoView = props.autoView,
    autoView = _props$autoView === void 0 ? true : _props$autoView,
    _props$closePopupAuto = props.closePopupAutoView,
    closePopupAutoView = _props$closePopupAuto === void 0 ? true : _props$closePopupAuto,
    _props$highlightColor = props.highlightColor,
    highlightColor = _props$highlightColor === void 0 ? '#f7ff01' : _props$highlightColor,
    hideHighlight = props.hideHighlight,
    wrapDomStyle = props.wrapDomStyle,
    mapDomStyle = props.mapDomStyle,
    baseMapOptions = props.baseMapOptions,
    _props$viewMode = props.viewMode,
    viewMode = _props$viewMode === void 0 ? '2D' : _props$viewMode,
    baseColor = props.baseColor,
    setLoading = props.setLoading;
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    mapLoaded = _useState2[0],
    setMapLoaded = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = _slicedToArray(_useState3, 2),
    tipVis = _useState4[0],
    setTipVis = _useState4[1];
  var _useState5 = (0, _react.useState)(null),
    _useState6 = _slicedToArray(_useState5, 2),
    tip = _useState6[0],
    setTip = _useState6[1];
  var mapRef = (0, _react.useRef)(null);
  var mapDomRef = (0, _react.useRef)(null);
  var tipRef = (0, _react.useRef)(null);
  var popupRef = (0, _react.useRef)();
  var getMapFeatureInfoByText = (0, _useGetMapFeatureInfoByText["default"])(mapRef);
  (0, _react.useEffect)(function () {
    initMap();
    return function () {
      setLoading === null || setLoading === void 0 || setLoading(false);
    };
  }, []);
  (0, _ahooks.useUpdateEffect)(function () {
    if (mapRef.current) {
      mapRef.current.baseMap.setBaseMap(baseMapStyle);
      addLabelImageryProvider();
    }
  }, [JSON.stringify(baseMapStyle)]);
  var addLabelImageryProvider = function addLabelImageryProvider() {
    if (!baseMapStyle.hideLabel) {
      // 调用影响中文注记服务
      if (baseMapStyle.imageryProvider === 'TdtImageryProvider') {
        var cia = new _TdtImageryProvider.TdtLabelImageryProvider(_objectSpread({
          tk: tk
        }, baseMapStyle));
        mapRef.current.imageryLayers.addImageryProvider(cia); // 添加到cesium图层上
      } else if (baseMapStyle.imageryProvider === 'IRSImageryProvider') {
        var _cia = new _IRSImageryProvider.IRSLabelImageryProvider(baseMapStyle);
        mapRef.current.imageryLayers.addImageryProvider(_cia); // 添加到cesium图层上
      }
    } else {
      if (mapRef.current) {
        var layers = mapRef.current.imageryLayers._layers || [];
        var ciaLayer = layers.find(function (item) {
          var _item$_imageryProvide;
          return ((_item$_imageryProvide = item._imageryProvider) === null || _item$_imageryProvide === void 0 ? void 0 : _item$_imageryProvide._layer) === 'cia_w';
        });
        if (ciaLayer) {
          mapRef.current.imageryLayers.remove(ciaLayer);
        }
      }
    }
  };
  var initMap = function initMap() {
    var center = props.center,
      fitViewHeight = props.fitViewHeight,
      dark = props.dark,
      zoom = props.zoom,
      createdMap = props.createdMap,
      defaultView = props.defaultView,
      options = _objectWithoutProperties(props, _excluded);
    var _getDefaultMapInfo = (0, _getDefaultMapInfo2["default"])(),
      minZoom = _getDefaultMapInfo.minZoom,
      maxZoom = _getDefaultMapInfo.maxZoom,
      defaultZoomLevel = _getDefaultMapInfo.defaultZoomLevel,
      longitude = _getDefaultMapInfo.longitude,
      latitude = _getDefaultMapInfo.latitude;

    // 默认视野相关
    var viewDefault = _objectSpread({
      center: center || [(defaultView === null || defaultView === void 0 ? void 0 : defaultView.x) || longitude || 120.081627, (defaultView === null || defaultView === void 0 ? void 0 : defaultView.y) || latitude || 30.89638],
      zoom: zoom || defaultZoomLevel && Number(defaultZoomLevel) || 0,
      minZoom: minZoom && Number(minZoom) || 0,
      maxZoom: maxZoom && Number(maxZoom) || 20,
      pitch: viewMode === '3D' ? -35 : defaultPitch
    }, defaultView);
    if (viewDefault.zoom && !viewDefault.center[2]) {
      viewDefault.center[2] = (0, _heightAndZoom.zoomToHeight)(viewDefault.zoom);
    }
    _cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhZjc0ZDQ1ZS0wNWNhLTRhMDQtODJmYy03NTcyNDcxYzgzMDUiLCJpZCI6NzE4MTQsImlhdCI6MTYzNTQ3NzgyNX0.4TrdZWPWc9_6jLeGe90bRmBPB14XptwinSewVMu1iCE';
    var imageryProvider = baseMapStyle.imageryProvider && _base.Imagery[baseMapStyle.imageryProvider] && new _base.Imagery[baseMapStyle.imageryProvider](_objectSpread({
      style: baseMapStyle.style,
      url: baseMapUrl,
      crs: 'WGS84',
      dark: dark,
      a: 11
    }, baseMapStyle));
    var map = new _cesium.Viewer(mapDomRef.current, _objectSpread({
      shouldAnimate: true,
      animation: false,
      // 控制场景动画的播放速度控件
      baseLayerPicker: false,
      // 底图切换控件
      fullscreenButton: false,
      // 全屏控件
      geocoder: false,
      // 地理位置查询定位控件
      homeButton: false,
      // 默认相机位置控件
      timeline: false,
      // 时间滚动条控件
      infoBox: false,
      //是否显示信息框
      sceneModePicker: false,
      //是否显示3D/2D选择器
      selectionIndicator: false,
      // 点击点绿色弹出 是否显示选取指示器组件
      sceneMode: _cesium.SceneMode.SCENE3D,
      //设定3维地图的默认场景模式: SceneMode.SCENE2D、SceneMode.SCENE3D、SceneMode.MORPHING
      navigationHelpButton: false,
      // 默认的相机控制提示控件
      scene3DOnly: true,
      // 每个几何实例仅以3D渲染以节省GPU内存
      navigationInstructionsInitiallyVisible: false,
      showRenderLoopErrors: process.env.NODE_ENV === 'development',
      //是否显示渲染错误
      orderIndependentTranslucency: false,
      //设置背景透明
      imageryProvider: imageryProvider
    }, options));
    map.clock.currentTime = new _cesium.JulianDate.fromIso8601("2024-01-26T12:00:00Z");
    map.viewDefault = viewDefault;

    // 设置地球暗色
    if (dark) {
      map.scene.globe.baseColor = _cesium.Color.fromCssColorString('#152937');
    }

    // 设置地球颜色
    if (baseColor) {
      map.scene.globe.baseColor = _cesium.Color.fromCssColorString(baseColor);
    }

    // 事件订阅
    map.eventEmitter = new _EventEmitter["default"]();

    // 监听加载是否完成
    var helper = new _cesium.EventHelper();
    helper.add(map.scene.globe.tileLoadProgressEvent, function (e) {
      setLoading === null || setLoading === void 0 || setLoading(true);
      map.eventEmitter.emit('loading', e);
      if (e === 0) {
        setLoading === null || setLoading === void 0 || setLoading(false);
      }
    });

    // 设置cesium请求调度器的最大并发数量
    _cesium.RequestScheduler.maximumRequestsPerServer = 18;

    // 关闭请求调度器的请求节流
    _cesium.RequestScheduler.throttleRequests = false;
    map.viewMode = viewMode;

    // 自动调整视角
    map.autoView = autoView;

    // 关闭气泡自动调整视角
    map.closePopupAutoView = closePopupAutoView;

    // 去版权信息
    map._cesiumWidget._creditContainer.style.display = 'none'; // 隐藏cesium ion

    mapRef.current = map;
    map.dark = dark;

    // 地图fit高度
    map.fitViewHeight = fitViewHeight || 5000;

    // 隐藏高亮效果
    map.hideHighlight = hideHighlight;

    // 底图服务
    map.baseMap = new _base.BaseMap({
      map: map,
      imageryProvider: baseMapStyle.imageryProvider,
      style: baseMapStyle.style,
      layer: imageryProvider,
      options: baseMapOptions
    });

    // 添加 dataSource 和 imagery 图层
    map.layers = new _Layers["default"]({
      map: map
    });

    // 高亮图层
    map.highlightLayer = new _HighlightLayer["default"]({
      map: map,
      color: highlightColor
    });

    // 图层改变的时候
    map.layers.on('change', function (layers) {
      onEvents.layersChange && onEvents.layersChange(layers);
      map.eventEmitter.emit('layersChange', layers);
    });

    // 图层新增
    map.layers.on('add', function (layer) {
      onEvents.layersAdd && onEvents.layersAdd(layer);
      map.eventEmitter.emit('layersAdd', layer);
    });

    // 图层移除
    map.layers.on('remove', function (layer) {
      onEvents.layersRemove && onEvents.layersRemove(layer);
      map.eventEmitter.emit('layersRemove', layer);
    });

    // 图层清空
    map.layers.on('clear', function () {
      onEvents.layersClear && onEvents.layersClear();
      map.eventEmitter.emit('layersClear');
    });

    // 图层展示隐藏
    map.layers.on('visible', function (layer, visible) {
      map.layers.onChange(); // 触发图层改变

      // 图层关闭时，隐藏自身的气泡
      if (!visible && map.popupRef) {
        map.hideTemplate(layer);
      }
      onEvents.layersVisible && onEvents.layersVisible(layer, visible);
      map.eventEmitter.emit('layersVisible');
    });

    // 图层变化
    map.layersChange = function () {
      map.layers.onChange();
    };

    // 获取 layers 里面的 key 集合
    map.getAllKeys = function () {
      return map.layers.getAllKeys();
    };

    // 获取当前展示的 keys
    map.getLayersShowKeys = function () {
      return map.layers.getShowKeys();
    };

    // 获取当前隐藏的 keys
    map.getLayersHiddenKeys = function () {
      return map.layers.getHiddenKeys();
    };

    // 根据 keys 设置图层的显示，其他的隐藏
    map.setLayersShowByKeys = function (_keys) {
      return map.layers.setShowByKeys(_keys);
    };

    // 根据 keys 设置图层的隐藏，其他的显示
    map.setLayersHideByKeys = function (_keys) {
      return map.layers.setHideByKeys(_keys);
    };

    // 添加图层
    map.addLayer = function (layer, index) {
      return map.layers.addLayer(layer, index);
    };

    // 移除图层
    map.removeLayer = function (layer) {
      return map.layers.removeLayer(layer);
    };

    // 清除图层和entity
    map.clearLayers = function () {
      return map.layers.clearLayers();
    };

    // 获取 ImageLayer 图层
    map.getImageLayers = function (keys) {
      return map.layers.getImageLayers(keys);
    };

    // 获取 FeatureLayer 图层
    map.getFeatureLayers = function (keys) {
      return map.layers.getFeatureLayers(keys);
    };

    // 获取 Imagery 图层最后一个 index 值
    map.getImageryLastIndex = function (_index) {
      var index = 1;
      var layers = map.getImageryLayers();
      if (layers !== null && layers !== void 0 && layers.length) {
        if (_index && layers.findIndex(function (v) {
          return _index < v.zIndex;
        }) !== -1) {
          var _i = layers.findIndex(function (v) {
            return _index < v.zIndex;
          }) + 1;
          index = _i < index ? _i : index;
        } else {
          index = layers.length;
        }
      }
      return index;
    };

    // 查找所有dataSource和imagery图层
    map.getAllLayers = function () {
      var _map$dataSources, _map$imageryLayers, _map$scene;
      var dataSources = (map === null || map === void 0 || (_map$dataSources = map.dataSources) === null || _map$dataSources === void 0 ? void 0 : _map$dataSources._dataSources) || [];
      var imageryLayers = (map === null || map === void 0 || (_map$imageryLayers = map.imageryLayers) === null || _map$imageryLayers === void 0 ? void 0 : _map$imageryLayers._layers) || [];
      var primitives = (map === null || map === void 0 || (_map$scene = map.scene) === null || _map$scene === void 0 || (_map$scene = _map$scene.primitives) === null || _map$scene === void 0 ? void 0 : _map$scene._primitives) || [];
      return [].concat(_toConsumableArray(dataSources), _toConsumableArray(imageryLayers), _toConsumableArray(primitives));
    };

    // 根据key查找imageryLayers图层
    map.getImageryLayers = function (_keys) {
      var _map$imageryLayers2;
      var layers = (map === null || map === void 0 || (_map$imageryLayers2 = map.imageryLayers) === null || _map$imageryLayers2 === void 0 ? void 0 : _map$imageryLayers2._layers) || [];
      if (_keys && layers.length) {
        var keys = Array.isArray(_keys) ? _keys : [_keys];
        return layers.filter(function (layer) {
          return layer.key && keys.includes(layer.key);
        });
      }
      return layers;
    };

    // 通过图形查询所属图层
    map.getLayerByFeature = function (entity) {
      if (!entity) return;
      return map.getAllLayers().find(function (layer) {
        if (entity instanceof _cesium.ImageryLayerFeatureInfo) {
          var _entity$imageryLayer;
          if (layer !== null && layer !== void 0 && layer.key && layer.key === (entity === null || entity === void 0 || (_entity$imageryLayer = entity.imageryLayer) === null || _entity$imageryLayer === void 0 ? void 0 : _entity$imageryLayer.key)) {
            return layer;
          }
        } else if (layer instanceof _cesium.Cesium3DTileset && entity instanceof _cesium.Cesium3DTileFeature) {
          var _entity$primitive;
          if (layer !== null && layer !== void 0 && layer.key && layer.key === (entity === null || entity === void 0 || (_entity$primitive = entity.primitive) === null || _entity$primitive === void 0 ? void 0 : _entity$primitive.key)) {
            return layer;
          }
        } else if (layer instanceof _cesium.Primitive) {
          var _entity$primitive2;
          if (layer !== null && layer !== void 0 && layer.key && layer.key === (entity === null || entity === void 0 || (_entity$primitive2 = entity.primitive) === null || _entity$primitive2 === void 0 ? void 0 : _entity$primitive2.key)) {
            return layer;
          }
        } else {
          if (layer !== null && layer !== void 0 && layer.key && layer.key === (entity === null || entity === void 0 ? void 0 : entity.key)) {
            return layer;
          }
        }
      });
    };

    // 获取 3DTiles feature 属性
    map.get3DTileFeatureProperties = function (feature) {
      var properties = {};
      if (feature && feature.getPropertyNames) {
        var propertyIds = feature.getPropertyNames() || [];
        if (propertyIds !== null && propertyIds !== void 0 && propertyIds.length) {
          var length = propertyIds.length;
          for (var i = 0; i < length; ++i) {
            var propertyId = propertyIds[i];
            properties[propertyId] = feature.getProperty(propertyId);
          }
        }
      }
      return properties;
    };

    // 获取entity中数据
    map.getProperties = function (feature) {
      var _feature$primitive;
      if (feature instanceof _cesium.Cesium3DTileFeature) {
        return map.get3DTileFeatureProperties(feature);
      } else if (feature !== null && feature !== void 0 && (_feature$primitive = feature.primitive) !== null && _feature$primitive !== void 0 && _feature$primitive.data && (feature === null || feature === void 0 ? void 0 : feature.primitive) instanceof _cesium.Primitive) {
        return feature.primitive.data.find(function (item) {
          return item.id === feature.id;
        });
      } else {
        var _feature$_properties, _properties;
        var properties = (feature === null || feature === void 0 || (_feature$_properties = feature._properties) === null || _feature$_properties === void 0 ? void 0 : _feature$_properties.getValue(feature._id)) || (feature === null || feature === void 0 ? void 0 : feature.properties) || {};
        properties = ((_properties = properties) === null || _properties === void 0 ? void 0 : _properties.properties) || properties;
        return properties;
      }
    };

    // 通过key查询图层
    map.getLayerByKey = function (key) {
      return map.getAllLayers().find(function (layer) {
        return key && layer.key && layer.key === key;
      });
    };

    // 根据id查询图层
    map.getLayerById = map.getLayerByKey;

    // 通过keys查询多个图层
    map.getLayerByKeys = function (keys) {
      return map.getAllLayers().filter(function (layer) {
        return layer.key && keys.includes(layer.key);
      });
    };
    map.destroyhighlightLayer = function () {
      map.highlightLayer.clearFeatures();
    };
    // 添加高亮entity
    map.addHighlightFeature = function (feature, style) {
      map.highlightLayer.addHighlightFeature(feature, style);
    };
    // 通过返回值控制是否执行关闭
    map.onCloseTemplateBefore = function (feature) {
      // 清除高亮
      map.destroyhighlightLayer();
      if (onCloseTemplateBefore) {
        return onCloseTemplateBefore(feature);
      }
    };

    // 根据key查找展示的图层
    map.getVisibleLayersByKeys = function (keys) {
      var layers = map.getAllLayers() || [];
      return layers.filter(function (layer) {
        if (typeof keys === 'string') {
          return layer.key === keys && layer.show;
        } else if (Array.isArray(keys)) {
          return keys.includes(layer.key) && layer.show;
        } else {
          return layer.show && layer.key;
        }
      });
    };

    // 展示提示
    map.showTip = function (content) {
      setTip(content);
    };

    // 隐藏提示
    map.hideTip = function () {
      setTip(null);
    };

    // 根据图层条件设置图层选中
    map.showTemplateByFilter = /*#__PURE__*/function () {
      var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(key, field, value, _highlightLayer) {
        var layer, obj;
        return _regenerator().w(function (_context) {
          while (1) switch (_context.n) {
            case 0:
              layer = map.getLayerByKey(key);
              if (layer !== null && layer !== void 0 && layer.show) {
                obj = layer.getFeatureByFieldValue(field, value);
                if (obj) {
                  if (obj.then) {
                    obj.then(function (features) {
                      if (features !== null && features !== void 0 && features.length) {
                        var feature = features[0];
                        map.showTemplate(feature.feature, _highlightLayer || map.highlightLayer);
                      }
                    });
                  } else {
                    map.showTemplate(obj, _highlightLayer || map.highlightLayer);
                  }
                } else {
                  map.hideTemplate();
                }
              }
            case 1:
              return _context.a(2);
          }
        }, _callee);
      }));
      return function (_x, _x2, _x3, _x4) {
        return _ref.apply(this, arguments);
      };
    }();

    // 展示看板
    map.showTemplate = function (feature) {
      popupRef.current.showTemplate(feature);
    };

    // 隐藏看板
    map.hideTemplate = function () {
      popupRef.current.hideTemplate();
    };

    // 鼠标事件控制器
    var handleEvent = new _cesium.ScreenSpaceEventHandler(map.scene.canvas);

    // 获取图层上的图形信息
    map.pickDataSourcesFeature = function (event) {
      if (event !== null && event !== void 0 && event.position) {
        var _pick;
        var position = event.position;
        var pick = map.scene.pick(position);
        if ((0, _lodash.isObject)((_pick = pick) === null || _pick === void 0 ? void 0 : _pick.id)) {
          pick = pick.id;
        }
        if (checkClickable(pick)) {
          return;
        }
        return pick;
      }
    };

    // 根据关键字获取图形信息
    map.getMapFeatureInfoByText = getMapFeatureInfoByText;

    // 获取wms的图形数据
    map.pickImageryLayerFeatures = function (event) {
      if (event !== null && event !== void 0 && event.position) {
        var position = event.position;
        var pickRay = map.camera.getPickRay(position);
        return map.imageryLayers.pickImageryLayerFeatures(pickRay, map.scene);
      }
    };

    // 获取当前地图中心的经纬度
    map.getCenterPosition = function () {
      var centerResult = map.camera.pickEllipsoid(new _cesium.Cartesian2(map.canvas.clientWidth / 2, map.canvas.clientHeight / 2));
      var curPosition = _cesium.Ellipsoid.WGS84.cartesianToCartographic(centerResult);
      var curLongitude = curPosition.longitude * 180 / window.Math.PI;
      var curLatitude = curPosition.latitude * 180 / window.Math.PI;
      return [curLongitude, curLatitude];
    };

    // 二三维切换
    map.setViewMode = function (type) {
      map.viewMode = type;
      map.fitView();
    };

    // 获取地图视角信息
    map.getViewOptions = function () {
      //获取当前视角的pitch
      var pitch = map.camera.pitch;

      //获取当前视角的heading
      var heading = map.camera.heading;

      //获取当前视角的 position（位置）
      var position = map.camera.position;
      var cameraHeight = map.camera.positionCartographic.height;

      // 经纬高对象
      var cartographic = _cesium.Cartographic.fromCartesian(position);
      var x = _cesium.Math.toDegrees(cartographic.longitude);
      var y = _cesium.Math.toDegrees(cartographic.latitude);
      return {
        z: cameraHeight,
        x: x,
        y: y,
        pitch: _cesium.Math.toDegrees(pitch || 0.0),
        heading: _cesium.Math.toDegrees(heading || 0.0)
      };
    };

    // 获取当前地图视图的边界
    map.getViewExtend = function () {
      var params = {};
      var extend = map.camera.computeViewRectangle();
      if (typeof extend === 'undefined') {
        //2D下会可能拾取不到坐标，extend返回undefined,因此作如下转换
        var canvas = map.scene.canvas;
        var upperLeft = new _cesium.Cartesian2(0, 0); //canvas左上角坐标转2d坐标
        var lowerRight = new _cesium.Cartesian2(canvas.clientWidth, canvas.clientHeight); //canvas右下角坐标转2d坐标

        var ellipsoid = map.scene.globe.ellipsoid;
        var upperLeft3 = map.camera.pickEllipsoid(upperLeft, ellipsoid); //2D转3D世界坐标

        var lowerRight3 = map.camera.pickEllipsoid(lowerRight, ellipsoid); //2D转3D世界坐标

        var upperLeftCartographic = map.scene.globe.ellipsoid.cartesianToCartographic(upperLeft3); //3D世界坐标转弧度
        var lowerRightCartographic = map.scene.globe.ellipsoid.cartesianToCartographic(lowerRight3); //3D世界坐标转弧度

        var minx = _cesium.Math.toDegrees(upperLeftCartographic.longitude); //弧度转经纬度
        var maxx = _cesium.Math.toDegrees(lowerRightCartographic.longitude); //弧度转经纬度

        var miny = _cesium.Math.toDegrees(lowerRightCartographic.latitude); //弧度转经纬度
        var maxy = _cesium.Math.toDegrees(upperLeftCartographic.latitude); //弧度转经纬度

        params.minx = minx;
        params.maxx = maxx;
        params.miny = miny;
        params.maxy = maxy;
      } else {
        //3D获取方式
        params.maxx = _cesium.Math.toDegrees(extend.east);
        params.maxy = _cesium.Math.toDegrees(extend.north);
        params.minx = _cesium.Math.toDegrees(extend.west);
        params.miny = _cesium.Math.toDegrees(extend.south);
      }

      // 返回屏幕所在经纬度范围
      return params;
    };

    // 根据camera高度近似计算当前层级
    map.heightToZoom = _heightAndZoom.heightToZoom;

    // 根据当前层级近似计算camera高度
    map.zoomToHeight = _heightAndZoom.zoomToHeight;

    // 注册事件
    (0, _events.registerEventLayer)(map, props);

    // 注册地图组件事件
    function registerMapEvent(e, event) {
      if (map[event]) {
        map[event](e);
        onEvents[event] && onEvents[event](e);
      }
    }

    // 注册图层组件事件
    function registerEvent(feature, event, eventName) {
      if (feature) {
        var layer = map.getLayerByFeature(feature);
        if (layer !== null && layer !== void 0 && layer[eventName] || feature[eventName]) {
          var _feature$eventName;
          var properties = map.getProperties(feature) || {};
          if (feature instanceof _cesium.ImageryLayerFeatureInfo && feature !== null && feature !== void 0 && feature.data) {
            properties = _objectSpread(_objectSpread({}, properties), {}, {
              data: feature === null || feature === void 0 ? void 0 : feature.data
            });
          }

          // 触发自身事件
          (_feature$eventName = feature[eventName]) === null || _feature$eventName === void 0 || _feature$eventName.call(feature, properties, {
            feature: feature,
            event: event
          });
          if (layer !== null && layer !== void 0 && layer[eventName]) {
            layer[eventName](properties, {
              feature: feature,
              event: event
            });
          }
        }
      }
    }

    // 监测图层是否允许点击
    function checkClickable(feature) {
      var layer = map.getLayerByFeature(feature);
      var unclickable = false;
      // 无法单独设置group内的图层
      // 暂时为了取消行政区划影像图层的点击效果
      if (layer) {
        unclickable = layer.viewOnly || layer.unclickable;
      }
      return unclickable;
    }

    // 点击事件
    handleEvent.setInputAction(function (event) {
      event.lonLat = map.getPositionLonLat(event);
      map._clickObject = event;
      registerMapEvent(event, 'onClick');
      map.hideTip();

      // 是否禁止冒泡
      if (!map.cancelBubble) {
        var pick = map.scene.pick(event.position);
        if (pick instanceof _cesium.Cesium3DTileFeature) {
          var layer = map.getLayerByFeature(pick);
          if (layer) {
            if (layer.unclickable) {
              return;
            }
            registerEvent(pick, event, 'onClick');
            if (layer.template) {
              map.onClickTemplateAfter && map.onClickTemplateAfter(pick);
              map.showTemplate(pick);
            }
          }
        } else {
          var entity = map.pickDataSourcesFeature(event);
          var featuresPromise = map.pickImageryLayerFeatures(event);
          if (entity) {
            registerEvent(entity, event, 'onClick');
            var _layer = map.getLayerByFeature((entity === null || entity === void 0 ? void 0 : entity[0]) || entity);
            if (Array.isArray(entity) || _layer && _layer.template) {
              var _layer$cluster;
              map.onClickTemplateAfter && map.onClickTemplateAfter(entity);
              if (Array.isArray(entity) && (entity === null || entity === void 0 ? void 0 : entity.length) > 1 && _layer !== null && _layer !== void 0 && (_layer$cluster = _layer.cluster) !== null && _layer$cluster !== void 0 && _layer$cluster.hideTemplate) {
                return;
              }
              map.showTemplate(entity);
            }
          } else if ((0, _cesium.defined)(featuresPromise)) {
            // 兼容1.98.0版本
            var handleFeatures = function handleFeatures(features) {
              features.sort(function (a, b) {
                return b.imageryLayer._layerIndex - a.imageryLayer._layerIndex;
              });
              var feature = features === null || features === void 0 ? void 0 : features[0];
              if (checkClickable(feature)) {
                return;
              }
              registerEvent(feature, event, 'onClick');
              map.showTemplate(feature);
            };

            // 针对低于 1.90.0 版本
            if (_cesium.when) {
              (0, _cesium.when)(featuresPromise, handleFeatures);
            } else {
              featuresPromise.then(handleFeatures);
            }
          }
        }
      }
    }, _cesium.ScreenSpaceEventType.LEFT_CLICK);

    // 双击事件
    handleEvent.setInputAction(function (event) {
      map.trackedEntity = undefined; // 取消双击锁定

      event.lonLat = map.getPositionLonLat(event);
      registerMapEvent(event, 'onDoubleClick');
      var feature = map.pickDataSourcesFeature(event);
      registerEvent(feature, event, 'onDoubleClick');
    }, _cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);

    // 鼠标移动
    var hoverFeature;
    var getUid = function getUid(feature) {
      if (feature && !feature._id) {
        feature._id = window.Math.random();
      }
      return feature._id;
    };

    // 鼠标移入移出
    handleEvent.setInputAction(function (event) {
      event.lonLat = map.getPositionLonLat({
        position: event.endPosition
      });
      registerMapEvent(event, 'onMouseMove');
      var feature = map.pickDataSourcesFeature({
        position: event.endPosition
      });
      if (feature) {
        var layer = map.getLayerByFeature(feature);
        if (layer && (layer.labelField || layer.tipTemplate)) {
          var labelField = layer.labelField,
            tipTemplate = layer.tipTemplate;
          var properties = map.getProperties(feature);
          var label;
          if (tipTemplate) {
            label = tipTemplate(properties);
          } else {
            label = properties ? properties[labelField] : '';
          }
          if (label) {
            map.showTip(label);
          } else {
            map.hideTip();
          }
        } else {
          map.hideTip();
        }
        registerEvent(feature, event, 'onMouseMove');

        // 判断是否在图形内移动
        if (hoverFeature) {
          var uid = getUid(feature);
          var hoverUid = getUid(hoverFeature);

          // 判断是否进入新的图形
          if (uid !== hoverUid) {
            registerEvent(hoverFeature, event, 'onMouseLeave');
            registerEvent(feature, event, 'onMouseEnter');
            hoverFeature = feature;
          }
        } else {
          registerEvent(feature, event, 'onMouseEnter');
          hoverFeature = feature;
        }
        registerEvent(feature, event, 'onMouseMove');
      } else {
        if (hoverFeature) {
          registerEvent(hoverFeature, event, 'onMouseLeave');
        }
        hoverFeature = null;
        map.hideTip();
      }
    }, _cesium.ScreenSpaceEventType.MOUSE_MOVE);

    // 层级事件
    if (onZoom) {
      map.camera.moveEnd.addEventListener(function () {
        var viewRectangle = map.camera.computeViewRectangle();
        var west = viewRectangle.west / window.Math.PI * 180; // 左上方（西）
        var north = viewRectangle.north / window.Math.PI * 180; //右上方（北）
        var east = viewRectangle.east / window.Math.PI * 180; // 右下方（东）
        var south = viewRectangle.south / window.Math.PI * 180; // 左下方（南）
        var cameraHeight = map.camera.positionCartographic.height;
        var zoom = map.heightToZoom(window.Math.ceil(cameraHeight));
        onZoom && onZoom({
          west: west,
          north: north,
          east: east,
          south: south,
          cameraHeight: cameraHeight,
          viewRectangle: viewRectangle,
          zoom: zoom
        });
      });
    }

    // 动态调整视角，不传参数为默认视角，参数可以是图层、图形、数据等
    map.fitView = function (e) {
      var _ref2 = e || {},
        geoJson = _ref2.geoJson,
        geometryInfo = _ref2.geometryInfo,
        data = _ref2.data,
        entity = _ref2.entity,
        lng = _ref2.lng,
        lat = _ref2.lat,
        _ref2$height = _ref2.height,
        height = _ref2$height === void 0 ? 50000 : _ref2$height,
        options = _ref2.options,
        rest = _objectWithoutProperties(_ref2, _excluded2);
      var pitch = map.camera.pitch;

      // 判断是否点击了图形
      if (entity) {
        if (map.viewMode === '3D') {
          map.flyTo(entity, {
            duration: 2
          });
        } else {
          map.flyTo(entity, {
            duration: 2,
            offset: {
              heading: _cesium.Math.toRadians(0.0),
              pitch: pitch,
              range: height
            }
          });
        }
      } else if (lng && lat) {
        map.camera.flyTo(_objectSpread({
          destination: new _cesium.Cartesian3.fromDegrees(Number(lng), Number(lat), height),
          orientation: {
            pitch: _cesium.Math.toRadians(map.viewDefault.pitch || -88.0),
            roll: 0.0
          },
          duration: 2
        }, rest));
      } else if (data || geometryInfo || geoJson) {
        var _geoJson = geoJson;
        if (geometryInfo) {
          _geoJson = (0, _createFeatureCollection.createFeatureCollection)([{
            geometryInfo: geometryInfo
          }]);
        }
        if (data) {
          _geoJson = (0, _createFeatureCollection.createFeatureCollection)(Array.isArray(data) ? data : [data]);
        }
        var box = (0, _getBBoxFromGeojson["default"])(_geoJson, _objectSpread({
          padding: 100,
          unit: 'px'
        }, options)); // 单位为米

        var point1 = (0, _turf.point)([box[0], box[1]]);
        var point2 = (0, _turf.point)([box[2], box[3]]);
        var centerPoint = (0, _turf.midpoint)(point1, point2);
        var z = (0, _turf.distance)(point1, point2) * (map.viewMode === '3D' ? 1100 : 1600);
        var heading = _cesium.Math.toRadians(map.viewDefault.heading || 0.0);
        var _pitch = _cesium.Math.toRadians(map.viewDefault.pitch);
        var _center = _cesium.Cartesian3.fromDegrees.apply(_cesium.Cartesian3, _toConsumableArray(centerPoint.geometry.coordinates));
        map.camera.flyToBoundingSphere(new _cesium.BoundingSphere(_center, z), {
          offset: new _cesium.HeadingPitchRange(heading, _pitch, z),
          duration: 2
        });

        // map.camera.flyTo({
        //     destination: new Rectangle.fromDegrees(...box), //west, south, east, north,
        //     orientation: {
        //         pitch: map.viewMode === '3D' ? CesiumMath.toRadians(-35) : CesiumMath.toRadians(defaultPitch),
        //         // roll: 0.0,
        //     },
        //     duration: 2,
        //     ...rest,
        // });
      } else {
        var _map$viewDefault$cent = _slicedToArray(map.viewDefault.center, 3),
          x = _map$viewDefault$cent[0],
          y = _map$viewDefault$cent[1],
          _map$viewDefault$cent2 = _map$viewDefault$cent[2],
          _z2 = _map$viewDefault$cent2 === void 0 ? 80000.0 : _map$viewDefault$cent2;
        if (map.viewMode === '3D') {
          var _center2 = _cesium.Cartesian3.fromDegrees(x, y);
          var _heading = _cesium.Math.toRadians(map.viewDefault.heading || 0.0);
          var _pitch2 = _cesium.Math.toRadians(-35.0);
          map.camera.flyToBoundingSphere(new _cesium.BoundingSphere(_center2, _z2), {
            offset: new _cesium.HeadingPitchRange(_heading, _pitch2, _z2),
            duration: 2
          });
        } else {
          map.camera.flyTo({
            destination: new _cesium.Cartesian3.fromDegrees(x, y, _z2),
            orientation: {
              pitch: _cesium.Math.toRadians(map.viewDefault.pitch || 0.0),
              heading: _cesium.Math.toRadians(map.viewDefault.heading || 0.0),
              roll: 0.0
            },
            duration: 2
          });
        }
      }
    };
    map.fitViewByOptions = function (options) {
      var x = options.x,
        y = options.y,
        z = options.z,
        heading = options.heading,
        pitch = options.pitch,
        duration = options.duration;
      if (x && y) {
        var _z = z || map.camera.positionCartographic.height;
        map.camera.flyTo({
          destination: new _cesium.Cartesian3.fromDegrees(x, y, _z),
          // 定位到范围中心点
          orientation: {
            heading: _cesium.Math.toRadians(heading || 0.0),
            // 左右方向
            pitch: _cesium.Math.toRadians(pitch || 0.0),
            // 上下方向
            roll: 0.0
          },
          duration: duration || 1
        });
      }
    };
    map.getPositionLonLat = function (event) {
      var cartesian = map.camera.pickEllipsoid(event.position, map.scene.globe.ellipsoid); // Cartesian3对象
      if (cartesian) {
        var cartographic = _cesium.Cartographic.fromCartesian(cartesian); // 经纬高对象
        var lng = _cesium.Math.toDegrees(cartographic.longitude);
        var lat = _cesium.Math.toDegrees(cartographic.latitude);
        return [lng, lat];
      }
      return [];
    };
    if (duration) {
      // 自动调整视角
      map.fitView();

      // 延时触发回调事件
      setTimeout(function () {
        createdMap && createdMap(map, handleEvent);
        addLabelImageryProvider();
        onEvents.createdMap && onEvents.createdMap(map, handleEvent);
        setMapLoaded(true);
      }, (duration + 0.5) * 1000);
    } else {
      var _map$viewDefault$cent3 = _slicedToArray(map.viewDefault.center, 3),
        x = _map$viewDefault$cent3[0],
        y = _map$viewDefault$cent3[1],
        _map$viewDefault$cent4 = _map$viewDefault$cent3[2],
        z = _map$viewDefault$cent4 === void 0 ? 80000.0 : _map$viewDefault$cent4;
      if (map.viewMode === '3D') {
        var _center3 = _cesium.Cartesian3.fromDegrees(x, y);
        var heading = _cesium.Math.toRadians(map.viewDefault.heading || 0.0);
        var pitch = _cesium.Math.toRadians(map.viewDefault.pitch || -35.0);
        map.camera.flyToBoundingSphere(new _cesium.BoundingSphere(_center3, z), {
          offset: new _cesium.HeadingPitchRange(heading, pitch, z),
          duration: 0
        });
      } else {
        map.camera.setView({
          destination: new _cesium.Cartesian3.fromDegrees(x, y, z),
          orientation: {
            pitch: _cesium.Math.toRadians(map.viewDefault.pitch || 0.0),
            heading: _cesium.Math.toRadians(map.viewDefault.heading || 0.0),
            roll: 0.0 // default value
          }
        });
      }

      // 延时触发回调事件
      setTimeout(function () {
        createdMap && createdMap(map, handleEvent);
        addLabelImageryProvider();
        onEvents.createdMap && onEvents.createdMap(map, handleEvent);
        setMapLoaded(true);
      }, 500);
    }
  };
  var onMouseMove = function onMouseMove(event) {
    if (tip && tipRef.current) {
      tipRef.current.style.left = "".concat(event.nativeEvent.layerX + 15, "px");
      tipRef.current.style.top = "".concat(event.nativeEvent.layerY + 15, "px");
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: _objectSpread({
      width: width,
      height: height,
      background: baseColor || dark ? '#152937' : '#cccccc'
    }, wrapDomStyle),
    className: (0, _classnames["default"])('cs-map-container')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    ref: mapDomRef,
    className: (0, _classnames["default"])('cs-map'),
    onMouseMove: onMouseMove,
    onMouseOver: function onMouseOver() {
      return setTipVis(true);
    },
    onMouseOut: function onMouseOut() {
      return setTipVis(false);
    },
    style: mapDomStyle
  }, tip && tipVis && /*#__PURE__*/_react["default"].createElement("div", {
    ref: tipRef,
    className: (0, _classnames["default"])('custom-tip')
  }, tip)), mapLoaded && /*#__PURE__*/_react["default"].createElement(_Provider["default"], {
    value: {
      map: mapRef.current,
      showModal: props.showModal
    }
  }, children, mapRef.current && /*#__PURE__*/_react["default"].createElement(_Popup["default"], {
    ref: popupRef,
    map: mapRef.current
  })));
}
var _default = exports["default"] = Map;
Map.propTypes = {
  width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  height: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  createdMap: _propTypes["default"].func,
  onCloseTemplateBefore: _propTypes["default"].func,
  onZoom: _propTypes["default"].func,
  center: _propTypes["default"].array,
  zoom: _propTypes["default"].number,
  minZoom: _propTypes["default"].number,
  maxZoom: _propTypes["default"].number,
  defaultPitch: _propTypes["default"].number,
  dark: _propTypes["default"].bool,
  baseColor: _propTypes["default"].string,
  mapStyle: _propTypes["default"].oneOfType(['vec', 'img']),
  tk: _propTypes["default"].string.isRequired,
  onEvents: _propTypes["default"].object,
  baseMapUrl: _propTypes["default"].string,
  duration: _propTypes["default"].number,
  baseMapStyle: _propTypes["default"].object,
  children: _propTypes["default"].node,
  autoView: _propTypes["default"].bool,
  closePopupAutoView: _propTypes["default"].bool,
  highlightColor: _propTypes["default"].string,
  viewMode: _propTypes["default"].string,
  showModal: _propTypes["default"].func,
  wrapDomStyle: _propTypes["default"].object,
  mapDomStyle: _propTypes["default"].object,
  baseMapOptions: _propTypes["default"].object,
  setLoading: _propTypes["default"].func,
  fitViewHeight: _propTypes["default"].number,
  hideHighlight: _propTypes["default"].bool,
  defaultView: _propTypes["default"].object
};
//# sourceMappingURL=index.js.map
