@vtx/ol-map 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_map","_interopRequireDefault","require","_tools","_featureLayer","_imageLayer","_point","_marker","_polyline","_polygon","obj","__esModule"],"sources":["index.js"],"sourcesContent":["export { default as Map } from './map';\nexport { default as Tools } from './tools';\nexport { default as FeatureLayer } from './feature-layer';\nexport { default as ImageLayer } from './image-layer';\nexport { default as Point } from './point';\nexport { default as Marker } from './marker';\nexport { default as Polyline } from './polyline';\nexport { default as Polygon } from './polygon';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,QAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA+C,SAAAD,uBAAAS,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA"}
1
+ {"version":3,"file":"index.js","names":["_map","_interopRequireDefault","require","_tools","_tileLayer","_featureLayer","_imageLayer","_point","_marker","_polyline","_polygon","obj","__esModule"],"sources":["index.js"],"sourcesContent":["export { default as Map } from './map';\nexport { default as Tools } from './tools';\nexport { default as TileLayer } from './tile-layer';\nexport { default as FeatureLayer } from './feature-layer';\nexport { default as ImageLayer } from './image-layer';\nexport { default as Point } from './point';\nexport { default as Marker } from './marker';\nexport { default as Polyline } from './polyline';\nexport { default as Polygon } from './polygon';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,aAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,QAAA,GAAAT,sBAAA,CAAAC,OAAA;AAA+C,SAAAD,uBAAAU,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA"}
package/lib/map/Popup.js CHANGED
@@ -4,12 +4,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports["default"] = _default;
7
+ exports["default"] = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _icons = require("@ant-design/icons");
10
10
  var _ol = require("ol");
11
- var _layer2 = require("ol/layer");
12
- var _layer3 = require("../_util/layer");
11
+ var _layer = require("ol/layer");
13
12
  var _classnames = _interopRequireDefault(require("classnames"));
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -20,7 +19,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
20
19
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
20
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
22
21
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
- function _default(props) {
22
+ var Popup = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
24
23
  var _useState = (0, _react.useState)(null),
25
24
  _useState2 = _slicedToArray(_useState, 2),
26
25
  content = _useState2[0],
@@ -31,10 +30,15 @@ function _default(props) {
31
30
  setTitle = _useState4[1];
32
31
  var overlayRef = (0, _react.useRef)();
33
32
  var popupRef = (0, _react.useRef)();
33
+ var featureRef = (0, _react.useRef)();
34
34
  var map = props.map;
35
+ (0, _react.useImperativeHandle)(ref, function () {
36
+ return {
37
+ showTemplate: showTemplate,
38
+ hideTemplate: hideTemplate
39
+ };
40
+ });
35
41
  (0, _react.useEffect)(function () {
36
- // 鼠标点击展示缩略信息
37
- map.on('click', onClick);
38
42
  var overlay = new _ol.Overlay({
39
43
  element: popupRef.current,
40
44
  autoPan: {
@@ -47,39 +51,17 @@ function _default(props) {
47
51
  offset: [10, -45]
48
52
  });
49
53
  overlayRef.current = overlay;
50
-
51
- // 展示看板
52
- map.showTemplate = setTemplate;
53
-
54
- // 隐藏看板
55
- map.hideTemplate = onClose;
56
54
  map.addOverlay(overlay);
57
55
  return function () {
58
- map.un('click', onClick);
59
56
  map.removeOverlay(overlay);
60
57
  };
61
58
  }, []);
62
- var onClick = function onClick(event) {
63
- console.log("event.coordinate:", event.coordinate.join(','));
64
- if (!(map.analysisActive || map.toolboxActive)) {
65
- var feature = map.getFeaturesAtPixel(event.pixel)[0];
66
- if (feature) {
67
- map.hideTip();
68
- var layer = map.getLayerByFeature(feature);
69
- setTemplate(feature, layer);
70
- } else {
71
- var layers = map.getWmsVisibleLayers();
72
- (0, _layer3.getWMSFeatureInfoByLayers)(event, map, layers).then(function (features) {
73
- if (features !== null && features !== void 0 && features.length) {
74
- var _feature = features[0];
75
- var _layer = map.getLayerByKey(_feature.key);
76
- setTemplate(_feature, _layer);
77
- }
78
- });
79
- }
59
+ var showTemplate = function showTemplate(feature) {
60
+ featureRef.current = feature;
61
+ if (!feature) {
62
+ hideTemplate();
63
+ return;
80
64
  }
81
- };
82
- var setTemplate = function setTemplate(feature) {
83
65
  var layer = map.getLayerByFeature(feature);
84
66
  if (!(layer !== null && layer !== void 0 && layer.template)) {
85
67
  return;
@@ -94,7 +76,7 @@ function _default(props) {
94
76
  if (template) {
95
77
  var _feature$getGeometry, _feature$getGeometry2;
96
78
  setContent(template(feature));
97
- overlayRef.current.values_.offset = layer instanceof _layer2.Image ? [10, -10] : [10, -45];
79
+ overlayRef.current.values_.offset = layer instanceof _layer.Image ? [10, -10] : [10, -45];
98
80
  var type = feature === null || feature === void 0 ? void 0 : (_feature$getGeometry = feature.getGeometry()) === null || _feature$getGeometry === void 0 ? void 0 : _feature$getGeometry.getType();
99
81
  var coordinate = feature === null || feature === void 0 ? void 0 : (_feature$getGeometry2 = feature.getGeometry()) === null || _feature$getGeometry2 === void 0 ? void 0 : _feature$getGeometry2.getCoordinates();
100
82
  if (['MultiLineString', 'LineString'].includes(type)) {
@@ -112,9 +94,16 @@ function _default(props) {
112
94
  }
113
95
  }
114
96
  };
115
- var onClose = function onClose() {
97
+ var hideTemplate = function hideTemplate() {
116
98
  overlayRef.current.setPosition(undefined);
117
99
  map.highlightLayer.clearFeatures();
100
+ setContent(null);
101
+ setTitle(null);
102
+ featureRef.current = null;
103
+ };
104
+ var onClose = function onClose() {
105
+ map.onCloseTemplateBefore && map.onCloseTemplateBefore(featureRef.current);
106
+ hideTemplate();
118
107
  };
119
108
  return /*#__PURE__*/_react["default"].createElement("div", {
120
109
  ref: popupRef,
@@ -131,5 +120,7 @@ function _default(props) {
131
120
  }, title), /*#__PURE__*/_react["default"].createElement("div", {
132
121
  className: (0, _classnames["default"])('content')
133
122
  }, content));
134
- }
123
+ });
124
+ var _default = Popup;
125
+ exports["default"] = _default;
135
126
  //# sourceMappingURL=Popup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Popup.js","names":["_react","_interopRequireWildcard","require","_icons","_ol","_layer2","_layer3","_classnames","_interopRequireDefault","obj","__esModule","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_slicedToArray","arr","i","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","o","minLen","_arrayLikeToArray","n","toString","slice","constructor","name","Array","from","test","len","length","arr2","_i","Symbol","iterator","_s","_e","_x","_r","_arr","_n","_d","next","done","push","value","err","isArray","_default","props","_useState","useState","_useState2","content","setContent","_useState3","_useState4","title","setTitle","overlayRef","useRef","popupRef","map","useEffect","on","onClick","overlay","Overlay","element","current","autoPan","animation","duration","stopEvent","positioning","offset","showTemplate","setTemplate","hideTemplate","onClose","addOverlay","un","removeOverlay","event","console","log","coordinate","join","analysisActive","toolboxActive","feature","getFeaturesAtPixel","pixel","hideTip","layer","getLayerByFeature","layers","getWmsVisibleLayers","getWMSFeatureInfoByLayers","then","features","getLayerByKey","template","highlightLayer","addHighlightFeature","labelField","values_","_feature$getGeometry","_feature$getGeometry2","Image","type","getGeometry","getType","getCoordinates","includes","_feature$getGeometry3","getFlatMidpoints","_feature$getGeometry4","getFlatInteriorPoint","setPosition","undefined","clearFeatures","createElement","ref","className","classnames","CloseOutlined","width","height"],"sources":["map/Popup.jsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\nimport { CloseOutlined } from '@ant-design/icons';\nimport { Overlay } from 'ol';\nimport { Image } from 'ol/layer';\nimport { getWMSFeatureInfoByLayers } from '../_util/layer';\nimport classnames from 'classnames';\n\nexport default function(props) {\n const [content, setContent] = useState(null);\n const [title, setTitle] = useState(null);\n const overlayRef = useRef();\n const popupRef = useRef();\n\n const { map } = props;\n\n useEffect(() => {\n // 鼠标点击展示缩略信息\n map.on('click', onClick);\n\n const overlay = new Overlay({\n element: popupRef.current,\n autoPan: {\n animation: {\n duration: 250,\n },\n },\n stopEvent: true,\n positioning: 'bottom-center',\n offset: [10, -45],\n });\n overlayRef.current = overlay;\n\n // 展示看板\n map.showTemplate = setTemplate;\n\n // 隐藏看板\n map.hideTemplate = onClose;\n\n map.addOverlay(overlay);\n\n return () => {\n map.un('click', onClick);\n\n map.removeOverlay(overlay);\n };\n }, []);\n\n const onClick = event => {\n console.log(\"event.coordinate:\", event.coordinate.join(','));\n if (!(map.analysisActive || map.toolboxActive)) {\n const feature = map.getFeaturesAtPixel(event.pixel)[0];\n if (feature) {\n map.hideTip();\n let layer = map.getLayerByFeature(feature);\n setTemplate(feature, layer);\n } else {\n let layers = map.getWmsVisibleLayers();\n getWMSFeatureInfoByLayers(event, map, layers).then(features => {\n if (features?.length) {\n let feature = features[0];\n let layer = map.getLayerByKey(feature.key);\n setTemplate(feature, layer);\n }\n });\n }\n }\n };\n\n const setTemplate = (feature) => {\n let layer = map.getLayerByFeature(feature);\n if (!(layer?.template)) {\n return\n }\n\n map.highlightLayer.addHighlightFeature(feature);\n\n if (layer) {\n let template = layer.template;\n let labelField = layer.labelField;\n if (labelField) {\n setTitle(feature.values_[labelField]);\n }\n if (template) {\n setContent(template(feature));\n\n overlayRef.current.values_.offset = layer instanceof Image ? [10, -10] : [10, -45];\n\n let type = feature?.getGeometry()?.getType();\n let coordinate = feature?.getGeometry()?.getCoordinates();\n if (['MultiLineString', 'LineString'].includes(type)) {\n // 线\n coordinate = feature?.getGeometry()?.getFlatMidpoints();\n overlayRef.current.values_.offset = [7, 0];\n } else if (['Polygon', 'MultiPolygon'].includes(type)) {\n // 面\n coordinate = feature?.getGeometry()?.getFlatInteriorPoint();\n overlayRef.current.values_.offset = [10, 0];\n }\n overlayRef.current.setPosition(coordinate);\n }\n }\n };\n\n const onClose = () => {\n overlayRef.current.setPosition(undefined);\n map.highlightLayer.clearFeatures();\n };\n\n return (\n <div ref={popupRef} className={classnames('ol-popup')}>\n <CloseOutlined className={classnames('close')} width={16} height={16} onClick={onClose} />\n <div className={classnames('title', {'noTitle': !title})}>{title}</div>\n <div className={classnames('content')}>{content}</div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAC,sBAAA,CAAAN,OAAA;AAAoC,SAAAM,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAAA,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAX,wBAAAQ,GAAA,EAAAG,WAAA,SAAAA,WAAA,IAAAH,GAAA,IAAAA,GAAA,CAAAC,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CAAC,eACvE9E,MAAA,YAAA+I,aAAA;IAAKE,SAAS,EAAE,IAAAC,sBAAU,EAAC,SAAS;EAAE,GAAExE,OAAa,CACpD,CAAC;AAEd"}
1
+ {"version":3,"file":"Popup.js","names":["_react","_interopRequireWildcard","require","_icons","_ol","_layer","_classnames","_interopRequireDefault","obj","__esModule","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_slicedToArray","arr","i","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","o","minLen","_arrayLikeToArray","n","toString","slice","constructor","name","Array","from","test","len","length","arr2","_i","Symbol","iterator","_s","_e","_x","_r","_arr","_n","_d","next","done","push","value","err","isArray","Popup","forwardRef","props","ref","_useState","useState","_useState2","content","setContent","_useState3","_useState4","title","setTitle","overlayRef","useRef","popupRef","featureRef","map","useImperativeHandle","showTemplate","hideTemplate","useEffect","overlay","Overlay","element","current","autoPan","animation","duration","stopEvent","positioning","offset","addOverlay","removeOverlay","feature","layer","getLayerByFeature","template","highlightLayer","addHighlightFeature","labelField","values_","_feature$getGeometry","_feature$getGeometry2","Image","type","getGeometry","getType","coordinate","getCoordinates","includes","_feature$getGeometry3","getFlatMidpoints","_feature$getGeometry4","getFlatInteriorPoint","setPosition","undefined","clearFeatures","onClose","onCloseTemplateBefore","createElement","className","classnames","CloseOutlined","width","height","onClick","_default","exports"],"sources":["map/Popup.jsx"],"sourcesContent":["import React, { useEffect, useRef, useState, useImperativeHandle, forwardRef } from 'react';\nimport { CloseOutlined } from '@ant-design/icons';\nimport { Overlay } from 'ol';\nimport { Image } from 'ol/layer';\nimport classnames from 'classnames';\n\nconst Popup = forwardRef((props, ref) => {\n const [content, setContent] = useState(null);\n const [title, setTitle] = useState(null);\n const overlayRef = useRef();\n const popupRef = useRef();\n const featureRef = useRef();\n\n const { map } = props;\n\n useImperativeHandle(ref, () => {\n return {\n showTemplate,\n hideTemplate,\n };\n });\n\n useEffect(() => {\n const overlay = new Overlay({\n element: popupRef.current,\n autoPan: {\n animation: {\n duration: 250,\n },\n },\n stopEvent: true,\n positioning: 'bottom-center',\n offset: [10, -45],\n });\n overlayRef.current = overlay;\n\n map.addOverlay(overlay);\n\n return () => {\n map.removeOverlay(overlay);\n };\n }, []);\n\n const showTemplate = (feature) => {\n featureRef.current = feature;\n\n if (!feature) {\n hideTemplate();\n return;\n }\n let layer = map.getLayerByFeature(feature);\n if (!(layer?.template)) {\n return\n }\n\n map.highlightLayer.addHighlightFeature(feature);\n\n if (layer) {\n let template = layer.template;\n let labelField = layer.labelField;\n if (labelField) {\n setTitle(feature.values_[labelField]);\n }\n if (template) {\n setContent(template(feature));\n\n overlayRef.current.values_.offset = layer instanceof Image ? [10, -10] : [10, -45];\n\n let type = feature?.getGeometry()?.getType();\n let coordinate = feature?.getGeometry()?.getCoordinates();\n if (['MultiLineString', 'LineString'].includes(type)) {\n // 线\n coordinate = feature?.getGeometry()?.getFlatMidpoints();\n overlayRef.current.values_.offset = [7, 0];\n } else if (['Polygon', 'MultiPolygon'].includes(type)) {\n // 面\n coordinate = feature?.getGeometry()?.getFlatInteriorPoint();\n overlayRef.current.values_.offset = [10, 0];\n }\n overlayRef.current.setPosition(coordinate);\n }\n }\n };\n\n const hideTemplate = () => {\n overlayRef.current.setPosition(undefined);\n map.highlightLayer.clearFeatures();\n setContent(null);\n setTitle(null);\n featureRef.current = null;\n };\n\n const onClose = () => {\n map.onCloseTemplateBefore && map.onCloseTemplateBefore(featureRef.current)\n hideTemplate();\n }\n return (\n <div ref={popupRef} className={classnames('ol-popup')}>\n <CloseOutlined className={classnames('close')} width={16} height={16} onClick={onClose} />\n <div className={classnames('title', {'noTitle': !title})}>{title}</div>\n <div className={classnames('content')}>{content}</div>\n </div>\n );\n})\n\nexport default Popup;\n"],"mappings":";;;;;;;AAAA,IAAAA,MA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AAEvD,OAAa,CACpD,CAAC;AAEd,CAAC,CAAC;AAAA,IAAA4D,QAAA,GAEanE,KAAK;AAAAoE,OAAA,cAAAD,QAAA"}
package/lib/map/index.js CHANGED
@@ -18,10 +18,15 @@ var _Popup = _interopRequireDefault(require("./Popup"));
18
18
  var _getBaseLayers = _interopRequireDefault(require("./getBaseLayers"));
19
19
  var _HighLayer = _interopRequireDefault(require("../tools/Utils/HighLayer"));
20
20
  var _events = require("../events");
21
+ var _layer2 = require("../_util/layer");
22
+ var _createFeatureCollection = require("../feature-layer/createFeatureCollection");
21
23
  require("ol/ol.css");
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
23
25
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+ 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
28
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
29
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
25
30
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
31
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
27
32
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -38,6 +43,20 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
38
43
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
39
44
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
40
45
  function Map(props) {
46
+ var _props$width = props.width,
47
+ width = _props$width === void 0 ? '100%' : _props$width,
48
+ _props$height = props.height,
49
+ height = _props$height === void 0 ? '100%' : _props$height,
50
+ children = props.children,
51
+ center = props.center,
52
+ dark = props.dark,
53
+ zoom = props.zoom,
54
+ createdMap = props.createdMap,
55
+ _props$style = props.style,
56
+ style = _props$style === void 0 ? 'vec' : _props$style,
57
+ tk = props.tk,
58
+ onCloseTemplateBefore = props.onCloseTemplateBefore,
59
+ onZoom = props.onZoom;
41
60
  var _useState = (0, _react.useState)(false),
42
61
  _useState2 = _slicedToArray(_useState, 2),
43
62
  mapLoaded = _useState2[0],
@@ -58,6 +77,8 @@ function Map(props) {
58
77
  var mapDomRef = (0, _react.useRef)(null);
59
78
  var tipRef = (0, _react.useRef)(null);
60
79
  var highLayerRef = (0, _react.useRef)();
80
+ var popupRef = (0, _react.useRef)();
81
+ var timeRef = (0, _react.useRef)(null);
61
82
  (0, _react.useEffect)(function () {
62
83
  initMap();
63
84
  return function () {
@@ -83,13 +104,6 @@ function Map(props) {
83
104
  };
84
105
  }, []);
85
106
  function initMap() {
86
- var center = props.center,
87
- dark = props.dark,
88
- zoom = props.zoom,
89
- createdMap = props.createdMap,
90
- _props$style = props.style,
91
- style = _props$style === void 0 ? 'vec' : _props$style,
92
- tk = props.tk;
93
107
  var _getDefaultMapInfo = (0, _getDefaultMapInfo2["default"])(),
94
108
  minZoom = _getDefaultMapInfo.minZoom,
95
109
  maxZoom = _getDefaultMapInfo.maxZoom,
@@ -193,30 +207,67 @@ function Map(props) {
193
207
  map.hideModal = function () {
194
208
  setModal(null);
195
209
  };
196
- map.fitView = function (e) {
210
+
211
+ // 展示看板
212
+ map.showTemplate = function (feature) {
213
+ popupRef.current.showTemplate(feature);
214
+ };
215
+
216
+ // 隐藏看板
217
+ map.hideTemplate = function () {
218
+ popupRef.current.hideTemplate();
219
+ };
220
+
221
+ // 通过返回值控制是否执行关闭
222
+ map.onCloseTemplateBefore = function (feature) {
223
+ if (onCloseTemplateBefore) {
224
+ return onCloseTemplateBefore(feature);
225
+ }
226
+ };
227
+
228
+ // 自适应
229
+ map.fitView = function (e, options) {
197
230
  if (e) {
231
+ var _e$values_;
198
232
  var extent;
199
233
  if (e instanceof _layer.Vector) {
234
+ // 针对图层处理
200
235
  extent = e.getSource().getExtent();
201
236
  } else if (e instanceof _source.Vector) {
237
+ // 针对图层源处理
202
238
  extent = e.getExtent();
203
- } else if (Array.isArray(e)) {
204
- var vectorSource = new _source.Vector({
205
- features: e
206
- });
239
+ } else if (Array.isArray(e) || e.geometryInfo) {
240
+ var _e$;
241
+ // 针对数据处理
242
+ var vectorSource = new _source.Vector();
243
+ if (e.geometryInfo || e !== null && e !== void 0 && (_e$ = e[0]) !== null && _e$ !== void 0 && _e$.geometryInfo) {
244
+ // 针对数据处理
245
+ var f = (0, _createFeatureCollection.createGeoJson)(e);
246
+ vectorSource.addFeatures(f);
247
+ } else if (e instanceof _ol.Feature || (e === null || e === void 0 ? void 0 : e[0]) instanceof _ol.Feature) {
248
+ // 针对图形处理
249
+ vectorSource.addFeatures(e);
250
+ }
207
251
  extent = vectorSource.getExtent();
208
- } else {
252
+ } else if (e !== null && e !== void 0 && (_e$values_ = e.values_) !== null && _e$values_ !== void 0 && _e$values_.geometry) {
253
+ // 针对单个图形
209
254
  extent = e.values_.geometry.getExtent();
210
255
  }
211
- map.getView().fit(extent, {
212
- padding: [100, 400, 100, 400],
213
- maxZoom: 18,
214
- duration: 500
215
- });
256
+ if (extent) {
257
+ map.getView().fit(extent, _objectSpread({
258
+ padding: [100, 400, 100, 400],
259
+ maxZoom: 18,
260
+ duration: 500
261
+ }, options));
262
+ } else {
263
+ map.getView().animate(_objectSpread(_objectSpread({}, map.defaultInfo), {}, {
264
+ duration: 500
265
+ }, options));
266
+ }
216
267
  } else {
217
268
  map.getView().animate(_objectSpread(_objectSpread({}, map.defaultInfo), {}, {
218
269
  duration: 500
219
- }));
270
+ }, options));
220
271
  }
221
272
  };
222
273
 
@@ -240,25 +291,17 @@ function Map(props) {
240
291
  if (!(map.analysisActive || map.toolboxActive)) {
241
292
  var feature = map.getFeaturesAtPixel(event.pixel)[0];
242
293
  if (feature) {
243
- var layer = map.getLayerByFeature(feature);
244
- if (layer) {
245
- var labelField = layer.labelField;
246
- if (labelField) {
247
- var label = feature.values_[labelField];
248
- if (label) {
249
- map.showTip(label);
250
- } else {
251
- map.hideTip();
252
- }
253
- } else {
254
- map.hideTip();
294
+ var _map$getLayerByFeatur;
295
+ var labelField = (_map$getLayerByFeatur = map.getLayerByFeature(feature)) === null || _map$getLayerByFeatur === void 0 ? void 0 : _map$getLayerByFeatur.labelField;
296
+ if (labelField) {
297
+ var label = feature.values_[labelField];
298
+ if (label) {
299
+ map.showTip(label);
300
+ return;
255
301
  }
256
- } else {
257
- map.hideTip();
258
302
  }
259
- } else {
260
- map.hideTip();
261
303
  }
304
+ map.hideTip();
262
305
  }
263
306
  });
264
307
 
@@ -276,13 +319,7 @@ function Map(props) {
276
319
 
277
320
  // 触发自身事件
278
321
  (_feature$event = feature[event]) === null || _feature$event === void 0 ? void 0 : _feature$event.call(feature, properties);
279
-
280
- // 触发图层事件
281
- var layer = map.getAllLayers().find(function (layer) {
282
- if (layer instanceof _layer.Vector && layer.getSource() && layer.getSource().hasFeature(feature)) {
283
- return layer;
284
- }
285
- });
322
+ var layer = map.getLayerByFeature(feature);
286
323
  if (layer !== null && layer !== void 0 && layer[event]) {
287
324
  layer[event](properties);
288
325
  }
@@ -322,11 +359,48 @@ function Map(props) {
322
359
  });
323
360
 
324
361
  // 点击事件,通过属性传递
325
- map.on('click', function (event) {
326
- registerMapEvent(event, 'onClick');
327
- var feature = map.getFeaturesAtPixel(event.pixel)[0];
328
- registerEvent(feature, 'onClick');
329
- });
362
+ map.on('click', /*#__PURE__*/function () {
363
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
364
+ var feature, layers, features;
365
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
366
+ while (1) switch (_context.prev = _context.next) {
367
+ case 0:
368
+ registerMapEvent(event, 'onClick');
369
+ map.hideTip();
370
+ feature = map.getFeaturesAtPixel(event.pixel)[0];
371
+ if (map.analysisActive || map.toolboxActive) {
372
+ _context.next = 14;
373
+ break;
374
+ }
375
+ if (feature) {
376
+ _context.next = 10;
377
+ break;
378
+ }
379
+ layers = map.getWmsVisibleLayers();
380
+ _context.next = 8;
381
+ return (0, _layer2.getWMSFeatureInfoByLayers)(event, map, layers);
382
+ case 8:
383
+ features = _context.sent;
384
+ if (features !== null && features !== void 0 && features.length) {
385
+ feature = features[0];
386
+ }
387
+ case 10:
388
+ registerEvent(feature, 'onClick');
389
+ map.showTemplate(feature);
390
+ _context.next = 15;
391
+ break;
392
+ case 14:
393
+ registerEvent(feature, 'onClick');
394
+ case 15:
395
+ case "end":
396
+ return _context.stop();
397
+ }
398
+ }, _callee);
399
+ }));
400
+ return function (_x2) {
401
+ return _ref.apply(this, arguments);
402
+ };
403
+ }());
330
404
 
331
405
  // 双击事件,通过属性传递
332
406
  map.on('dblclick', function (event) {
@@ -334,12 +408,33 @@ function Map(props) {
334
408
  var feature = map.getFeaturesAtPixel(event.pixel)[0];
335
409
  registerEvent(feature, 'onDoubleClick');
336
410
  });
411
+
412
+ // 层级事件
413
+ map.onZoom = function (zoom) {
414
+ onZoom && onZoom(zoom);
415
+ };
416
+
417
+ //监测地图zoom改变
418
+ map.getView().on('change:resolution', function () {
419
+ if (timeRef.current) {
420
+ clearTimeout(timeRef.current);
421
+ }
422
+ timeRef.current = setTimeout(function () {
423
+ var zoom = map.getView().getZoom();
424
+ map.onZoom(zoom);
425
+ }, 50);
426
+ });
337
427
  createdMap && createdMap(map);
338
428
  setMapLoaded(true);
339
429
  window.addEventListener('resize', handleResize);
340
430
  }
341
431
  var handleResize = function handleResize() {
342
- mapRef.current && mapRef.current.updateSize();
432
+ if (timeRef.current) {
433
+ clearTimeout(timeRef.current);
434
+ }
435
+ timeRef.current = setTimeout(function () {
436
+ mapRef.current && mapRef.current.updateSize();
437
+ }, 50);
343
438
  };
344
439
  var onMouseMove = function onMouseMove(event) {
345
440
  if (tip) {
@@ -347,12 +442,6 @@ function Map(props) {
347
442
  tipRef.current.style.top = "".concat(event.nativeEvent.layerY + 15, "px");
348
443
  }
349
444
  };
350
- var _props$width = props.width,
351
- width = _props$width === void 0 ? '100%' : _props$width,
352
- _props$height = props.height,
353
- height = _props$height === void 0 ? '100%' : _props$height,
354
- dark = props.dark,
355
- children = props.children;
356
445
 
357
446
  // 渲染 Children
358
447
  var renderChildren = function renderChildren() {
@@ -394,7 +483,8 @@ function Map(props) {
394
483
  ref: tipRef,
395
484
  className: (0, _classnames["default"])('custom-tip')
396
485
  }, tip)), mapLoaded && /*#__PURE__*/_react["default"].createElement(_Popup["default"], {
397
- map: mapRef.current
486
+ map: mapRef.current,
487
+ ref: popupRef
398
488
  }), mapLoaded && renderChildren());
399
489
  }
400
490
  var _default = Map;