@antv/l7-component 2.9.32-alpha.4 → 2.9.32-alpha.5

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