@antv/l7-component 2.9.32-alpha.2 → 2.9.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/marker.js ADDED
@@ -0,0 +1,434 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
+ import _inherits from "@babel/runtime/helpers/inherits";
6
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
+
10
+ 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); }; }
11
+
12
+ 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; } }
13
+
14
+ import { TYPES } from '@antv/l7-core';
15
+ import { anchorTranslate, anchorType, applyAnchorClass, bindAll, DOM } from '@antv/l7-utils';
16
+ import { EventEmitter } from 'eventemitter3';
17
+
18
+ // marker 支持 dragger 未完成
19
+ var Marker = /*#__PURE__*/function (_EventEmitter) {
20
+ _inherits(Marker, _EventEmitter);
21
+
22
+ var _super = _createSuper(Marker);
23
+
24
+ function Marker(option) {
25
+ var _this;
26
+
27
+ _classCallCheck(this, Marker);
28
+
29
+ _this = _super.call(this);
30
+
31
+ _defineProperty(_assertThisInitialized(_this), "added", false);
32
+
33
+ _defineProperty(_assertThisInitialized(_this), "eventHandle", function (e) {
34
+ _this.emit(e.type, {
35
+ target: e,
36
+ data: _this.markerOption.extData,
37
+ lngLat: _this.lngLat
38
+ });
39
+ });
40
+
41
+ _this.markerOption = _objectSpread(_objectSpread({}, _this.getDefault()), option);
42
+ bindAll(['update', 'onMove', 'onUp', 'addDragHandler', 'onMapClick'], _assertThisInitialized(_this));
43
+
44
+ _this.init();
45
+
46
+ return _this;
47
+ }
48
+
49
+ _createClass(Marker, [{
50
+ key: "getMarkerLayerContainerSize",
51
+ value: function getMarkerLayerContainerSize() {}
52
+ }, {
53
+ key: "getDefault",
54
+ value: function getDefault() {
55
+ return {
56
+ element: undefined,
57
+ // DOM element
58
+ anchor: anchorType.BOTTOM,
59
+ offsets: [0, 0],
60
+ color: '#5B8FF9',
61
+ draggable: false
62
+ };
63
+ }
64
+ }, {
65
+ key: "addTo",
66
+ value: function addTo(scene) {
67
+ // this.remove();
68
+ this.scene = scene;
69
+ this.mapsService = scene.get(TYPES.IMapService);
70
+ this.sceneSerive = scene.get(TYPES.ISceneService);
71
+ var element = this.markerOption.element; // this.sceneSerive.getSceneContainer().appendChild(element as HTMLElement);
72
+
73
+ this.mapsService.getMarkerContainer().appendChild(element);
74
+ this.registerMarkerEvent(element);
75
+ this.mapsService.on('camerachange', this.update); // 注册高德1.x 的地图事件监听
76
+
77
+ this.mapsService.on('viewchange', this.update); // 注册高德2.0 的地图事件监听
78
+
79
+ this.update();
80
+ this.added = true;
81
+ this.emit('added');
82
+ return this;
83
+ }
84
+ }, {
85
+ key: "remove",
86
+ value: function remove() {
87
+ if (this.mapsService) {
88
+ this.mapsService.off('click', this.onMapClick);
89
+ this.mapsService.off('move', this.update);
90
+ this.mapsService.off('moveend', this.update);
91
+ this.mapsService.off('mousedown', this.addDragHandler);
92
+ this.mapsService.off('touchstart', this.addDragHandler);
93
+ this.mapsService.off('mouseup', this.onUp);
94
+ this.mapsService.off('touchend', this.onUp);
95
+ }
96
+
97
+ this.unRegisterMarkerEvent();
98
+ this.removeAllListeners();
99
+ var element = this.markerOption.element;
100
+
101
+ if (element) {
102
+ DOM.remove(element);
103
+ }
104
+
105
+ if (this.popup) {
106
+ this.popup.remove();
107
+ }
108
+
109
+ return this;
110
+ }
111
+ }, {
112
+ key: "setLnglat",
113
+ value: function setLnglat(lngLat) {
114
+ this.lngLat = lngLat;
115
+
116
+ if (Array.isArray(lngLat)) {
117
+ this.lngLat = {
118
+ lng: lngLat[0],
119
+ lat: lngLat[1]
120
+ };
121
+ }
122
+
123
+ if (this.popup) {
124
+ this.popup.setLnglat(this.lngLat);
125
+ }
126
+
127
+ this.update();
128
+ return this;
129
+ }
130
+ }, {
131
+ key: "getLnglat",
132
+ value: function getLnglat() {
133
+ return this.lngLat;
134
+ }
135
+ }, {
136
+ key: "getElement",
137
+ value: function getElement() {
138
+ return this.markerOption.element;
139
+ }
140
+ }, {
141
+ key: "setElement",
142
+ value: function setElement(el) {
143
+ var _this2 = this;
144
+
145
+ if (!this.added) {
146
+ this.once('added', function () {
147
+ _this2.setElement(el);
148
+ });
149
+ return this;
150
+ }
151
+
152
+ var element = this.markerOption.element;
153
+
154
+ if (element) {
155
+ DOM.remove(element);
156
+ }
157
+
158
+ this.markerOption.element = el;
159
+ this.init();
160
+ this.mapsService.getMarkerContainer().appendChild(el);
161
+ this.registerMarkerEvent(el);
162
+ this.update();
163
+ return this;
164
+ }
165
+ }, {
166
+ key: "openPopup",
167
+ value: function openPopup() {
168
+ var _this3 = this;
169
+
170
+ if (!this.added) {
171
+ this.once('added', function () {
172
+ _this3.openPopup();
173
+ });
174
+ return this;
175
+ }
176
+
177
+ var popup = this.popup;
178
+
179
+ if (!popup) {
180
+ return this;
181
+ }
182
+
183
+ if (!popup.isOpen()) {
184
+ popup.addTo(this.scene);
185
+ }
186
+
187
+ return this;
188
+ }
189
+ }, {
190
+ key: "closePopup",
191
+ value: function closePopup() {
192
+ var _this4 = this;
193
+
194
+ if (!this.added) {
195
+ this.once('added', function () {
196
+ _this4.closePopup();
197
+ });
198
+ }
199
+
200
+ var popup = this.popup;
201
+
202
+ if (popup) {
203
+ popup.remove();
204
+ }
205
+
206
+ return this;
207
+ }
208
+ }, {
209
+ key: "setPopup",
210
+ value: function setPopup(popup) {
211
+ this.popup = popup;
212
+
213
+ if (this.lngLat) {
214
+ this.popup.setLnglat(this.lngLat);
215
+ }
216
+
217
+ return this;
218
+ }
219
+ }, {
220
+ key: "togglePopup",
221
+ value: function togglePopup() {
222
+ var popup = this.popup;
223
+
224
+ if (!popup) {
225
+ return this;
226
+ } else if (popup.isOpen()) {
227
+ popup.remove();
228
+ } else {
229
+ popup.addTo(this.scene);
230
+ }
231
+
232
+ return this;
233
+ }
234
+ }, {
235
+ key: "getPopup",
236
+ value: function getPopup() {
237
+ return this.popup;
238
+ }
239
+ }, {
240
+ key: "getOffset",
241
+ value: function getOffset() {
242
+ return this.markerOption.offsets;
243
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
244
+
245
+ }, {
246
+ key: "setDraggable",
247
+ value: function setDraggable(draggable) {
248
+ throw new Error('Method not implemented.');
249
+ }
250
+ }, {
251
+ key: "isDraggable",
252
+ value: function isDraggable() {
253
+ return this.markerOption.draggable;
254
+ }
255
+ }, {
256
+ key: "getExtData",
257
+ value: function getExtData() {
258
+ return this.markerOption.extData;
259
+ }
260
+ }, {
261
+ key: "setExtData",
262
+ value: function setExtData(data) {
263
+ this.markerOption.extData = data;
264
+ }
265
+ }, {
266
+ key: "update",
267
+ value: function update() {
268
+ if (!this.mapsService) {
269
+ return;
270
+ }
271
+
272
+ var _this$markerOption = this.markerOption,
273
+ element = _this$markerOption.element,
274
+ anchor = _this$markerOption.anchor;
275
+ this.updatePosition();
276
+ DOM.setTransform(element, "".concat(anchorTranslate[anchor]));
277
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
278
+
279
+ }, {
280
+ key: "onMapClick",
281
+ value: function onMapClick(e) {
282
+ var element = this.markerOption.element;
283
+
284
+ if (this.popup && element) {
285
+ this.togglePopup();
286
+ }
287
+ }
288
+ }, {
289
+ key: "getCurrentContainerSize",
290
+ value: function getCurrentContainerSize() {
291
+ var container = this.mapsService.getContainer();
292
+ return {
293
+ containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
294
+ containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
295
+ bounds: this.mapsService.getBounds()
296
+ };
297
+ }
298
+ }, {
299
+ key: "updatePosition",
300
+ value: function updatePosition() {
301
+ if (!this.mapsService) {
302
+ return;
303
+ }
304
+
305
+ var _this$markerOption2 = this.markerOption,
306
+ element = _this$markerOption2.element,
307
+ offsets = _this$markerOption2.offsets;
308
+ var _this$lngLat = this.lngLat,
309
+ lng = _this$lngLat.lng,
310
+ lat = _this$lngLat.lat;
311
+ var pos = this.mapsService.lngLatToContainer([lng, lat]);
312
+
313
+ if (element) {
314
+ element.style.display = 'block';
315
+ element.style.whiteSpace = 'nowrap';
316
+
317
+ var _ref = this.getMarkerLayerContainerSize() || this.getCurrentContainerSize(),
318
+ containerHeight = _ref.containerHeight,
319
+ containerWidth = _ref.containerWidth,
320
+ bounds = _ref.bounds;
321
+
322
+ if (!bounds) return; // 当前可视区域包含跨日界线
323
+
324
+ if (Math.abs(bounds[0][0]) > 180 || Math.abs(bounds[1][0]) > 180) {
325
+ if (pos.x > containerWidth) {
326
+ // 日界线右侧点左移
327
+ var newPos = this.mapsService.lngLatToContainer([lng - 360, lat]);
328
+ pos.x = newPos.x;
329
+ }
330
+
331
+ if (pos.x < 0) {
332
+ // 日界线左侧点右移
333
+ var _newPos = this.mapsService.lngLatToContainer([lng + 360, lat]);
334
+
335
+ pos.x = _newPos.x;
336
+ }
337
+ } // 不在当前可视区域内隐藏点
338
+
339
+
340
+ if (pos.x > containerWidth || pos.x < 0 || pos.y > containerHeight || pos.y < 0) {
341
+ element.style.display = 'none';
342
+ }
343
+
344
+ element.style.left = pos.x + offsets[0] + 'px';
345
+ element.style.top = pos.y - offsets[1] + 'px';
346
+ }
347
+ }
348
+ }, {
349
+ key: "init",
350
+ value: function init() {
351
+ var _this5 = this;
352
+
353
+ var element = this.markerOption.element;
354
+ var _this$markerOption3 = this.markerOption,
355
+ color = _this$markerOption3.color,
356
+ anchor = _this$markerOption3.anchor;
357
+
358
+ if (!element) {
359
+ this.defaultMarker = true;
360
+ element = DOM.create('div');
361
+ this.markerOption.element = element;
362
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
363
+ svg.setAttributeNS(null, 'display', 'block');
364
+ svg.setAttributeNS(null, 'height', '48px');
365
+ svg.setAttributeNS(null, 'width', '48px');
366
+ svg.setAttributeNS(null, 'viewBox', '0 0 1024 1024');
367
+ var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
368
+ path.setAttributeNS(null, 'd', 'M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z');
369
+ path.setAttributeNS(null, 'fill', color);
370
+ svg.appendChild(path);
371
+ element.appendChild(svg);
372
+ }
373
+
374
+ DOM.addClass(element, 'l7-marker');
375
+ Object.keys(this.markerOption.style || {}).forEach( // @ts-ignore
376
+ function (key) {
377
+ var _this5$markerOption, _this5$markerOption2;
378
+
379
+ var value = ((_this5$markerOption = _this5.markerOption) === null || _this5$markerOption === void 0 ? void 0 : _this5$markerOption.style) && ((_this5$markerOption2 = _this5.markerOption) === null || _this5$markerOption2 === void 0 ? void 0 : _this5$markerOption2.style[key]);
380
+
381
+ if (element) {
382
+ // @ts-ignore
383
+ element.style[key] = value;
384
+ }
385
+ });
386
+ element.addEventListener('click', function (e) {
387
+ _this5.onMapClick(e);
388
+ });
389
+ element.addEventListener('click', this.eventHandle);
390
+ applyAnchorClass(element, anchor, 'marker');
391
+ }
392
+ }, {
393
+ key: "registerMarkerEvent",
394
+ value: function registerMarkerEvent(element) {
395
+ element.addEventListener('mousemove', this.eventHandle);
396
+ element.addEventListener('click', this.eventHandle);
397
+ element.addEventListener('mousedown', this.eventHandle);
398
+ element.addEventListener('mouseup', this.eventHandle);
399
+ element.addEventListener('dblclick', this.eventHandle);
400
+ element.addEventListener('contextmenu', this.eventHandle);
401
+ element.addEventListener('mouseover', this.eventHandle);
402
+ element.addEventListener('mouseout', this.eventHandle);
403
+ }
404
+ }, {
405
+ key: "unRegisterMarkerEvent",
406
+ value: function unRegisterMarkerEvent() {
407
+ var element = this.getElement();
408
+ element.removeEventListener('mousemove', this.eventHandle);
409
+ element.removeEventListener('click', this.eventHandle);
410
+ element.removeEventListener('mousedown', this.eventHandle);
411
+ element.removeEventListener('mouseup', this.eventHandle);
412
+ element.removeEventListener('dblclick', this.eventHandle);
413
+ element.removeEventListener('contextmenu', this.eventHandle);
414
+ element.removeEventListener('mouseover', this.eventHandle);
415
+ element.removeEventListener('mouseout', this.eventHandle);
416
+ }
417
+ }, {
418
+ key: "addDragHandler",
419
+ value: // eslint-disable-next-line @typescript-eslint/no-unused-vars
420
+ function addDragHandler(e) {
421
+ throw new Error('Method not implemented.');
422
+ } // eslint-disable-next-line @typescript-eslint/no-unused-vars
423
+
424
+ }, {
425
+ key: "onUp",
426
+ value: function onUp(e) {
427
+ throw new Error('Method not implemented.');
428
+ }
429
+ }]);
430
+
431
+ return Marker;
432
+ }(EventEmitter);
433
+
434
+ export { Marker as default };
package/es/popup.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { ILngLat, IPopup, IPopupOption } from '@antv/l7-core';
2
+ import { EventEmitter } from 'eventemitter3';
3
+ import { Container } from 'inversify';
4
+ /** colse event */
5
+ export default class Popup extends EventEmitter implements IPopup {
6
+ private popupOption;
7
+ private mapsService;
8
+ private sceneSerive;
9
+ private lngLat;
10
+ private content;
11
+ private closeButton;
12
+ private timeoutInstance;
13
+ private container;
14
+ private tip;
15
+ private scene;
16
+ constructor(cfg?: Partial<IPopupOption>);
17
+ addTo(scene: Container): this;
18
+ close(): void;
19
+ open(): void;
20
+ setHTML(html: string): this;
21
+ setLnglat(lngLat: ILngLat | number[]): this;
22
+ getLnglat(): ILngLat;
23
+ setText(text: string): this;
24
+ setMaxWidth(maxWidth: string): this;
25
+ setDOMContent(htmlNode: ChildNode | DocumentFragment): this;
26
+ remove(): this;
27
+ isOpen(): boolean;
28
+ private createContent;
29
+ private creatDom;
30
+ private removeDom;
31
+ private getdefault;
32
+ private onClickClose;
33
+ private update;
34
+ private updatePosition;
35
+ }