"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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
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 n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function 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),
    _useState0 = _slicedToArray(_useState9, 2),
    pointTip = _useState0[0],
    setPointTip = _useState0[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__*/_regenerator().m(function _callee3() {
      var _baseLayerRef$current;
      var defaultMapInfo, minZoom, maxZoom, defaultZoomLevel, longitude, latitude, otherDefaultMapInfo, viewDefault, map, baseLayerParams, _baseLayerRef$current2, view, registerMapEvent, registerEvent, hoverFeature;
      return _regenerator().w(function (_context3) {
        while (1) switch (_context3.n) {
          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);
            map.baseLayerParams = baseLayerParams;
            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);
            };
            view = map.getView(); // 高亮效果
            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, options) {
              map.highlightLayer.addHighlightFeature(feature, options);
            };

            // 清除高亮
            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__*/_regenerator().m(function _callee(key, field, value, options) {
                var layer, obj;
                return _regenerator().w(function (_context) {
                  while (1) switch (_context.n) {
                    case 0:
                      layer = map.getLayerByKey(key);
                      if (layer !== null && layer !== void 0 && layer.show) {
                        obj = layer.getFeatureByFieldValue(field, value);
                        if (obj !== 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 1:
                      return _context.a(2);
                  }
                }, _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__*/_regenerator().m(function _callee2(event) {
                var features, _features2, layers, _features;
                return _regenerator().w(function (_context2) {
                  while (1) switch (_context2.n) {
                    case 0:
                      registerMapEvent('onClick', event);
                      map.hideTip();
                      map.hidePointTip();
                      map._clickObject = event;
                      features = map.getFeaturesAtPixel(event.pixel) || [];
                      if (map.analysisActive || map.toolboxActive) {
                        _context2.n = 4;
                        break;
                      }
                      if (!((_features2 = features) !== null && _features2 !== void 0 && (_features2 = _features2[0]) !== null && _features2 !== void 0 && _features2.isHighLight)) {
                        _context2.n = 1;
                        break;
                      }
                      return _context2.a(2, registerEvent('onClick', features[0], event));
                    case 1:
                      if (features.length) {
                        _context2.n = 3;
                        break;
                      }
                      layers = map.getWmsVisibleLayers().filter(function (layer) {
                        return !layer.viewOnly;
                      });
                      _context2.n = 2;
                      return (0, _layer2.getWMSFeatureInfoByLayers)(event, map, layers);
                    case 2:
                      _features = _context2.v;
                      if (_features !== null && _features !== void 0 && _features.length) {
                        features = [_features[0]];
                      }
                    case 3:
                      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.n = 5;
                      break;
                    case 4:
                      if (features.length) {
                        registerEvent('onClick', features[0], event);
                      }
                    case 5:
                      return _context2.a(2);
                  }
                }, _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 1:
            return _context3.a(2);
        }
      }, _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
