"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 _antd = require("antd");
var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ol = require("ol");
var _layer = require("ol/layer");
var _source = require("ol/source");
var _control = require("ol/control");
var _util = require("ol/util");
var _classnames = _interopRequireDefault(require("classnames"));
var _getDefaultMapInfo = _interopRequireDefault(require("../_util/getDefaultMapInfo"));
var _Popup = _interopRequireDefault(require("./Popup"));
var _getBaseLayers = _interopRequireDefault(require("./getBaseLayers"));
var _TdtImageryProvider = _interopRequireDefault(require("./getBaseLayers/imagery/tdt/TdtImageryProvider"));
var _HighLayer = _interopRequireDefault(require("../tools/Utils/HighLayer"));
var _Search = require("../tools/Search");
var _events = require("../events");
var _layer2 = require("../_util/layer");
var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
var _FeatureLayer = _interopRequireDefault(require("../feature-layer/FeatureLayer"));
var _ImageLayer = _interopRequireDefault(require("../image-layer/ImageLayer"));
var _ImageTileLayer = _interopRequireDefault(require("../image-layer/ImageTileLayer"));
var _ahooks = require("ahooks");
var _provider = _interopRequireDefault(require("../provider"));
var _Layers = _interopRequireDefault(require("./Layers"));
var _Analysis = _interopRequireDefault(require("./Analysis"));
var _WmsLayer = _interopRequireDefault(require("../wms-layer/WmsLayer"));
require("ol/ol.css");
require("./style");
var _search = require("../_util/search");
var _lodash = require("lodash");
var _excluded = ["minZoom", "maxZoom", "defaultZoomLevel", "longitude", "latitude"];
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 _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 _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 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 _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 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 _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,
    children = props.children,
    center = props.center,
    dark = props.dark,
    style = props.style,
    zoom = props.zoom,
    createdMap = props.createdMap,
    mapStyle = props.mapStyle,
    baseMapStyle = props.baseMapStyle,
    tk = props.tk,
    onCloseTemplateBefore = props.onCloseTemplateBefore,
    onZoom = props.onZoom,
    customBaseLayers = props.customBaseLayers,
    positionStyle = props.positionStyle,
    _props$autoView = props.autoView,
    autoView = _props$autoView === void 0 ? true : _props$autoView,
    _props$closePopupAuto = props.closePopupAutoView,
    closePopupAutoView = _props$closePopupAuto === void 0 ? true : _props$closePopupAuto,
    hidePopupTable = props.hidePopupTable,
    fitViewMaxZoom = props.fitViewMaxZoom,
    encrypt = props.encrypt;
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    mapLoaded = _useState2[0],
    setMapLoaded = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    setModal = _useState4[1];
  var _useState5 = (0, _react.useState)(false),
    _useState6 = _slicedToArray(_useState5, 2),
    tipVis = _useState6[0],
    setTipVis = _useState6[1];
  var _useState7 = (0, _react.useState)(null),
    _useState8 = _slicedToArray(_useState7, 2),
    tip = _useState8[0],
    setTip = _useState8[1];
  var _useState9 = (0, _react.useState)(null),
    _useState10 = _slicedToArray(_useState9, 2),
    pointTip = _useState10[0],
    setPointTip = _useState10[1];
  var mapRef = (0, _react.useRef)(null);
  var timerRef = (0, _react.useRef)(null);
  var mapDomRef = (0, _react.useRef)(null);
  var highLayerRef = (0, _react.useRef)();
  var popupRef = (0, _react.useRef)();
  var timeRef = (0, _react.useRef)(null);
  var baseLayerRef = (0, _react.useRef)([]);
  (0, _react.useEffect)(function () {
    initMap();
    return function () {
      window.removeEventListener('resize', handleResize);
      highLayerRef.current && highLayerRef.current.destroy();
    };
  }, []);
  (0, _react.useEffect)(function () {
    if (mapRef.current) {
      timerRef.current = setInterval(function () {
        var layers = mapRef.current.getLayers().getArray() || [];
        layers.map(function (v) {
          if (v.autoRefresh && v.key && v.get('visible') && v.refresh) {
            v.refresh();
          }
        });
      }, 10000);
    }
    return function () {
      if (timerRef.current) {
        clearInterval(timerRef.current);
      }
    };
  }, []);
  (0, _ahooks.useUpdateEffect)(function () {
    mapRef.current.setMapStyle(mapStyle);
  }, [mapStyle]);
  var initMap = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
      var _baseLayerRef$current;
      var defaultMapInfo, minZoom, maxZoom, defaultZoomLevel, longitude, latitude, otherDefaultMapInfo, viewDefault, map, baseLayerParams, _baseLayerRef$current2, registerMapEvent, registerEvent, hoverFeature;
      return _regeneratorRuntime().wrap(function _callee3$(_context3) {
        while (1) switch (_context3.prev = _context3.next) {
          case 0:
            registerEvent = function _registerEvent(eventTarget, feature, event) {
              if (feature) {
                var _feature$eventTarget;
                var properties = feature.getProperties();

                // 触发自身事件
                (_feature$eventTarget = feature[eventTarget]) === null || _feature$eventTarget === void 0 || _feature$eventTarget.call(feature, properties, event);
                var layer = map.getLayerByFeature(feature);
                if (layer !== null && layer !== void 0 && layer[eventTarget]) {
                  layer[eventTarget](properties, event);
                }
              }
            };
            registerMapEvent = function _registerMapEvent(eventTarget, e) {
              if (map[eventTarget]) {
                map[eventTarget](e);
              }
            };
            defaultMapInfo = (0, _getDefaultMapInfo["default"])();
            minZoom = defaultMapInfo.minZoom, maxZoom = defaultMapInfo.maxZoom, defaultZoomLevel = defaultMapInfo.defaultZoomLevel, longitude = defaultMapInfo.longitude, latitude = defaultMapInfo.latitude, otherDefaultMapInfo = _objectWithoutProperties(defaultMapInfo, _excluded); // 全屏
            viewDefault = {
              center: center || longitude && latitude && [longitude, latitude] || [116.397228, 30.9096],
              zoom: zoom || defaultZoomLevel && Number(defaultZoomLevel) || 4,
              minZoom: minZoom && Number(minZoom) || props.minZoom || 4,
              maxZoom: maxZoom && Number(maxZoom) || props.maxZoom
            };
            map = new _ol.Map({
              target: mapDomRef.current,
              controls: (0, _control.defaults)({
                zoom: false
              }).extend([]),
              // layers: [...getBaseLayers({ mapStyle, dark, tk, baseMapStyle })],
              pixelRatio: 1,
              view: new _ol.View(_objectSpread(_objectSpread({}, viewDefault), {}, {
                projection: 'EPSG:4326',
                constrainResolution: true
              })),
              // 设置缩放级别为整数
              constrainResolution: true,
              // 关闭无级缩放地图
              smoothResolutionConstraint: false
            }); // 统一加密啊配置
            map.encrypt = encrypt;
            baseLayerParams = _objectSpread(_objectSpread({}, otherDefaultMapInfo), {}, {
              mapStyle: mapStyle || defaultMapInfo.mapStyle || 'vec',
              baseMapStyle: baseMapStyle || defaultMapInfo.baseMapStyle || 'TdtImageryProvider',
              dark: dark || defaultMapInfo.dark,
              tk: tk || defaultMapInfo.tk
            });
            if (customBaseLayers) {
              baseLayerRef.current = _toConsumableArray(customBaseLayers(baseLayerParams));
            } else {
              baseLayerRef.current = _toConsumableArray((0, _getBaseLayers["default"])(baseLayerParams));
            }

            // 用于鹰眼图层
            map.baseLayer = (0, _lodash.cloneDeep)(baseLayerRef.current);
            if ((_baseLayerRef$current = baseLayerRef.current) !== null && _baseLayerRef$current !== void 0 && _baseLayerRef$current.length) {
              (_baseLayerRef$current2 = baseLayerRef.current) === null || _baseLayerRef$current2 === void 0 || _baseLayerRef$current2.map(function (item) {
                map.addLayer(item);
              });
            }
            map.tk = tk;

            // 隐藏表格弹出框
            map.hidePopupTable = hidePopupTable;

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

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

            // 图层管理
            map.layers = new _Layers["default"]({
              map: map
            });

            // 分析管理
            map.analysis = new _Analysis["default"]({
              map: map
            });
            mapRef.current = map;

            // 地图视角默认配置
            map.viewDefault = viewDefault;

            // 设置地图底图样式
            map.setMapStyle = function (_mapStyle) {
              var _map$getLayerByKey, _map$getLayerByKey2;
              var _TdtImageryProvider$g = _TdtImageryProvider["default"].getSource({
                  mapStyle: _mapStyle,
                  tk: tk
                }),
                _TdtImageryProvider$g2 = _slicedToArray(_TdtImageryProvider$g, 2),
                tileLayerSource = _TdtImageryProvider$g2[0],
                markLayerSource = _TdtImageryProvider$g2[1];
              (_map$getLayerByKey = map.getLayerByKey('__TDT_TILE')) === null || _map$getLayerByKey === void 0 || _map$getLayerByKey.setSource(tileLayerSource);
              (_map$getLayerByKey2 = map.getLayerByKey('__TDT_MARK')) === null || _map$getLayerByKey2 === void 0 || _map$getLayerByKey2.setSource(markLayerSource);
            };

            // 高亮效果
            highLayerRef.current = new _HighLayer["default"]({
              map: map
            });
            map.highlightLayer = highLayerRef.current;

            // 切换底图
            map.changeBaseLayer = function (baseMapStyle) {
              var _baseLayerRef$current3, _baseLayerRef$current4;
              (_baseLayerRef$current3 = baseLayerRef.current) === null || _baseLayerRef$current3 === void 0 || _baseLayerRef$current3.map(function (item) {
                map.removeLayer(item);
              });
              baseLayerRef.current = _toConsumableArray((0, _getBaseLayers["default"])({
                mapStyle: mapStyle,
                dark: dark,
                tk: tk,
                baseMapStyle: baseMapStyle
              }));
              (_baseLayerRef$current4 = baseLayerRef.current) === null || _baseLayerRef$current4 === void 0 || _baseLayerRef$current4.map(function (item) {
                map.addLayer(item);
              });
              map.baseLayer = (0, _lodash.cloneDeep)(baseLayerRef.current);
            };

            // 获取基础图层
            map.getBaseLayers = _getBaseLayers["default"];

            // 设置高亮
            map.setHighlightFeature = function (feature) {
              map.highlightLayer.addHighlightFeature(feature);
            };

            // 清除高亮
            map.clearHighlightFeature = function () {
              map.highlightLayer.clearFeatures();
            };

            // 根 key 查找图层
            map.getLayerByKey = function (key) {
              return map.getAllLayers().find(function (layer) {
                if (layer.key === key) {
                  return layer;
                }
              });
            };

            // 查找展示的绑定key的wms图层
            map.getWmsVisibleLayers = function (keys) {
              var layers = [];
              var allLayers = map.getAllLayers();
              if (Array.isArray(keys) && keys !== null && keys !== void 0 && keys.length) {
                allLayers = allLayers.filter(function (item) {
                  return keys.includes(item.key);
                });
              }
              allLayers.map(function (layer) {
                if (layer.key && (layer instanceof _layer.Image || layer instanceof _ImageTileLayer["default"] || layer instanceof _ImageLayer["default"] || layer instanceof _WmsLayer["default"]) && layer.get('visible')) {
                  layers.push(layer);
                }
              });
              return layers;
            };

            // 查找展示的绑定key的wfs图层
            map.getWfsVisibleLayers = function (keys) {
              var layers = [];
              var allLayers = map.getAllLayers();
              if (Array.isArray(keys) && keys !== null && keys !== void 0 && keys.length) {
                allLayers = allLayers.filter(function (item) {
                  return keys.includes(item.key);
                });
              }
              allLayers.map(function (layer) {
                if (layer.key && layer instanceof _layer.Vector && layer.get('visible')) {
                  layers.push(layer);
                }
              });
              return layers;
            };

            // 根据key查找展示的图层,不传keys查所有展示的除底图的带key的图层
            map.getVisibleLayersByKeys = function (keys) {
              var layers = map.getAllLayers() || [];
              return layers.filter(function (layer) {
                if (typeof keys === 'string') {
                  return layer.key === keys && layer.get('visible');
                } else if (Array.isArray(keys)) {
                  return keys.includes(layer.key) && layer.get('visible');
                } else if (layer.key !== "Highlight") {
                  return layer.get('visible') && layer.key;
                }
              });
            };

            // 通过图形查询所属图层
            map.getLayerByFeature = function (feature) {
              return map.getAllLayers().find(function (layer) {
                if (layer.key) {
                  var _feature$values_, _feature$values_2;
                  if (feature !== null && feature !== void 0 && feature.key && feature.key === layer.key) {
                    return layer;
                  } else if (layer instanceof _layer.Vector && layer.key !== 'Highlight') {
                    var source = layer.getSource();
                    if (source.source && source.source.hasFeature(feature)) {
                      return layer;
                    } else if (source.hasFeature(feature)) {
                      return layer;
                    }
                  } else if (feature !== null && feature !== void 0 && feature.layerKey && (feature === null || feature === void 0 ? void 0 : feature.layerKey) === layer.key) {
                    return layer;
                  } else if (feature !== null && feature !== void 0 && (_feature$values_ = feature.values_) !== null && _feature$values_ !== void 0 && _feature$values_.key && layer.key === (feature === null || feature === void 0 || (_feature$values_2 = feature.values_) === null || _feature$values_2 === void 0 ? void 0 : _feature$values_2.key)) {
                    return layer;
                  }
                }
              });
            };

            // 根据关键字获取图形信息
            map.getMapFeatureInfoByText = function (text) {
              return (0, _Search.getMapFeatureInfoByText)(map, text);
            };

            // poi查询
            map.poiSearch = function () {
              var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
              return (0, _search.poiSearch)(params);
            };

            // 获取图层是否允许点击
            map.getLayerHasViewOnlyByFeature = function (feature) {
              var layer = map.getLayerByFeature(feature);
              return layer === null || layer === void 0 ? void 0 : layer.viewOnly;
            };

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

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

            // 隐藏提示
            map.hidePointTip = function () {
              setPointTip(null);
            };

            // 展示弹窗
            map.showModal = function (params) {
              setModal(params);
            };

            // 隐藏弹窗
            map.hideModal = function () {
              setModal(null);
            };

            // 根据图层条件设置图层选中
            map.showTemplateByFilter = /*#__PURE__*/function () {
              var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, field, value, options) {
                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 !== null && obj !== void 0 && obj.then) {
                          obj.then(function (features) {
                            if (features !== null && features !== void 0 && features.length) {
                              var feature = features[0];
                              map.showTemplate(feature.feature || feature, options);
                            }
                          });
                        } else {
                          if (obj) {
                            map.showTemplate(obj, options);
                          }
                        }
                      }
                    case 2:
                    case "end":
                      return _context.stop();
                  }
                }, _callee);
              }));
              return function (_x, _x2, _x3, _x4) {
                return _ref2.apply(this, arguments);
              };
            }();

            // 展示看板
            map.showTemplate = function (feature, options) {
              var _popupRef$current, _popupRef$current$sho;
              (_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 || (_popupRef$current$sho = _popupRef$current.showTemplate) === null || _popupRef$current$sho === void 0 || _popupRef$current$sho.call(_popupRef$current, feature, options);
            };

            // 隐藏看板
            map.hideTemplate = function () {
              var _popupRef$current2, _popupRef$current2$hi;
              (_popupRef$current2 = popupRef.current) === null || _popupRef$current2 === void 0 || (_popupRef$current2$hi = _popupRef$current2.hideTemplate) === null || _popupRef$current2$hi === void 0 || _popupRef$current2$hi.call(_popupRef$current2);
            };
            map.setLastView = function () {
              var _popupRef$current3, _popupRef$current3$se;
              (_popupRef$current3 = popupRef.current) === null || _popupRef$current3 === void 0 || (_popupRef$current3$se = _popupRef$current3.setLastView) === null || _popupRef$current3$se === void 0 || _popupRef$current3$se.call(_popupRef$current3);
            };

            // 下标显隐
            map.setLabelVisible = function (visible) {
              map.getAllLayers().find(function (layer) {
                if (layer instanceof _FeatureLayer["default"]) {
                  layer.label = visible;
                }
              });
            };

            // 聚合显隐
            map.setClusterVisible = function (visible) {
              map.getAllLayers().find(function (layer) {
                if (layer instanceof _FeatureLayer["default"]) {
                  layer.cluster = visible;
                }
              });
            };

            // 海量点显隐
            map.setPointVisible = function (visible) {
              map.getAllLayers().find(function (layer) {
                if (layer instanceof _FeatureLayer["default"]) {
                  layer.point = visible;
                }
              });
            };

            // 通过返回值控制是否执行关闭
            map.onCloseTemplateBefore = function (feature) {
              if (onCloseTemplateBefore) {
                return onCloseTemplateBefore(feature);
              }
            };
            map.getViewOptions = function () {
              var view = map.getView();
              var _view$getCenter = view.getCenter(),
                _view$getCenter2 = _slicedToArray(_view$getCenter, 2),
                x = _view$getCenter2[0],
                y = _view$getCenter2[1];
              return {
                zoom: view.getZoom(),
                x: x,
                y: y
              };
            };

            // 自适应
            map.fitView = function (e, options) {
              if (e) {
                var _e$values_;
                var extent;
                if (e instanceof _layer.Vector) {
                  // 针对图层处理
                  extent = e.getSource().getExtent();
                } else if (e instanceof _source.Vector) {
                  // 针对图层源处理
                  extent = e.getExtent();
                } else if (Array.isArray(e) || e.geometryInfo) {
                  var _e$;
                  // 针对数据处理
                  var vectorSource = new _source.Vector();
                  if (e.geometryInfo || e !== null && e !== void 0 && (_e$ = e[0]) !== null && _e$ !== void 0 && _e$.geometryInfo) {
                    // 针对数据处理
                    var f = (0, _createFeatureCollection.createGeoJson)(e);
                    vectorSource.addFeatures(f);
                  } else if (e instanceof _ol.Feature || (e === null || e === void 0 ? void 0 : e[0]) instanceof _ol.Feature) {
                    // 针对图形处理
                    vectorSource.addFeatures(e);
                  }
                  extent = vectorSource.getExtent();
                } else if (e !== null && e !== void 0 && (_e$values_ = e.values_) !== null && _e$values_ !== void 0 && _e$values_.geometry) {
                  // 针对单个图形
                  extent = e.values_.geometry.getExtent();
                }
                if (extent) {
                  if (e !== null && e !== void 0 && e.noFitView) {
                    return;
                  }
                  var currentZoom = map.getView().getZoom();
                  var _maxZoom = fitViewMaxZoom || 16;
                  map.getView().fit(extent, _objectSpread({
                    padding: [100, 400, 100, 400],
                    maxZoom: currentZoom > _maxZoom ? currentZoom : _maxZoom,
                    duration: 500
                  }, options));
                } else {
                  map.getView().animate(_objectSpread(_objectSpread({}, map.viewDefault), {}, {
                    duration: 500
                  }, options));
                }
              } else {
                map.getView().animate(_objectSpread(_objectSpread({}, map.viewDefault), {}, {
                  duration: 500
                }, options));
              }
            };
            map.fitViewByOptions = function (options) {
              var x = options.x,
                y = options.y,
                zoom = options.zoom;
              if (x && y) {
                var view = map.getView();
                view.animate({
                  zoom: zoom || view.getZoom(),
                  center: [Number(x), Number(y)]
                });
              }
            };

            // 鼠标移入展示名称
            map.on('pointermove', function (event) {
              if (!(map.analysisActive || map.toolboxActive || map.drawActive)) {
                var feature = map.getFeaturesAtPixel(event.pixel)[0];
                if (feature) {
                  var layer = map.getLayerByFeature(feature);
                  mapDomRef.current.style.cursor = 'pointer'; // 设置手形光标

                  if (layer && (layer.labelField || layer.tipTemplate)) {
                    var labelField = layer.labelField,
                      tipTemplate = layer.tipTemplate;
                    var label;
                    if (tipTemplate) {
                      label = tipTemplate(feature.values_);
                    } else {
                      label = feature.values_[labelField];
                    }
                    if (label) {
                      map.showPointTip(label);
                    } else {
                      map.hidePointTip();
                    }
                  } else {
                    map.hidePointTip();
                  }
                } else {
                  map.hidePointTip();
                  mapDomRef.current.style.cursor = 'default'; // 恢复默认光标
                }
              }
            });

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

            // 鼠标事件，点击属性传递

            map.on('pointermove', function (event) {
              registerMapEvent('onMouseMove', event);
              var feature = map.getFeaturesAtPixel(event.pixel)[0];
              if (feature) {
                registerEvent('onMouseMove', feature, event);

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

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

            // 点击事件，通过属性传递
            map.on('click', /*#__PURE__*/function () {
              var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(event) {
                var features, _features2, layers, _features;
                return _regeneratorRuntime().wrap(function _callee2$(_context2) {
                  while (1) switch (_context2.prev = _context2.next) {
                    case 0:
                      registerMapEvent('onClick', event);
                      map.hideTip();
                      map.hidePointTip();
                      map._clickObject = event;
                      features = map.getFeaturesAtPixel(event.pixel) || [];
                      if (map.analysisActive || map.toolboxActive) {
                        _context2.next = 17;
                        break;
                      }
                      if (!((_features2 = features) !== null && _features2 !== void 0 && (_features2 = _features2[0]) !== null && _features2 !== void 0 && _features2.isHighLight)) {
                        _context2.next = 8;
                        break;
                      }
                      return _context2.abrupt("return", registerEvent('onClick', features[0], event));
                    case 8:
                      if (features.length) {
                        _context2.next = 14;
                        break;
                      }
                      layers = map.getWmsVisibleLayers().filter(function (layer) {
                        return !layer.viewOnly;
                      });
                      _context2.next = 12;
                      return (0, _layer2.getWMSFeatureInfoByLayers)(event, map, layers);
                    case 12:
                      _features = _context2.sent;
                      if (_features !== null && _features !== void 0 && _features.length) {
                        features = [_features[0]];
                      }
                    case 14:
                      if (features.length) {
                        registerEvent('onClick', features[0], event);

                        // 过滤掉仅展示的图层和没有设置气泡的图层
                        features = features.filter(function (feature) {
                          var layer = map.getLayerByFeature(feature);
                          return layer && !layer.viewOnly && layer.template;
                        });
                        if (features.length) {
                          map.showTemplate(features);
                        } else {
                          map.hideTemplate();
                        }
                      } else {
                        map.hideTemplate();
                      }
                      _context2.next = 18;
                      break;
                    case 17:
                      if (features.length) {
                        registerEvent('onClick', features[0], event);
                      }
                    case 18:
                    case "end":
                      return _context2.stop();
                  }
                }, _callee2);
              }));
              return function (_x5) {
                return _ref3.apply(this, arguments);
              };
            }());

            // 双击事件，通过属性传递
            map.on('dblclick', function (event) {
              registerMapEvent('onDoubleClick', event);
              var feature = map.getFeaturesAtPixel(event.pixel)[0];
              registerEvent('onDoubleClick', feature, event);
            });

            // 层级事件
            map.onZoom = function (zoom) {
              onZoom && onZoom(zoom);
            };

            //监测地图zoom改变
            map.getView().on('change:resolution', function () {
              if (timeRef.current) {
                clearTimeout(timeRef.current);
              }
              timeRef.current = setTimeout(function () {
                var zoom = map.getView().getZoom();
                map.onZoom(zoom);
              }, 50);
            });
            createdMap && createdMap(map);
            setMapLoaded(true);
            window.addEventListener('resize', handleResize);
          case 61:
          case "end":
            return _context3.stop();
        }
      }, _callee3);
    }));
    return function initMap() {
      return _ref.apply(this, arguments);
    };
  }();
  var handleResize = function handleResize() {
    if (timeRef.current) {
      clearTimeout(timeRef.current);
    }
    timeRef.current = setTimeout(function () {
      mapRef.current && mapRef.current.updateSize();
    }, 50);
  };
  var onMouseMove = function onMouseMove(event) {
    if (pointTip || tip) {
      var dom = document.getElementById('TIP');
      var left = event.nativeEvent.offsetX + 15;
      var top = event.nativeEvent.offsetY + 15;

      // 适配  右边和 上面的情况
      var rightBound = mapRef.current.getViewport().clientWidth - dom.getBoundingClientRect().width - 15;
      var topBound = mapRef.current.getViewport().clientHeight - dom.getBoundingClientRect().height - 15;
      left = left > rightBound ? rightBound : left;
      top = top > topBound ? topBound : top;
      dom.style.left = "".concat(left, "px");
      dom.style.top = "".concat(top, "px");
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_antd.ConfigProvider, {
    locale: _zh_CN["default"]
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: _objectSpread({
      width: width,
      height: height,
      background: dark ? '#152937' : '#cccccc'
    }, style),
    className: (0, _classnames["default"])('ol-map-container', {
      'ol-map-container-dark': dark
    })
  }, /*#__PURE__*/_react["default"].createElement("div", {
    ref: mapDomRef,
    className: (0, _classnames["default"])('ol-map-content'),
    style: {
      width: width,
      height: height
    },
    onMouseMove: onMouseMove,
    onMouseOver: function onMouseOver() {
      return setTipVis(true);
    },
    onMouseOut: function onMouseOut() {
      return setTipVis(false);
    }
  }, (pointTip || tip) && tipVis && /*#__PURE__*/_react["default"].createElement("div", {
    id: "TIP",
    className: (0, _classnames["default"])('ol-map-custom-tip'),
    style: _objectSpread({}, positionStyle)
  }, pointTip || tip)), mapLoaded && /*#__PURE__*/_react["default"].createElement(_provider["default"], {
    value: {
      map: mapRef.current,
      showModal: props.showModal,
      onPopupClick: props.onPopupClick,
      dark: dark
    }
  }, /*#__PURE__*/_react["default"].createElement(_Popup["default"], {
    map: mapRef.current,
    ref: popupRef
  }), children)));
}
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,
  center: _propTypes["default"].array,
  zoom: _propTypes["default"].number,
  minZoom: _propTypes["default"].number,
  maxZoom: _propTypes["default"].number,
  dark: _propTypes["default"].bool,
  mapStyle: _propTypes["default"].oneOfType(['vec', 'img']),
  tk: _propTypes["default"].string.isRequired,
  style: _propTypes["default"].object,
  baseMapStyle: _propTypes["default"].object,
  encrypt: _propTypes["default"].bool
};
//# sourceMappingURL=index.js.map
