"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 _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"],
  _excluded2 = ["geoJson", "geometryInfo", "data", "entity", "lng", "lat", "height", "options"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
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 s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(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 (e.includes(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: 'GeoQImageryProvider',
      style: 'Blue'
    } : _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);
    }
  }, [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,
      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 = {
      center: center || longitude && latitude && [longitude, latitude] || [120.081627, 30.89638],
      zoom: zoom || defaultZoomLevel && Number(defaultZoomLevel) || 0,
      minZoom: minZoom && Number(minZoom) || 0,
      maxZoom: maxZoom && Number(maxZoom) || 20
    };
    if (viewDefault.zoom && !viewDefault.center[3]) {
      var z = (0, _heightAndZoom.zoomToHeight)(viewDefault.zoom);
      viewDefault.center = [viewDefault.center[0], viewDefault.center[1], z];
    }
    _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
    }, 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));

    // 设置地球暗色
    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__*/_regeneratorRuntime().mark(function _callee(key, field, value, _highlightLayer) {
        var layer, obj;
        return _regeneratorRuntime().wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            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 2:
            case "end":
              return _context.stop();
          }
        }, _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 position = event.position;
        var pick = map.scene.pick(position);
        if ((0, _lodash.isObject)(pick === null || pick === void 0 ? void 0 : pick.id)) {
          return pick.id;
        }
        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.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(-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)); // 单位为米

        map.camera.flyTo(_objectSpread({
          destination: _construct(_cesium.Rectangle.fromDegrees, _toConsumableArray(box)),
          //west, south, east, north,
          orientation: {
            pitch: map.viewMode === '3D' ? _cesium.Math.toRadians(-35) : _cesium.Math.toRadians(defaultPitch),
            roll: 0.0
          },
          duration: 2
        }, rest));
      } else {
        var _viewDefault$center = _slicedToArray(viewDefault.center, 3),
          x = _viewDefault$center[0],
          y = _viewDefault$center[1],
          _viewDefault$center$ = _viewDefault$center[2],
          _z = _viewDefault$center$ === void 0 ? 80000.0 : _viewDefault$center$;
        if (map.viewMode === '3D') {
          var _center = _cesium.Cartesian3.fromDegrees(x, y);
          var heading = _cesium.Math.toRadians(0.0);
          var _pitch = _cesium.Math.toRadians(-35.0);
          map.camera.flyToBoundingSphere(new _cesium.BoundingSphere(_center, _z), {
            offset: new _cesium.HeadingPitchRange(heading, _pitch, _z),
            duration: 2
          });
        } else {
          map.camera.flyTo({
            destination: new _cesium.Cartesian3.fromDegrees(x, y, _z),
            orientation: {
              pitch: _cesium.Math.toRadians(defaultPitch),
              roll: 0.0
            },
            duration: 2
          });
        }
      }
    };
    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 _viewDefault$center2 = _slicedToArray(viewDefault.center, 3),
        x = _viewDefault$center2[0],
        y = _viewDefault$center2[1],
        _viewDefault$center2$ = _viewDefault$center2[2],
        _z2 = _viewDefault$center2$ === void 0 ? 80000.0 : _viewDefault$center2$;
      if (map.viewMode === '3D') {
        var _center2 = _cesium.Cartesian3.fromDegrees(x, y);
        var heading = _cesium.Math.toRadians(0.0);
        var pitch = _cesium.Math.toRadians(-35.0);
        map.camera.flyToBoundingSphere(new _cesium.BoundingSphere(_center2, _z2), {
          offset: new _cesium.HeadingPitchRange(heading, pitch, _z2),
          duration: 0
        });
      } else {
        map.camera.setView({
          destination: new _cesium.Cartesian3.fromDegrees(x, y, _z2)
        });
      }

      // 延时触发回调事件
      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
};
//# sourceMappingURL=index.js.map
