@antv/l7-component 2.21.0 → 2.21.2

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.
Files changed (83) hide show
  1. package/es/assets/iconfont/iconfont.js +6 -6
  2. package/es/constants/index.js +2 -2
  3. package/es/control/baseControl/buttonControl.js +109 -144
  4. package/es/control/baseControl/control.js +212 -258
  5. package/es/control/baseControl/popperControl.js +67 -95
  6. package/es/control/baseControl/selectControl.js +132 -178
  7. package/es/control/exportImage.js +59 -142
  8. package/es/control/fullscreen.js +69 -100
  9. package/es/control/geoLocate.js +37 -84
  10. package/es/control/layerSwitch.js +111 -154
  11. package/es/control/logo.js +43 -69
  12. package/es/control/mapTheme.js +57 -98
  13. package/es/control/mouseLocation.js +37 -69
  14. package/es/control/scale.js +107 -135
  15. package/es/control/swipe.js +297 -393
  16. package/es/control/zoom.js +80 -112
  17. package/es/css/index.css +10 -7
  18. package/es/index.js +667 -1
  19. package/es/marker-layer.js +274 -326
  20. package/es/marker.d.ts +0 -2
  21. package/es/marker.js +394 -453
  22. package/es/popup/layerPopup.js +277 -321
  23. package/es/popup/popup.js +422 -482
  24. package/es/utils/anchor.js +6 -6
  25. package/es/utils/icon.js +4 -4
  26. package/es/utils/popper.js +180 -196
  27. package/es/utils/screenfull.js +29 -51
  28. package/lib/assets/iconfont/iconfont.js +6 -6
  29. package/lib/constants/index.d.ts +60 -0
  30. package/lib/constants/index.js +2 -2
  31. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  32. package/lib/control/baseControl/buttonControl.js +110 -143
  33. package/lib/control/baseControl/control.d.ts +112 -0
  34. package/lib/control/baseControl/control.js +213 -257
  35. package/lib/control/baseControl/index.d.ts +4 -0
  36. package/lib/control/baseControl/index.js +5 -5
  37. package/lib/control/baseControl/popperControl.d.ts +28 -0
  38. package/lib/control/baseControl/popperControl.js +68 -94
  39. package/lib/control/baseControl/selectControl.d.ts +53 -0
  40. package/lib/control/baseControl/selectControl.js +133 -177
  41. package/lib/control/exportImage.d.ts +19 -0
  42. package/lib/control/exportImage.js +60 -141
  43. package/lib/control/fullscreen.d.ts +20 -0
  44. package/lib/control/fullscreen.js +70 -99
  45. package/lib/control/geoLocate.d.ts +17 -0
  46. package/lib/control/geoLocate.js +38 -83
  47. package/lib/control/layerSwitch.d.ts +27 -0
  48. package/lib/control/layerSwitch.js +112 -153
  49. package/lib/control/logo.d.ts +14 -0
  50. package/lib/control/logo.js +44 -69
  51. package/lib/control/mapTheme.d.ts +11 -0
  52. package/lib/control/mapTheme.js +58 -97
  53. package/lib/control/mouseLocation.d.ts +16 -0
  54. package/lib/control/mouseLocation.js +38 -68
  55. package/lib/control/scale.d.ts +35 -0
  56. package/lib/control/scale.js +108 -134
  57. package/lib/control/swipe.d.ts +66 -0
  58. package/lib/control/swipe.js +298 -392
  59. package/lib/control/zoom.d.ts +39 -0
  60. package/lib/control/zoom.js +81 -111
  61. package/lib/css/index.css +10 -7
  62. package/lib/index.d.ts +19 -0
  63. package/lib/index.js +683 -17
  64. package/lib/interface.d.ts +18 -0
  65. package/lib/marker-layer.d.ts +55 -0
  66. package/lib/marker-layer.js +276 -324
  67. package/lib/marker.d.ts +58 -0
  68. package/lib/marker.js +395 -452
  69. package/lib/popup/layerPopup.d.ts +99 -0
  70. package/lib/popup/layerPopup.js +278 -320
  71. package/lib/popup/popup.d.ts +142 -0
  72. package/lib/popup/popup.js +423 -481
  73. package/lib/utils/anchor.d.ts +22 -0
  74. package/lib/utils/anchor.js +6 -6
  75. package/lib/utils/icon.d.ts +1 -0
  76. package/lib/utils/icon.js +6 -5
  77. package/lib/utils/popper.d.ts +76 -0
  78. package/lib/utils/popper.js +184 -196
  79. package/lib/utils/screenfull.d.ts +2 -0
  80. package/lib/utils/screenfull.js +29 -52
  81. package/package.json +16 -20
  82. package/CHANGELOG.md +0 -325
  83. package/LICENSE.md +0 -21
package/es/popup/popup.js CHANGED
@@ -1,616 +1,556 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/esm/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
8
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
11
3
  import { DOM, anchorTranslate, anchorType, applyAnchorClass } from '@antv/l7-utils';
12
4
  import { EventEmitter } from 'eventemitter3';
13
5
  import { createL7Icon } from "../utils/icon";
14
6
  export { Popup };
15
- var Popup = /*#__PURE__*/function (_EventEmitter) {
16
- _inherits(Popup, _EventEmitter);
17
- var _super = _createSuper(Popup);
18
- function Popup(cfg) {
19
- var _this;
20
- _classCallCheck(this, Popup);
21
- _this = _super.call(this);
7
+ export default class Popup extends EventEmitter {
8
+ get lngLat() {
9
+ var _this$popupOption$lng;
10
+ return (_this$popupOption$lng = this.popupOption.lngLat) !== null && _this$popupOption$lng !== void 0 ? _this$popupOption$lng : {
11
+ lng: 0,
12
+ lat: 0
13
+ };
14
+ }
15
+ set lngLat(newLngLat) {
16
+ this.popupOption.lngLat = newLngLat;
17
+ }
18
+ constructor(cfg) {
19
+ super();
22
20
  /**
23
21
  * 配置
24
22
  * @protected
25
23
  */
24
+ _defineProperty(this, "popupOption", void 0);
25
+ _defineProperty(this, "mapsService", void 0);
26
+ _defineProperty(this, "sceneService", void 0);
27
+ _defineProperty(this, "layerService", void 0);
28
+ _defineProperty(this, "scene", void 0);
26
29
  /**
27
30
  * 关闭按钮对应的 DOM
28
31
  * @protected
29
32
  */
33
+ _defineProperty(this, "closeButton", void 0);
30
34
  /**
31
35
  * Popup 的总容器 DOM,包含 content 和 tip
32
36
  * @protected
33
37
  */
38
+ _defineProperty(this, "container", void 0);
34
39
  /**
35
40
  * popup 气泡容器
36
41
  * @protected
37
42
  */
43
+ _defineProperty(this, "content", void 0);
38
44
  /**
39
45
  * popup 气泡标题
40
46
  * @protected
41
47
  */
48
+ _defineProperty(this, "contentTitle", void 0);
42
49
  /**
43
50
  * popup 内容容器
44
51
  * @protected
45
52
  */
53
+ _defineProperty(this, "contentPanel", void 0);
46
54
  /**
47
55
  * 气泡箭头对应的 DOM
48
56
  * @protected
49
57
  */
58
+ _defineProperty(this, "tip", void 0);
50
59
  /**
51
60
  * 当前是否展示
52
61
  * @protected
53
62
  */
54
- _defineProperty(_assertThisInitialized(_this), "isShow", true);
55
- _defineProperty(_assertThisInitialized(_this), "onMouseMove", function (e) {
63
+ _defineProperty(this, "isShow", true);
64
+ _defineProperty(this, "onMouseMove", e => {
56
65
  var _container$getBoundin;
57
- var container = _this.mapsService.getMapContainer();
58
- var _ref = (_container$getBoundin = container === null || container === void 0 ? void 0 : container.getBoundingClientRect()) !== null && _container$getBoundin !== void 0 ? _container$getBoundin : {},
59
- _ref$left = _ref.left,
60
- left = _ref$left === void 0 ? 0 : _ref$left,
61
- _ref$top = _ref.top,
62
- top = _ref$top === void 0 ? 0 : _ref$top;
63
- _this.setPopupPosition(e.clientX - left, e.clientY - top);
66
+ const container = this.mapsService.getMapContainer();
67
+ const {
68
+ left = 0,
69
+ top = 0
70
+ } = (_container$getBoundin = container === null || container === void 0 ? void 0 : container.getBoundingClientRect()) !== null && _container$getBoundin !== void 0 ? _container$getBoundin : {};
71
+ this.setPopupPosition(e.clientX - left, e.clientY - top);
64
72
  });
65
73
  /**
66
74
  * 将经纬度转换成对应的像素偏移位置
67
75
  * @protected
68
76
  */
69
- _defineProperty(_assertThisInitialized(_this), "updateLngLatPosition", function () {
70
- if (!_this.mapsService || _this.popupOption.followCursor) {
77
+ _defineProperty(this, "updateLngLatPosition", () => {
78
+ if (!this.mapsService || this.popupOption.followCursor) {
71
79
  return;
72
80
  }
73
- var _this$lngLat = _this.lngLat,
74
- lng = _this$lngLat.lng,
75
- lat = _this$lngLat.lat;
76
- var _this$mapsService$lng = _this.mapsService.lngLatToContainer([lng, lat]),
77
- x = _this$mapsService$lng.x,
78
- y = _this$mapsService$lng.y;
79
- _this.setPopupPosition(x, y);
81
+ const {
82
+ lng,
83
+ lat
84
+ } = this.lngLat;
85
+ const {
86
+ x,
87
+ y
88
+ } = this.mapsService.lngLatToContainer([lng, lat]);
89
+ this.setPopupPosition(x, y);
80
90
  });
81
91
  //zoom时计算PopUp的位置并更新
82
- _defineProperty(_assertThisInitialized(_this), "updateLngLatPositionWhenZoom", function (ev) {
83
- if (!_this.mapsService || _this.popupOption.followCursor) {
92
+ _defineProperty(this, "updateLngLatPositionWhenZoom", ev => {
93
+ if (!this.mapsService || this.popupOption.followCursor) {
84
94
  return;
85
95
  }
86
- var map = ev.map;
87
- var viewHalf = map.getSize();
96
+ const map = ev.map;
97
+ const viewHalf = map.getSize();
88
98
  viewHalf.x = viewHalf.x / 2;
89
99
  viewHalf.y = viewHalf.y / 2;
90
- var center = ev.center;
91
- var zoom = ev.zoom;
92
- var projectedCenter = map.DE(_this.lngLat, zoom, center);
100
+ const center = ev.center;
101
+ const zoom = ev.zoom;
102
+ const projectedCenter = map.DE(this.lngLat, zoom, center);
93
103
  projectedCenter.x = Math.round(projectedCenter.x);
94
104
  projectedCenter.y = Math.round(projectedCenter.y);
95
- _this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
105
+ this.setPopupPosition(projectedCenter.x, projectedCenter.y, true);
96
106
  });
97
- _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
107
+ _defineProperty(this, "onKeyDown", e => {
98
108
  if (e.keyCode === 27) {
99
- _this.remove();
109
+ this.remove();
100
110
  }
101
111
  });
102
- _defineProperty(_assertThisInitialized(_this), "onCloseButtonClick", function (e) {
112
+ _defineProperty(this, "onCloseButtonClick", e => {
103
113
  if (e.stopPropagation) {
104
114
  e.stopPropagation();
105
115
  }
106
- _this.hide();
116
+ this.hide();
107
117
  });
108
118
  //更新位置 支持zoom时更新
109
- _defineProperty(_assertThisInitialized(_this), "updatePosition", function (ev) {
110
- var zoom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
111
- var hasPosition = !!_this.lngLat;
112
- var _this$popupOption = _this.popupOption,
113
- className = _this$popupOption.className,
114
- style = _this$popupOption.style,
115
- maxWidth = _this$popupOption.maxWidth,
116
- anchor = _this$popupOption.anchor,
117
- stopPropagation = _this$popupOption.stopPropagation;
118
- if (!_this.mapsService || !hasPosition || !_this.content) {
119
+ _defineProperty(this, "updatePosition", (ev, zoom = true) => {
120
+ const hasPosition = !!this.lngLat;
121
+ const {
122
+ className,
123
+ style,
124
+ maxWidth,
125
+ anchor,
126
+ stopPropagation
127
+ } = this.popupOption;
128
+ if (!this.mapsService || !hasPosition || !this.content) {
119
129
  return;
120
130
  }
121
- var popupContainer = _this.mapsService.getMarkerContainer();
131
+ const popupContainer = this.mapsService.getMarkerContainer();
122
132
  // 如果当前没有创建 Popup 容器则创建
123
- if (!_this.container && popupContainer) {
124
- _this.container = DOM.create('div', "l7-popup ".concat(className !== null && className !== void 0 ? className : '', " ").concat(!_this.isShow ? 'l7-popup-hide' : ''), popupContainer);
133
+ if (!this.container && popupContainer) {
134
+ this.container = DOM.create('div', `l7-popup ${className !== null && className !== void 0 ? className : ''} ${!this.isShow ? 'l7-popup-hide' : ''}`, popupContainer);
125
135
  if (style) {
126
- _this.container.setAttribute('style', style);
136
+ this.container.setAttribute('style', style);
127
137
  }
128
- _this.tip = DOM.create('div', 'l7-popup-tip', _this.container);
129
- _this.container.appendChild(_this.content);
138
+ this.tip = DOM.create('div', 'l7-popup-tip', this.container);
139
+ this.container.appendChild(this.content);
130
140
 
131
141
  // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
132
142
  if (stopPropagation) {
133
- ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
134
- _this.container.addEventListener(type, function (e) {
143
+ ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(type => {
144
+ this.container.addEventListener(type, e => {
135
145
  e.stopPropagation();
136
146
  });
137
147
  });
138
148
  }
139
- _this.container.style.whiteSpace = 'nowrap';
149
+ this.container.style.whiteSpace = 'nowrap';
140
150
  }
141
151
  if (zoom) {
142
- _this.updateLngLatPositionWhenZoom(ev);
152
+ this.updateLngLatPositionWhenZoom(ev);
143
153
  } else {
144
- _this.updateLngLatPosition();
154
+ this.updateLngLatPosition();
145
155
  }
146
- DOM.setTransform(_this.container, "".concat(anchorTranslate[anchor]));
147
- applyAnchorClass(_this.container, anchor, 'popup');
156
+ DOM.setTransform(this.container, `${anchorTranslate[anchor]}`);
157
+ applyAnchorClass(this.container, anchor, 'popup');
148
158
  if (maxWidth) {
149
- var _this$container$getBo = _this.container.getBoundingClientRect(),
150
- width = _this$container$getBo.width;
159
+ const {
160
+ width
161
+ } = this.container.getBoundingClientRect();
151
162
  if (width > parseFloat(maxWidth)) {
152
- _this.container.style.width = maxWidth;
163
+ this.container.style.width = maxWidth;
153
164
  }
154
165
  } else {
155
- _this.container.style.removeProperty('width');
166
+ this.container.style.removeProperty('width');
156
167
  }
157
168
  });
158
- _defineProperty(_assertThisInitialized(_this), "updateWhenZoom", function (ev) {
159
- _this.updatePosition(ev, true);
169
+ _defineProperty(this, "updateWhenZoom", ev => {
170
+ this.updatePosition(ev, true);
160
171
  });
161
- _defineProperty(_assertThisInitialized(_this), "update", function () {
162
- _this.updatePosition(null, false);
172
+ _defineProperty(this, "update", () => {
173
+ this.updatePosition(null, false);
163
174
  });
164
- _this.popupOption = _objectSpread(_objectSpread({}, _this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
165
- var lngLat = _this.popupOption.lngLat;
175
+ this.popupOption = _objectSpread(_objectSpread({}, this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
176
+ const {
177
+ lngLat
178
+ } = this.popupOption;
166
179
  if (lngLat) {
167
- _this.lngLat = lngLat;
180
+ this.lngLat = lngLat;
168
181
  }
169
- return _this;
170
182
  }
171
- _createClass(Popup, [{
172
- key: "lngLat",
173
- get: function get() {
174
- var _this$popupOption$lng;
175
- return (_this$popupOption$lng = this.popupOption.lngLat) !== null && _this$popupOption$lng !== void 0 ? _this$popupOption$lng : {
176
- lng: 0,
177
- lat: 0
178
- };
179
- },
180
- set: function set(newLngLat) {
181
- this.popupOption.lngLat = newLngLat;
183
+ getIsShow() {
184
+ return this.isShow;
185
+ }
186
+ addTo(scene) {
187
+ this.mapsService = scene.mapService;
188
+ this.sceneService = scene.sceneService;
189
+ this.layerService = scene.layerService;
190
+ //天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
191
+ // this.mapsService.on('zoomchange', this.updateWhenZoom);
192
+ this.mapsService.on('camerachange', this.update);
193
+ this.mapsService.on('viewchange', this.update);
194
+ this.scene = scene;
195
+ this.update();
196
+ // 临时关闭
197
+ this.updateCloseOnClick();
198
+ this.updateCloseOnEsc();
199
+ this.updateFollowCursor();
200
+ const {
201
+ html,
202
+ text,
203
+ title
204
+ } = this.popupOption;
205
+ if (html) {
206
+ this.setHTML(html);
207
+ } else if (text) {
208
+ this.setText(text);
182
209
  }
183
- }, {
184
- key: "getIsShow",
185
- value: function getIsShow() {
186
- return this.isShow;
210
+ if (title) {
211
+ this.setTitle(title);
187
212
  }
188
- }, {
189
- key: "addTo",
190
- value: function addTo(scene) {
191
- this.mapsService = scene.mapService;
192
- this.sceneService = scene.sceneService;
193
- this.layerService = scene.layerService;
194
- //天地图仅监听zoomchange 不注册camerachane,对于平移,在mapsService中实现
195
- // this.mapsService.on('zoomchange', this.updateWhenZoom);
196
- this.mapsService.on('camerachange', this.update);
197
- this.mapsService.on('viewchange', this.update);
198
- this.scene = scene;
199
- this.update();
200
- // 临时关闭
201
- this.updateCloseOnClick();
202
- this.updateCloseOnEsc();
203
- this.updateFollowCursor();
204
- var _this$popupOption2 = this.popupOption,
205
- html = _this$popupOption2.html,
206
- text = _this$popupOption2.text,
207
- title = _this$popupOption2.title;
208
- if (html) {
209
- this.setHTML(html);
210
- } else if (text) {
211
- this.setText(text);
212
- }
213
- if (title) {
214
- this.setTitle(title);
215
- }
216
- this.emit('open');
217
- return this;
213
+ this.emit('open');
214
+ return this;
215
+ }
216
+
217
+ // 移除popup
218
+ remove() {
219
+ if (!(this !== null && this !== void 0 && this.isOpen())) {
220
+ return;
218
221
  }
222
+ if (this.content) {
223
+ DOM.remove(this.content);
224
+ }
225
+ if (this.container) {
226
+ DOM.remove(this.container);
227
+ // @ts-ignore
228
+ delete this.container;
229
+ }
230
+ if (this.mapsService) {
231
+ // TODO: mapbox AMap 事件同步
232
+ this.mapsService.off('camerachange', this.update);
233
+ this.mapsService.off('viewchange', this.update);
234
+ //天地图的缩放事件
235
+ // this.mapsService.off('zoomchange', this.updateWhenZoom);
236
+ this.updateCloseOnClick(true);
237
+ this.updateCloseOnEsc(true);
238
+ this.updateFollowCursor(true);
239
+ // @ts-ignore
240
+ delete this.mapsService;
241
+ }
242
+ this.emit('close');
243
+ return this;
244
+ }
219
245
 
220
- // 移除popup
221
- }, {
222
- key: "remove",
223
- value: function remove() {
224
- if (!(this !== null && this !== void 0 && this.isOpen())) {
225
- return;
226
- }
227
- if (this.content) {
228
- DOM.remove(this.content);
229
- }
246
+ /**
247
+ * 获取 option 配置
248
+ */
249
+ getOptions() {
250
+ return this.popupOption;
251
+ }
252
+ setOptions(option) {
253
+ this.show();
254
+ this.popupOption = _objectSpread(_objectSpread({}, this.popupOption), option);
255
+ if (this.checkUpdateOption(option, ['html', 'text', 'title', 'closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
230
256
  if (this.container) {
231
257
  DOM.remove(this.container);
232
258
  // @ts-ignore
233
- delete this.container;
234
- }
235
- if (this.mapsService) {
236
- // TODO: mapbox AMap 事件同步
237
- this.mapsService.off('camerachange', this.update);
238
- this.mapsService.off('viewchange', this.update);
239
- //天地图的缩放事件
240
- // this.mapsService.off('zoomchange', this.updateWhenZoom);
241
- this.updateCloseOnClick(true);
242
- this.updateCloseOnEsc(true);
243
- this.updateFollowCursor(true);
244
- // @ts-ignore
245
- delete this.mapsService;
246
- }
247
- this.emit('close');
248
- return this;
249
- }
250
-
251
- /**
252
- * 获取 option 配置
253
- */
254
- }, {
255
- key: "getOptions",
256
- value: function getOptions() {
257
- return this.popupOption;
258
- }
259
- }, {
260
- key: "setOptions",
261
- value: function setOptions(option) {
262
- this.show();
263
- this.popupOption = _objectSpread(_objectSpread({}, this.popupOption), option);
264
- if (this.checkUpdateOption(option, ['html', 'text', 'title', 'closeButton', 'closeButtonOffsets', 'maxWidth', 'anchor', 'stopPropagation', 'className', 'style', 'lngLat', 'offsets'])) {
265
- if (this.container) {
266
- DOM.remove(this.container);
267
- // @ts-ignore
268
- this.container = undefined;
269
- }
270
- if (this.popupOption.html) {
271
- this.setHTML(this.popupOption.html);
272
- } else if (this.popupOption.text) {
273
- this.setText(this.popupOption.text);
274
- }
275
- if (this.popupOption.title) {
276
- this.setTitle(this.popupOption.title);
277
- }
278
- }
279
- if (this.checkUpdateOption(option, ['closeOnEsc'])) {
280
- this.updateCloseOnEsc();
281
- }
282
- if (this.checkUpdateOption(option, ['closeOnClick'])) {
283
- this.updateCloseOnClick();
259
+ this.container = undefined;
284
260
  }
285
- if (this.checkUpdateOption(option, ['followCursor'])) {
286
- this.updateFollowCursor();
261
+ if (this.popupOption.html) {
262
+ this.setHTML(this.popupOption.html);
263
+ } else if (this.popupOption.text) {
264
+ this.setText(this.popupOption.text);
287
265
  }
288
- if (this.checkUpdateOption(option, ['html']) && option.html) {
289
- this.setHTML(option.html);
290
- } else if (this.checkUpdateOption(option, ['text']) && option.text) {
291
- this.setText(option.text);
266
+ if (this.popupOption.title) {
267
+ this.setTitle(this.popupOption.title);
292
268
  }
293
- if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
294
- this.setLnglat(option.lngLat);
295
- }
296
- return this;
297
269
  }
298
- }, {
299
- key: "open",
300
- value: function open() {
301
- this.addTo(this.scene);
302
- return this;
270
+ if (this.checkUpdateOption(option, ['closeOnEsc'])) {
271
+ this.updateCloseOnEsc();
303
272
  }
304
- }, {
305
- key: "close",
306
- value: function close() {
307
- this.remove();
308
- return this;
273
+ if (this.checkUpdateOption(option, ['closeOnClick'])) {
274
+ this.updateCloseOnClick();
309
275
  }
310
- }, {
311
- key: "show",
312
- value: function show() {
313
- if (this.isShow) {
314
- return;
315
- }
316
- if (this.container) {
317
- DOM.removeClass(this.container, 'l7-popup-hide');
318
- }
319
- this.isShow = true;
320
- this.emit('show');
321
- return this;
276
+ if (this.checkUpdateOption(option, ['followCursor'])) {
277
+ this.updateFollowCursor();
322
278
  }
323
- }, {
324
- key: "hide",
325
- value: function hide() {
326
- if (!this.isShow) {
327
- return;
328
- }
329
- if (this.container) {
330
- DOM.addClass(this.container, 'l7-popup-hide');
331
- }
332
- this.isShow = false;
333
- this.emit('hide');
334
- return this;
279
+ if (this.checkUpdateOption(option, ['html']) && option.html) {
280
+ this.setHTML(option.html);
281
+ } else if (this.checkUpdateOption(option, ['text']) && option.text) {
282
+ this.setText(option.text);
335
283
  }
336
-
337
- /**
338
- * 设置 HTML 内容
339
- * @param html
340
- */
341
- }, {
342
- key: "setHTML",
343
- value: function setHTML(html) {
344
- this.popupOption.html = html;
345
- return this.setDOMContent(html);
284
+ if (this.checkUpdateOption(option, ['lngLat']) && option.lngLat) {
285
+ this.setLnglat(option.lngLat);
346
286
  }
347
-
348
- /**
349
- * 设置 Popup 展示文本
350
- * @param text
351
- */
352
- }, {
353
- key: "setText",
354
- value: function setText(text) {
355
- this.popupOption.text = text;
356
- return this.setDOMContent(window.document.createTextNode(text));
287
+ return this;
288
+ }
289
+ open() {
290
+ this.addTo(this.scene);
291
+ return this;
292
+ }
293
+ close() {
294
+ this.remove();
295
+ return this;
296
+ }
297
+ show() {
298
+ if (this.isShow) {
299
+ return;
357
300
  }
358
- }, {
359
- key: "setTitle",
360
- value: function setTitle(title) {
361
- this.show();
362
- this.popupOption.title = title;
363
- if (title) {
364
- if (!this.contentTitle) {
365
- this.contentTitle = DOM.create('div', 'l7-popup-content__title');
366
- if (this.content.firstChild) {
367
- this.content.insertBefore(this.contentTitle, this.content.firstChild);
368
- } else {
369
- this.content.append(this.contentTitle);
370
- }
371
- }
372
- DOM.clearChildren(this.contentTitle);
373
- DOM.appendElementType(this.contentTitle, title);
374
- } else if (this.contentTitle) {
375
- DOM.remove(this.contentTitle);
376
- this.contentTitle = undefined;
377
- }
301
+ if (this.container) {
302
+ DOM.removeClass(this.container, 'l7-popup-hide');
378
303
  }
379
-
380
- /**
381
- * 将地图自动平移到气泡位置
382
- */
383
- }, {
384
- key: "panToPopup",
385
- value: function panToPopup() {
386
- var _this$lngLat2 = this.lngLat,
387
- lng = _this$lngLat2.lng,
388
- lat = _this$lngLat2.lat;
389
- if (this.popupOption.autoPan) {
390
- this.mapsService.panTo([lng, lat]);
391
- }
392
- return this;
304
+ this.isShow = true;
305
+ this.emit('show');
306
+ return this;
307
+ }
308
+ hide() {
309
+ if (!this.isShow) {
310
+ return;
393
311
  }
394
- }, {
395
- key: "setLngLat",
396
- value: function setLngLat(lngLat) {
397
- return this.setLnglat(lngLat);
312
+ if (this.container) {
313
+ DOM.addClass(this.container, 'l7-popup-hide');
398
314
  }
315
+ this.isShow = false;
316
+ this.emit('hide');
317
+ return this;
318
+ }
399
319
 
400
- /**
401
- * 设置 Popup 所在经纬度
402
- * @param lngLat
403
- */
404
- }, {
405
- key: "setLnglat",
406
- value: function setLnglat(lngLat) {
407
- var _this2 = this;
408
- this.show();
409
- this.lngLat = lngLat;
410
- if (Array.isArray(lngLat)) {
411
- this.lngLat = {
412
- lng: lngLat[0],
413
- lat: lngLat[1]
414
- };
415
- }
416
- if (this.mapsService) {
417
- // 防止事件重复监听
418
- // this.mapsService.off('zoonanim', this.updateWhenZoom);
419
- this.mapsService.off('camerachange', this.update);
420
- this.mapsService.off('viewchange', this.update);
320
+ /**
321
+ * 设置 HTML 内容
322
+ * @param html
323
+ */
324
+ setHTML(html) {
325
+ this.popupOption.html = html;
326
+ return this.setDOMContent(html);
327
+ }
421
328
 
422
- // this.mapsService.on('zoonanim', this.updateWhenZoom);
423
- this.mapsService.on('camerachange', this.update);
424
- this.mapsService.on('viewchange', this.update);
425
- }
426
- this.update();
427
- if (this.popupOption.autoPan) {
428
- setTimeout(function () {
429
- _this2.panToPopup();
430
- }, 0);
329
+ /**
330
+ * 设置 Popup 展示文本
331
+ * @param text
332
+ */
333
+ setText(text) {
334
+ this.popupOption.text = text;
335
+ return this.setDOMContent(window.document.createTextNode(text));
336
+ }
337
+ setTitle(title) {
338
+ this.show();
339
+ this.popupOption.title = title;
340
+ if (title) {
341
+ if (!this.contentTitle) {
342
+ this.contentTitle = DOM.create('div', 'l7-popup-content__title');
343
+ if (this.content.firstChild) {
344
+ this.content.insertBefore(this.contentTitle, this.content.firstChild);
345
+ } else {
346
+ this.content.append(this.contentTitle);
347
+ }
431
348
  }
432
- return this;
349
+ DOM.clearChildren(this.contentTitle);
350
+ DOM.appendElementType(this.contentTitle, title);
351
+ } else if (this.contentTitle) {
352
+ DOM.remove(this.contentTitle);
353
+ this.contentTitle = undefined;
433
354
  }
355
+ }
434
356
 
435
- /**
436
- * 获取 Popup 所在经纬度
437
- */
438
- }, {
439
- key: "getLnglat",
440
- value: function getLnglat() {
441
- return this.lngLat;
357
+ /**
358
+ * 将地图自动平移到气泡位置
359
+ */
360
+ panToPopup() {
361
+ const {
362
+ lng,
363
+ lat
364
+ } = this.lngLat;
365
+ if (this.popupOption.autoPan) {
366
+ this.mapsService.panTo([lng, lat]);
442
367
  }
368
+ return this;
369
+ }
370
+ setLngLat(lngLat) {
371
+ return this.setLnglat(lngLat);
372
+ }
443
373
 
444
- /**
445
- * 设置 Popup 最大宽度
446
- * @param maxWidth
447
- */
448
- }, {
449
- key: "setMaxWidth",
450
- value: function setMaxWidth(maxWidth) {
451
- this.popupOption.maxWidth = maxWidth;
452
- this.update();
453
- return this;
454
- }
455
- }, {
456
- key: "isOpen",
457
- value: function isOpen() {
458
- return !!this.mapsService;
459
- }
460
- }, {
461
- key: "getDefault",
462
- value:
463
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
464
- function getDefault(option) {
465
- // tslint:disable-next-line:no-object-literal-type-assertion
466
- return {
467
- closeButton: true,
468
- closeOnClick: false,
469
- maxWidth: '240px',
470
- offsets: [0, 0],
471
- anchor: anchorType.BOTTOM,
472
- stopPropagation: true,
473
- autoPan: false,
474
- autoClose: true,
475
- closeOnEsc: false,
476
- followCursor: false
374
+ /**
375
+ * 设置 Popup 所在经纬度
376
+ * @param lngLat
377
+ */
378
+ setLnglat(lngLat) {
379
+ this.show();
380
+ this.lngLat = lngLat;
381
+ if (Array.isArray(lngLat)) {
382
+ this.lngLat = {
383
+ lng: lngLat[0],
384
+ lat: lngLat[1]
477
385
  };
478
386
  }
387
+ if (this.mapsService) {
388
+ // 防止事件重复监听
389
+ // this.mapsService.off('zoonanim', this.updateWhenZoom);
390
+ this.mapsService.off('camerachange', this.update);
391
+ this.mapsService.off('viewchange', this.update);
479
392
 
480
- /**
481
- * 设置 Popup 内容 HTML
482
- * @param element
483
- */
484
- }, {
485
- key: "setDOMContent",
486
- value: function setDOMContent(element) {
487
- this.show();
488
- this.createContent();
489
- DOM.appendElementType(this.contentPanel, element);
490
- this.update();
491
- return this;
393
+ // this.mapsService.on('zoonanim', this.updateWhenZoom);
394
+ this.mapsService.on('camerachange', this.update);
395
+ this.mapsService.on('viewchange', this.update);
396
+ }
397
+ this.update();
398
+ if (this.popupOption.autoPan) {
399
+ setTimeout(() => {
400
+ this.panToPopup();
401
+ }, 0);
492
402
  }
403
+ return this;
404
+ }
493
405
 
494
- /**
495
- * 绑定地图点击事件触发销毁 Popup
496
- * @protected
497
- */
498
- }, {
499
- key: "updateCloseOnClick",
500
- value: function updateCloseOnClick(onlyClear) {
501
- var _this3 = this;
502
- var mapsService = this.mapsService;
503
- if (mapsService) {
504
- mapsService === null || mapsService === void 0 || mapsService.off('click', this.onCloseButtonClick);
505
- if (this.popupOption.closeOnClick && !onlyClear) {
506
- requestAnimationFrame(function () {
507
- mapsService === null || mapsService === void 0 || mapsService.on('click', _this3.onCloseButtonClick);
508
- });
509
- }
406
+ /**
407
+ * 获取 Popup 所在经纬度
408
+ */
409
+ getLnglat() {
410
+ return this.lngLat;
411
+ }
412
+
413
+ /**
414
+ * 设置 Popup 最大宽度
415
+ * @param maxWidth
416
+ */
417
+ setMaxWidth(maxWidth) {
418
+ this.popupOption.maxWidth = maxWidth;
419
+ this.update();
420
+ return this;
421
+ }
422
+ isOpen() {
423
+ return !!this.mapsService;
424
+ }
425
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
426
+ getDefault(option) {
427
+ // tslint:disable-next-line:no-object-literal-type-assertion
428
+ return {
429
+ closeButton: true,
430
+ closeOnClick: false,
431
+ maxWidth: '240px',
432
+ offsets: [0, 0],
433
+ anchor: anchorType.BOTTOM,
434
+ stopPropagation: true,
435
+ autoPan: false,
436
+ autoClose: true,
437
+ closeOnEsc: false,
438
+ followCursor: false
439
+ };
440
+ }
441
+
442
+ /**
443
+ * 设置 Popup 内容 HTML
444
+ * @param element
445
+ */
446
+ setDOMContent(element) {
447
+ this.show();
448
+ this.createContent();
449
+ DOM.appendElementType(this.contentPanel, element);
450
+ this.update();
451
+ return this;
452
+ }
453
+
454
+ /**
455
+ * 绑定地图点击事件触发销毁 Popup
456
+ * @protected
457
+ */
458
+ updateCloseOnClick(onlyClear) {
459
+ const mapsService = this.mapsService;
460
+ if (mapsService) {
461
+ mapsService === null || mapsService === void 0 || mapsService.off('click', this.onCloseButtonClick);
462
+ if (this.popupOption.closeOnClick && !onlyClear) {
463
+ requestAnimationFrame(() => {
464
+ mapsService === null || mapsService === void 0 || mapsService.on('click', this.onCloseButtonClick);
465
+ });
510
466
  }
511
467
  }
512
- }, {
513
- key: "updateCloseOnEsc",
514
- value: function updateCloseOnEsc(onlyClear) {
515
- window.removeEventListener('keydown', this.onKeyDown);
516
- if (this.popupOption.closeOnEsc && !onlyClear) {
517
- window.addEventListener('keydown', this.onKeyDown);
518
- }
468
+ }
469
+ updateCloseOnEsc(onlyClear) {
470
+ window.removeEventListener('keydown', this.onKeyDown);
471
+ if (this.popupOption.closeOnEsc && !onlyClear) {
472
+ window.addEventListener('keydown', this.onKeyDown);
519
473
  }
520
- }, {
521
- key: "updateFollowCursor",
522
- value: function updateFollowCursor(onlyClear) {
523
- var _this$mapsService;
524
- var container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
525
- if (container) {
526
- container === null || container === void 0 || container.removeEventListener('mousemove', this.onMouseMove);
527
- if (this.popupOption.followCursor && !onlyClear) {
528
- container === null || container === void 0 || container.addEventListener('mousemove', this.onMouseMove);
529
- }
474
+ }
475
+ updateFollowCursor(onlyClear) {
476
+ var _this$mapsService;
477
+ const container = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getContainer();
478
+ if (container) {
479
+ container === null || container === void 0 || container.removeEventListener('mousemove', this.onMouseMove);
480
+ if (this.popupOption.followCursor && !onlyClear) {
481
+ container === null || container === void 0 || container.addEventListener('mousemove', this.onMouseMove);
530
482
  }
531
483
  }
532
- }, {
533
- key: "createContent",
534
- value:
535
- /**
536
- * 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
537
- * @protected
538
- */
539
- function createContent() {
540
- var _this4 = this;
541
- if (this.content) {
542
- DOM.remove(this.content);
484
+ }
485
+ /**
486
+ * 创建 Popup 内容容器的 DOM (在每次 setHTML 或 setText 时都会被调用)
487
+ * @protected
488
+ */
489
+ createContent() {
490
+ if (this.content) {
491
+ DOM.remove(this.content);
492
+ }
493
+ this.contentTitle = undefined;
494
+ this.content = DOM.create('div', 'l7-popup-content', this.container);
495
+ this.setTitle(this.popupOption.title);
496
+ if (this.popupOption.closeButton) {
497
+ const closeButton = createL7Icon('l7-icon-guanbi');
498
+ DOM.addClass(closeButton, 'l7-popup-close-button');
499
+ this.content.appendChild(closeButton);
500
+ if (this.popupOption.closeButtonOffsets) {
501
+ // 关闭按钮的偏移
502
+ closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
503
+ closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
543
504
  }
544
- this.contentTitle = undefined;
545
- this.content = DOM.create('div', 'l7-popup-content', this.container);
546
- this.setTitle(this.popupOption.title);
547
- if (this.popupOption.closeButton) {
548
- var closeButton = createL7Icon('l7-icon-guanbi');
549
- DOM.addClass(closeButton, 'l7-popup-close-button');
550
- this.content.appendChild(closeButton);
551
- if (this.popupOption.closeButtonOffsets) {
552
- // 关闭按钮的偏移
553
- closeButton.style.right = this.popupOption.closeButtonOffsets[0] + 'px';
554
- closeButton.style.top = this.popupOption.closeButtonOffsets[1] + 'px';
555
- }
556
505
 
557
- // this.closeButton.type = 'button';
558
- closeButton.setAttribute('aria-label', 'Close popup');
559
- closeButton.addEventListener('click', function () {
560
- _this4.hide();
561
- });
506
+ // this.closeButton.type = 'button';
507
+ closeButton.setAttribute('aria-label', 'Close popup');
508
+ closeButton.addEventListener('click', () => {
509
+ this.hide();
510
+ });
562
511
 
563
- // 防止点击 Popup 关闭按钮时,触发 Layer click 事件
564
- closeButton.addEventListener('pointerup', function (e) {
565
- e.stopPropagation();
566
- });
567
- closeButton.addEventListener('pointerdown', function (e) {
568
- e.stopPropagation();
569
- });
570
- this.closeButton = closeButton;
571
- } else {
572
- this.closeButton = undefined;
573
- }
574
- this.contentPanel = DOM.create('div', 'l7-popup-content__panel', this.content);
512
+ // 防止点击 Popup 关闭按钮时,触发 Layer click 事件
513
+ closeButton.addEventListener('pointerup', e => {
514
+ e.stopPropagation();
515
+ });
516
+ closeButton.addEventListener('pointerdown', e => {
517
+ e.stopPropagation();
518
+ });
519
+ this.closeButton = closeButton;
520
+ } else {
521
+ this.closeButton = undefined;
575
522
  }
576
- }, {
577
- key: "setPopupPosition",
578
- value:
579
- /**
580
- * 设置 Popup 相对于地图容器的 Position
581
- * @param {Number} left
582
- * @param {Number} top
583
- * @param {Boolean} [useTransition=false] 是否使用过度效果
584
- * @protected
585
- */
586
- function setPopupPosition(left, top) {
587
- var useTransition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
588
- if (this.container) {
589
- var offsets = this.popupOption.offsets;
590
- this.container.style.left = left + offsets[0] + 'px';
591
- this.container.style.top = top - offsets[1] + 'px';
592
- if (useTransition) {
593
- this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
594
- } else {
595
- this.container.style.transition = '';
596
- }
523
+ this.contentPanel = DOM.create('div', 'l7-popup-content__panel', this.content);
524
+ }
525
+ /**
526
+ * 设置 Popup 相对于地图容器的 Position
527
+ * @param {Number} left
528
+ * @param {Number} top
529
+ * @param {Boolean} [useTransition=false] 是否使用过度效果
530
+ * @protected
531
+ */
532
+ setPopupPosition(left, top, useTransition = false) {
533
+ if (this.container) {
534
+ const {
535
+ offsets
536
+ } = this.popupOption;
537
+ this.container.style.left = left + offsets[0] + 'px';
538
+ this.container.style.top = top - offsets[1] + 'px';
539
+ if (useTransition) {
540
+ this.container.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
541
+ } else {
542
+ this.container.style.transition = '';
597
543
  }
598
544
  }
545
+ }
599
546
 
600
- /**
601
- * 检查当前传入 option 是否包含 keys 字段
602
- * @param option
603
- * @param keys
604
- * @protected
605
- */
606
- }, {
607
- key: "checkUpdateOption",
608
- value: function checkUpdateOption(option, keys) {
609
- return keys.some(function (key) {
610
- return key in option;
611
- });
612
- }
613
- }]);
614
- return Popup;
615
- }(EventEmitter);
616
- export { Popup as default };
547
+ /**
548
+ * 检查当前传入 option 是否包含 keys 字段
549
+ * @param option
550
+ * @param keys
551
+ * @protected
552
+ */
553
+ checkUpdateOption(option, keys) {
554
+ return keys.some(key => key in option);
555
+ }
556
+ }