@antv/l7-component 2.9.34 → 2.9.36-alpha.1

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 (110) hide show
  1. package/es/assets/iconfont/iconfont.js +53 -0
  2. package/es/constants/index.d.ts +60 -0
  3. package/es/constants/index.js +60 -0
  4. package/es/control/baseControl/buttonControl.d.ts +59 -0
  5. package/es/control/baseControl/buttonControl.js +191 -0
  6. package/es/control/baseControl/control.d.ts +106 -0
  7. package/es/control/baseControl/control.js +301 -0
  8. package/es/control/baseControl/index.d.ts +4 -0
  9. package/es/control/baseControl/index.js +4 -0
  10. package/es/control/baseControl/popperControl.d.ts +26 -0
  11. package/es/control/baseControl/popperControl.js +131 -0
  12. package/es/control/baseControl/selectControl.d.ts +46 -0
  13. package/es/control/baseControl/selectControl.js +232 -0
  14. package/es/control/exportImage.d.ts +18 -0
  15. package/es/control/exportImage.js +163 -0
  16. package/es/control/fullscreen.d.ts +19 -0
  17. package/es/control/fullscreen.js +151 -0
  18. package/es/control/geoLocate.d.ts +16 -0
  19. package/es/control/geoLocate.js +139 -0
  20. package/es/control/layerControl.d.ts +21 -0
  21. package/es/control/layerControl.js +172 -0
  22. package/es/control/logo.d.ts +10 -6
  23. package/es/control/logo.js +41 -11
  24. package/es/control/mapTheme.d.ts +10 -0
  25. package/es/control/mapTheme.js +135 -0
  26. package/es/control/mouseLocation.d.ts +15 -0
  27. package/es/control/mouseLocation.js +104 -0
  28. package/es/control/scale.d.ts +20 -10
  29. package/es/control/scale.js +77 -53
  30. package/es/control/zoom.d.ts +21 -10
  31. package/es/control/zoom.js +76 -49
  32. package/es/css/button.less +70 -0
  33. package/es/css/control.less +71 -0
  34. package/es/css/index.css +567 -0
  35. package/es/css/index.less +12 -0
  36. package/es/css/l7.less +60 -0
  37. package/es/css/layerPopup.less +8 -0
  38. package/es/css/logo.less +18 -0
  39. package/es/css/mouseLocation.less +9 -0
  40. package/es/css/popper.less +64 -0
  41. package/es/css/popup.less +169 -0
  42. package/es/css/scale.less +34 -0
  43. package/es/css/select.less +86 -0
  44. package/es/css/variables.less +28 -0
  45. package/es/css/zoom.less +21 -0
  46. package/es/images/logo.png +0 -0
  47. package/es/images/quanping.svg +12 -0
  48. package/es/index.d.ts +15 -8
  49. package/es/index.js +15 -9
  50. package/es/interface.d.ts +1 -20
  51. package/es/popup/layerPopup.d.ts +78 -0
  52. package/es/popup/layerPopup.js +308 -0
  53. package/es/popup/popup.d.ts +147 -0
  54. package/es/popup/popup.js +636 -0
  55. package/es/utils/icon.d.ts +1 -0
  56. package/es/utils/icon.js +9 -0
  57. package/es/utils/popper.d.ts +75 -0
  58. package/es/utils/popper.js +286 -0
  59. package/es/utils/screenfull.d.ts +2 -0
  60. package/es/utils/screenfull.js +157 -0
  61. package/lib/assets/iconfont/iconfont.js +55 -0
  62. package/lib/constants/index.js +68 -0
  63. package/lib/control/baseControl/buttonControl.js +207 -0
  64. package/lib/control/baseControl/control.js +333 -0
  65. package/lib/control/baseControl/index.js +57 -0
  66. package/lib/control/baseControl/popperControl.js +142 -0
  67. package/lib/control/baseControl/selectControl.js +253 -0
  68. package/lib/control/exportImage.js +177 -0
  69. package/lib/control/fullscreen.js +164 -0
  70. package/lib/control/geoLocate.js +154 -0
  71. package/lib/control/layerControl.js +182 -0
  72. package/lib/control/logo.js +50 -23
  73. package/lib/control/mapTheme.js +151 -0
  74. package/lib/control/mouseLocation.js +120 -0
  75. package/lib/control/scale.js +82 -62
  76. package/lib/control/zoom.js +78 -59
  77. package/lib/css/button.less +70 -0
  78. package/lib/css/control.less +71 -0
  79. package/lib/css/index.css +567 -0
  80. package/lib/css/index.less +12 -0
  81. package/lib/css/l7.less +60 -0
  82. package/lib/css/layerPopup.less +8 -0
  83. package/lib/css/logo.less +18 -0
  84. package/lib/css/mouseLocation.less +9 -0
  85. package/lib/css/popper.less +64 -0
  86. package/lib/css/popup.less +169 -0
  87. package/lib/css/scale.less +34 -0
  88. package/lib/css/select.less +86 -0
  89. package/lib/css/variables.less +28 -0
  90. package/lib/css/zoom.less +21 -0
  91. package/lib/images/logo.png +0 -0
  92. package/lib/images/quanping.svg +12 -0
  93. package/lib/index.js +165 -50
  94. package/lib/popup/layerPopup.js +317 -0
  95. package/lib/popup/popup.js +651 -0
  96. package/lib/utils/icon.js +18 -0
  97. package/lib/utils/popper.js +297 -0
  98. package/lib/utils/screenfull.js +167 -0
  99. package/package.json +8 -5
  100. package/es/control/BaseControl.d.ts +0 -27
  101. package/es/control/BaseControl.js +0 -134
  102. package/es/control/layer.d.ts +0 -38
  103. package/es/control/layer.js +0 -340
  104. package/es/css/l7.css +0 -502
  105. package/es/popup.d.ts +0 -35
  106. package/es/popup.js +0 -300
  107. package/lib/control/BaseControl.js +0 -160
  108. package/lib/control/layer.js +0 -362
  109. package/lib/css/l7.css +0 -502
  110. package/lib/popup.js +0 -317
@@ -0,0 +1,651 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
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) {
66
+ return;
67
+ }
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) {
80
+ if (e.keyCode === 27) {
81
+ _this.remove();
82
+ }
83
+ });
84
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCloseButtonClick", function (e) {
85
+ if (e.stopPropagation) {
86
+ e.stopPropagation();
87
+ }
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) {
101
+ return;
102
+ }
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
+
110
+ if (style) {
111
+ _this.container.setAttribute('style', style);
112
+ }
113
+
114
+ _this.tip = _l7Utils.DOM.create('div', 'l7-popup-tip', _this.container);
115
+
116
+ _this.container.appendChild(_this.content); // 高德地图需要阻止事件冒泡 // 测试mapbox 地图不需要添加
117
+
118
+
119
+ if (stopPropagation) {
120
+ ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick'].forEach(function (type) {
121
+ _this.container.addEventListener(type, function (e) {
122
+ e.stopPropagation();
123
+ });
124
+ });
125
+ }
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
+
144
+ if (lngLat) {
145
+ _this.lngLat = lngLat;
146
+ }
147
+
148
+ return _this;
149
+ }
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;
208
+ }
209
+ }, {
210
+ key: "getIsShow",
211
+ value: function getIsShow() {
212
+ return this.isShow;
213
+ }
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
+
252
+ if (this.container) {
253
+ _l7Utils.DOM.remove(this.container); // @ts-ignore
254
+
255
+
256
+ delete this.container;
257
+ }
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;
268
+ }
269
+
270
+ this.emit('close');
271
+ return this;
272
+ }
273
+ /**
274
+ * 获取 option 配置
275
+ */
276
+
277
+ }, {
278
+ key: "getOptions",
279
+ value: function getOptions() {
280
+ return this.popupOption;
281
+ }
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;
325
+ }
326
+ }, {
327
+ key: "open",
328
+ value: function open() {
329
+ this.addTo(this.scene);
330
+ return this;
331
+ }
332
+ }, {
333
+ key: "close",
334
+ value: function close() {
335
+ this.remove();
336
+ return this;
337
+ }
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;
352
+ }
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;
367
+ }
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));
378
+ }
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));
389
+ }
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;
406
+ }
407
+ }, {
408
+ key: "setLngLat",
409
+ value: function setLngLat(lngLat) {
410
+ return this.setLnglat(lngLat);
411
+ }
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;
448
+ }
449
+ /**
450
+ * 获取 Popup 所在经纬度
451
+ */
452
+
453
+ }, {
454
+ key: "getLnglat",
455
+ value: function getLnglat() {
456
+ return this.lngLat;
457
+ }
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;
469
+ }
470
+ }, {
471
+ key: "isOpen",
472
+ value: function isOpen() {
473
+ return !!this.mapsService;
474
+ }
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
+ };
491
+ }
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;
504
+ }
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
+ }
518
+ }
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
+ }
527
+ }
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
+ }
537
+ }
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);
583
+ }
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
+ });
613
+ }
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);
643
+ }
644
+
645
+ return frag;
646
+ }
647
+ }]);
648
+ return Popup;
649
+ }(_eventemitter.EventEmitter);
650
+
651
+ exports.default = exports.Popup = Popup;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createL7Icon = void 0;
7
+
8
+ var createL7Icon = function createL7Icon(className) {
9
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
10
+ svg.classList.add('l7-iconfont');
11
+ svg.setAttribute('aria-hidden', 'true');
12
+ var use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
13
+ use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', "#".concat(className));
14
+ svg.appendChild(use);
15
+ return svg;
16
+ };
17
+
18
+ exports.createL7Icon = createL7Icon;