@antv/l7-component 2.23.1 → 2.23.3-beta.0
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/index.d.ts +1 -1
- package/es/index.js +1 -827
- package/es/interface.d.ts +11 -0
- package/es/marker-layer.d.ts +2 -11
- package/es/marker-layer.js +206 -9
- package/es/marker.d.ts +10 -3
- package/es/marker.js +44 -16
- package/es/popup/layerPopup.d.ts +2 -2
- package/es/popup/layerPopup.js +7 -5
- package/es/popup/popup.d.ts +5 -0
- package/es/popup/popup.js +19 -1
- package/es/utils/eventManager.d.ts +42 -0
- package/es/utils/eventManager.js +84 -0
- package/es/utils/popper.js +8 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -829
- package/lib/interface.d.ts +11 -0
- package/lib/marker-layer.d.ts +2 -11
- package/lib/marker-layer.js +206 -9
- package/lib/marker.d.ts +10 -3
- package/lib/marker.js +44 -16
- package/lib/popup/layerPopup.d.ts +2 -2
- package/lib/popup/layerPopup.js +7 -5
- package/lib/popup/popup.d.ts +5 -0
- package/lib/popup/popup.js +19 -1
- package/lib/utils/eventManager.d.ts +42 -0
- package/lib/utils/eventManager.js +92 -0
- package/lib/utils/popper.js +8 -0
- package/package.json +10 -8
- package/es/css/index.css +0 -781
- package/lib/css/index.css +0 -781
package/lib/interface.d.ts
CHANGED
|
@@ -15,4 +15,15 @@ export interface IMarkerStyleOption {
|
|
|
15
15
|
export interface IMarkerLayerOption {
|
|
16
16
|
cluster: boolean;
|
|
17
17
|
clusterOption: Partial<IMarkerStyleOption>;
|
|
18
|
+
/**
|
|
19
|
+
* Default marker options applied to markers added to this layer when not overridden per-marker.
|
|
20
|
+
* Example: { color: '#ff0000', style: { width: '24px', height: '24px' }, className: 'my-marker' }
|
|
21
|
+
*/
|
|
22
|
+
markerOption?: Partial<{
|
|
23
|
+
color?: string;
|
|
24
|
+
style?: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
27
|
+
className?: string;
|
|
28
|
+
}>;
|
|
18
29
|
}
|
package/lib/marker-layer.d.ts
CHANGED
|
@@ -14,17 +14,7 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
14
14
|
private inited;
|
|
15
15
|
private containerSize;
|
|
16
16
|
constructor(option?: Partial<IMarkerLayerOption>);
|
|
17
|
-
getDefault():
|
|
18
|
-
cluster: boolean;
|
|
19
|
-
clusterOption: {
|
|
20
|
-
radius: number;
|
|
21
|
-
maxZoom: number;
|
|
22
|
-
minZoom: number;
|
|
23
|
-
zoom: number;
|
|
24
|
-
style: {};
|
|
25
|
-
className: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
17
|
+
getDefault(): IMarkerLayerOption;
|
|
28
18
|
addTo(scene: L7Container): this;
|
|
29
19
|
private setContainerSize;
|
|
30
20
|
private getContainerSize;
|
|
@@ -43,6 +33,7 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
43
33
|
addMarkers(): void;
|
|
44
34
|
clear(): void;
|
|
45
35
|
destroy(): void;
|
|
36
|
+
private updateMarkers;
|
|
46
37
|
private addPoint;
|
|
47
38
|
private removePoint;
|
|
48
39
|
private initCluster;
|
package/lib/marker-layer.js
CHANGED
|
@@ -64,6 +64,9 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
64
64
|
this.mapsService.on('camerachange', this.update); // amap1.x 更新事件
|
|
65
65
|
this.mapsService.on('viewchange', this.update); // amap2.0 更新事件
|
|
66
66
|
}
|
|
67
|
+
// 统一由 layer 管理 marker 的位置更新,避免每个 marker 单独注册地图事件
|
|
68
|
+
this.mapsService.on('camerachange', this.updateMarkers.bind(this));
|
|
69
|
+
this.mapsService.on('viewchange', this.updateMarkers.bind(this));
|
|
67
70
|
this.mapsService.on('camerachange', this.setContainerSize.bind(this)); // amap1.x 更新事件
|
|
68
71
|
this.mapsService.on('viewchange', this.setContainerSize.bind(this)); // amap2.0 更新事件
|
|
69
72
|
this.addMarkers();
|
|
@@ -93,6 +96,54 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
93
96
|
addMarker(marker) {
|
|
94
97
|
const cluster = this.markerLayerOption.cluster;
|
|
95
98
|
marker.getMarkerLayerContainerSize = this.getContainerSize.bind(this);
|
|
99
|
+
|
|
100
|
+
// apply default markerOption if provided by layer
|
|
101
|
+
try {
|
|
102
|
+
const mOpt = this.markerLayerOption.markerOption;
|
|
103
|
+
if (mOpt && marker && typeof marker.getElement === 'function') {
|
|
104
|
+
const el = marker.getElement();
|
|
105
|
+
if (el) {
|
|
106
|
+
// apply className
|
|
107
|
+
if (mOpt.className) {
|
|
108
|
+
// DOM helper available
|
|
109
|
+
try {
|
|
110
|
+
_l7Utils.DOM.addClass(el, mOpt.className);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
el.className = `${el.className || ''} ${mOpt.className}`.trim();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// apply style properties
|
|
116
|
+
if (mOpt.style && typeof mOpt.style === 'object') {
|
|
117
|
+
Object.keys(mOpt.style).forEach(k => {
|
|
118
|
+
try {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
el.style[k] = mOpt.style[k];
|
|
121
|
+
} catch (e) {
|
|
122
|
+
// ignore invalid styles
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// apply color: try find svg path inside marker element and set fill
|
|
127
|
+
if (mOpt.color) {
|
|
128
|
+
try {
|
|
129
|
+
// querySelector can return SVGPathElement; coerce to any for attribute access
|
|
130
|
+
const svgPath = el.querySelector ? el.querySelector('path') : null;
|
|
131
|
+
if (svgPath && typeof svgPath.setAttribute === 'function') {
|
|
132
|
+
svgPath.setAttribute('fill', mOpt.color);
|
|
133
|
+
} else {
|
|
134
|
+
// fallback: set background color
|
|
135
|
+
el.style.background = mOpt.color;
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
// ignore
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
// be defensive — don't block marker addition on errors applying defaults
|
|
145
|
+
void err;
|
|
146
|
+
}
|
|
96
147
|
if (cluster) {
|
|
97
148
|
this.addPoint(marker, this.markers.length);
|
|
98
149
|
if (this.mapsService) {
|
|
@@ -105,11 +156,36 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
105
156
|
}
|
|
106
157
|
}
|
|
107
158
|
this.markers.push(marker);
|
|
159
|
+
|
|
160
|
+
// if layer has been added to a scene, immediately add marker's element into scene
|
|
161
|
+
// this ensures addMarker works both before and after addTo(scene)
|
|
162
|
+
try {
|
|
163
|
+
if (this.inited && this.scene && typeof marker.addTo === 'function') {
|
|
164
|
+
// When cluster mode is enabled, defer actual DOM mounting of original markers
|
|
165
|
+
// to the clustering render pass so that only cluster markers (or the chosen
|
|
166
|
+
// original marker for single-point clusters) are attached. This prevents
|
|
167
|
+
// duplicate DOM nodes / missing event handlers caused by pre-mounting originals.
|
|
168
|
+
if (!this.markerLayerOption.cluster) {
|
|
169
|
+
marker.addTo(this.scene);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (e) {
|
|
173
|
+
// defensive: do not break on addTo errors
|
|
174
|
+
void e;
|
|
175
|
+
}
|
|
108
176
|
}
|
|
109
177
|
removeMarker(marker) {
|
|
110
178
|
this.markers.indexOf(marker);
|
|
111
179
|
const markerIndex = this.markers.indexOf(marker);
|
|
112
180
|
if (markerIndex > -1) {
|
|
181
|
+
// remove visual element and unbind handlers
|
|
182
|
+
try {
|
|
183
|
+
if (typeof marker.remove === 'function') {
|
|
184
|
+
marker.remove();
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
void e;
|
|
188
|
+
}
|
|
113
189
|
this.markers.splice(markerIndex, 1);
|
|
114
190
|
if (this.markerLayerOption.cluster) {
|
|
115
191
|
this.removePoint(markerIndex);
|
|
@@ -124,11 +200,27 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
124
200
|
* 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
|
|
125
201
|
*/
|
|
126
202
|
hide() {
|
|
127
|
-
this.markers.
|
|
128
|
-
|
|
203
|
+
this.markers.forEach(m => {
|
|
204
|
+
try {
|
|
205
|
+
if (typeof m.hide === 'function') {
|
|
206
|
+
m.hide();
|
|
207
|
+
} else {
|
|
208
|
+
m.getElement().style.opacity = '0';
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
void e;
|
|
212
|
+
}
|
|
129
213
|
});
|
|
130
|
-
this.clusterMarkers.
|
|
131
|
-
|
|
214
|
+
this.clusterMarkers.forEach(m => {
|
|
215
|
+
try {
|
|
216
|
+
if (typeof m.hide === 'function') {
|
|
217
|
+
m.hide();
|
|
218
|
+
} else {
|
|
219
|
+
m.getElement().style.opacity = '0';
|
|
220
|
+
}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
void e;
|
|
223
|
+
}
|
|
132
224
|
});
|
|
133
225
|
}
|
|
134
226
|
|
|
@@ -136,11 +228,27 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
136
228
|
* 显示 marker
|
|
137
229
|
*/
|
|
138
230
|
show() {
|
|
139
|
-
this.markers.
|
|
140
|
-
|
|
231
|
+
this.markers.forEach(m => {
|
|
232
|
+
try {
|
|
233
|
+
if (typeof m.show === 'function') {
|
|
234
|
+
m.show();
|
|
235
|
+
} else {
|
|
236
|
+
m.getElement().style.opacity = '1';
|
|
237
|
+
}
|
|
238
|
+
} catch (e) {
|
|
239
|
+
void e;
|
|
240
|
+
}
|
|
141
241
|
});
|
|
142
|
-
this.clusterMarkers.
|
|
143
|
-
|
|
242
|
+
this.clusterMarkers.forEach(m => {
|
|
243
|
+
try {
|
|
244
|
+
if (typeof m.show === 'function') {
|
|
245
|
+
m.show();
|
|
246
|
+
} else {
|
|
247
|
+
m.getElement().style.opacity = '1';
|
|
248
|
+
}
|
|
249
|
+
} catch (e) {
|
|
250
|
+
void e;
|
|
251
|
+
}
|
|
144
252
|
});
|
|
145
253
|
}
|
|
146
254
|
|
|
@@ -179,6 +287,25 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
179
287
|
this.mapsService.off('viewchange', this.update);
|
|
180
288
|
this.mapsService.off('camerachange', this.setContainerSize.bind(this));
|
|
181
289
|
this.mapsService.off('viewchange', this.setContainerSize.bind(this));
|
|
290
|
+
this.mapsService.off('camerachange', this.updateMarkers.bind(this));
|
|
291
|
+
this.mapsService.off('viewchange', this.updateMarkers.bind(this));
|
|
292
|
+
}
|
|
293
|
+
updateMarkers() {
|
|
294
|
+
// update positions for both origin markers and cluster markers
|
|
295
|
+
try {
|
|
296
|
+
this.markers.forEach(m => {
|
|
297
|
+
if (m && typeof m.update === 'function') {
|
|
298
|
+
m.update();
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
this.clusterMarkers.forEach(m => {
|
|
302
|
+
if (m && typeof m.update === 'function') {
|
|
303
|
+
m.update();
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
} catch (e) {
|
|
307
|
+
void e;
|
|
308
|
+
}
|
|
182
309
|
}
|
|
183
310
|
|
|
184
311
|
// 将marker数据保存在point中
|
|
@@ -261,6 +388,27 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
261
388
|
}
|
|
262
389
|
}
|
|
263
390
|
const marker = this.clusterMarker(feature);
|
|
391
|
+
// attach layer-level re-emission so consumers can listen to cluster marker events
|
|
392
|
+
try {
|
|
393
|
+
// IMarker type may not declare EventEmitter methods; cast to any for runtime attach
|
|
394
|
+
const anyMarker = marker;
|
|
395
|
+
if (anyMarker && typeof anyMarker.on === 'function') {
|
|
396
|
+
anyMarker.on('click', ev => {
|
|
397
|
+
try {
|
|
398
|
+
this.emit('marker:click', {
|
|
399
|
+
marker: anyMarker,
|
|
400
|
+
data: anyMarker.getExtData ? anyMarker.getExtData() : null,
|
|
401
|
+
lngLat: anyMarker.getLnglat ? anyMarker.getLnglat() : null,
|
|
402
|
+
originalEvent: ev
|
|
403
|
+
});
|
|
404
|
+
} catch (e) {
|
|
405
|
+
void e;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
} catch (e) {
|
|
410
|
+
void e;
|
|
411
|
+
}
|
|
264
412
|
this.clusterMarkers.push(marker);
|
|
265
413
|
marker.addTo(this.scene);
|
|
266
414
|
});
|
|
@@ -272,16 +420,65 @@ class MarkerLayer extends _eventemitter.EventEmitter {
|
|
|
272
420
|
return this.clusterIndex.getLeaves(clusterId, limit, offset);
|
|
273
421
|
}
|
|
274
422
|
clusterMarker(feature) {
|
|
423
|
+
var _feature$properties3, _feature$properties4;
|
|
275
424
|
const clusterOption = this.markerLayerOption.clusterOption;
|
|
276
425
|
const {
|
|
277
426
|
element = this.generateElement.bind(this)
|
|
278
427
|
} = clusterOption;
|
|
428
|
+
|
|
429
|
+
// determine cluster count
|
|
430
|
+
let pointCount = (_feature$properties3 = feature.properties) === null || _feature$properties3 === void 0 ? void 0 : _feature$properties3.point_count;
|
|
431
|
+
if (pointCount === undefined && (_feature$properties4 = feature.properties) !== null && _feature$properties4 !== void 0 && _feature$properties4.cluster_id) {
|
|
432
|
+
const leaves = this.getLeaves(feature.properties.cluster_id, Infinity, 0) || [];
|
|
433
|
+
pointCount = leaves.length;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// if this cluster effectively contains only one original marker, return the original marker
|
|
437
|
+
if ((pointCount === 1 || pointCount === '1') && feature.properties) {
|
|
438
|
+
// try to get the original marker by marker_id from leaves or properties
|
|
439
|
+
let leaf = null;
|
|
440
|
+
if (feature.properties.cluster_id) {
|
|
441
|
+
const leaves = this.getLeaves(feature.properties.cluster_id, 1, 0);
|
|
442
|
+
leaf = leaves && leaves[0];
|
|
443
|
+
} else if (feature.properties.marker_id !== undefined) {
|
|
444
|
+
leaf = feature;
|
|
445
|
+
}
|
|
446
|
+
if (leaf && leaf.properties && typeof leaf.properties.marker_id === 'number') {
|
|
447
|
+
const origin = this.normalMarker(leaf);
|
|
448
|
+
if (origin) {
|
|
449
|
+
// ensure aggregated properties are available on the original marker
|
|
450
|
+
try {
|
|
451
|
+
if (feature && feature.properties && typeof origin.setExtData === 'function') {
|
|
452
|
+
origin.setExtData(feature.properties);
|
|
453
|
+
}
|
|
454
|
+
} catch (e) {
|
|
455
|
+
void e;
|
|
456
|
+
}
|
|
457
|
+
return origin;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// fallback: if no marker_id, continue to render cluster element
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// for real clusters (count > 1) or fallback, create cluster marker element
|
|
464
|
+
let el;
|
|
465
|
+
if (typeof element === 'function') {
|
|
466
|
+
el = element(feature);
|
|
467
|
+
} else {
|
|
468
|
+
// element may be a DOM node already
|
|
469
|
+
el = element;
|
|
470
|
+
}
|
|
279
471
|
const marker = new _marker.default({
|
|
280
|
-
element:
|
|
472
|
+
element: el
|
|
281
473
|
}).setLnglat({
|
|
282
474
|
lng: feature.geometry.coordinates[0],
|
|
283
475
|
lat: feature.geometry.coordinates[1]
|
|
284
476
|
});
|
|
477
|
+
// attach aggregated properties to the cluster marker so getExtData() returns useful info
|
|
478
|
+
if (feature && feature.properties) {
|
|
479
|
+
// @ts-ignore
|
|
480
|
+
marker.setExtData(feature.properties);
|
|
481
|
+
}
|
|
285
482
|
return marker;
|
|
286
483
|
}
|
|
287
484
|
normalMarker(feature) {
|
package/lib/marker.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export default class Marker extends EventEmitter {
|
|
|
9
9
|
private scene;
|
|
10
10
|
private added;
|
|
11
11
|
private preLngLat;
|
|
12
|
+
private visible;
|
|
12
13
|
getMarkerLayerContainerSize(): IMarkerContainerAndBounds | void;
|
|
13
14
|
constructor(option?: Partial<IMarkerOption>);
|
|
14
15
|
getDefault(): {
|
|
@@ -21,6 +22,14 @@ export default class Marker extends EventEmitter {
|
|
|
21
22
|
};
|
|
22
23
|
addTo(scene: L7Container): this;
|
|
23
24
|
remove(): this;
|
|
25
|
+
/**
|
|
26
|
+
* Hide the marker visually but keep it in the layer's data structures.
|
|
27
|
+
*/
|
|
28
|
+
hide(): this;
|
|
29
|
+
/**
|
|
30
|
+
* Show the marker if it was hidden.
|
|
31
|
+
*/
|
|
32
|
+
show(): this;
|
|
24
33
|
setLnglat(lngLat: ILngLat | IPoint): this;
|
|
25
34
|
getLnglat(): ILngLat;
|
|
26
35
|
getElement(): HTMLElement;
|
|
@@ -35,7 +44,7 @@ export default class Marker extends EventEmitter {
|
|
|
35
44
|
getDraggable(): boolean;
|
|
36
45
|
getExtData(): any;
|
|
37
46
|
setExtData(data: any): void;
|
|
38
|
-
|
|
47
|
+
update(): void;
|
|
39
48
|
private updatePositionWhenZoom;
|
|
40
49
|
private onMapClick;
|
|
41
50
|
private getCurrentContainerSize;
|
|
@@ -54,6 +63,4 @@ export default class Marker extends EventEmitter {
|
|
|
54
63
|
*/
|
|
55
64
|
private touchStartTime;
|
|
56
65
|
private polyfillEvent;
|
|
57
|
-
private addDragHandler;
|
|
58
|
-
private onUp;
|
|
59
66
|
}
|
package/lib/marker.js
CHANGED
|
@@ -25,6 +25,7 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
25
25
|
lng: 0,
|
|
26
26
|
lat: 0
|
|
27
27
|
});
|
|
28
|
+
(0, _defineProperty2.default)(this, "visible", true);
|
|
28
29
|
(0, _defineProperty2.default)(this, "onMarkerDragStart", e => {
|
|
29
30
|
const mapContainer = this.mapsService.getContainer();
|
|
30
31
|
if (!mapContainer) {
|
|
@@ -111,7 +112,8 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
111
112
|
} = this.markerOption;
|
|
112
113
|
this.mapsService.getMarkerContainer().appendChild(element);
|
|
113
114
|
this.registerMarkerEvent(element);
|
|
114
|
-
|
|
115
|
+
// marker 不再在自身注册地图相机事件,以避免为每个 marker 注册大量底层 map 监听器。
|
|
116
|
+
// 由 MarkerLayer 在 addTo 时统一注册并在相机变化时调用每个 marker.update()。
|
|
115
117
|
this.update();
|
|
116
118
|
this.updateDraggable();
|
|
117
119
|
this.added = true;
|
|
@@ -120,10 +122,7 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
120
122
|
}
|
|
121
123
|
remove() {
|
|
122
124
|
if (this.mapsService) {
|
|
123
|
-
|
|
124
|
-
this.mapsService.off('move', this.update);
|
|
125
|
-
this.mapsService.off('moveend', this.update);
|
|
126
|
-
this.mapsService.off('camerachange', this.update);
|
|
125
|
+
// 不再负责移除地图级别的 update 监听(由 MarkerLayer 管理),移除地图事件请统一通过 layer
|
|
127
126
|
}
|
|
128
127
|
this.unRegisterMarkerEvent();
|
|
129
128
|
this.removeAllListeners();
|
|
@@ -138,6 +137,36 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
138
137
|
}
|
|
139
138
|
return this;
|
|
140
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Hide the marker visually but keep it in the layer's data structures.
|
|
143
|
+
*/
|
|
144
|
+
hide() {
|
|
145
|
+
const {
|
|
146
|
+
element
|
|
147
|
+
} = this.markerOption;
|
|
148
|
+
if (element) {
|
|
149
|
+
element.style.display = 'none';
|
|
150
|
+
}
|
|
151
|
+
this.visible = false;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Show the marker if it was hidden.
|
|
157
|
+
*/
|
|
158
|
+
show() {
|
|
159
|
+
const {
|
|
160
|
+
element
|
|
161
|
+
} = this.markerOption;
|
|
162
|
+
if (element) {
|
|
163
|
+
element.style.display = 'block';
|
|
164
|
+
}
|
|
165
|
+
this.visible = true;
|
|
166
|
+
// re-position after showing
|
|
167
|
+
this.update();
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
141
170
|
setLnglat(lngLat) {
|
|
142
171
|
this.lngLat = lngLat;
|
|
143
172
|
if (Array.isArray(lngLat)) {
|
|
@@ -268,6 +297,9 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
268
297
|
lng,
|
|
269
298
|
lat
|
|
270
299
|
} = this.lngLat;
|
|
300
|
+
if (!this.visible) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
271
303
|
if (element) {
|
|
272
304
|
element.style.display = 'block';
|
|
273
305
|
element.style.whiteSpace = 'nowrap';
|
|
@@ -306,7 +338,6 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
306
338
|
element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
307
339
|
}
|
|
308
340
|
}
|
|
309
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
310
341
|
onMapClick(e) {
|
|
311
342
|
const {
|
|
312
343
|
element
|
|
@@ -347,6 +378,13 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
347
378
|
lat
|
|
348
379
|
} = this.lngLat;
|
|
349
380
|
const pos = this.mapsService.lngLatToContainer([lng, lat]);
|
|
381
|
+
if (!this.visible) {
|
|
382
|
+
// remain hidden until show() is called
|
|
383
|
+
if (element) {
|
|
384
|
+
element.style.display = 'none';
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
350
388
|
if (element) {
|
|
351
389
|
element.style.display = 'block';
|
|
352
390
|
element.style.whiteSpace = 'nowrap';
|
|
@@ -460,15 +498,5 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
460
498
|
}
|
|
461
499
|
}
|
|
462
500
|
}
|
|
463
|
-
|
|
464
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
465
|
-
addDragHandler(e) {
|
|
466
|
-
return null;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
470
|
-
onUp(e) {
|
|
471
|
-
throw new Error('Method not implemented.');
|
|
472
|
-
}
|
|
473
501
|
}
|
|
474
502
|
exports.default = Marker;
|
|
@@ -17,7 +17,7 @@ export type LayerPopupConfigItem = {
|
|
|
17
17
|
export interface ILayerPopupOption extends IPopupOption {
|
|
18
18
|
config?: LayerPopupConfigItem[];
|
|
19
19
|
items?: LayerPopupConfigItem[];
|
|
20
|
-
trigger
|
|
20
|
+
trigger?: 'hover' | 'click' | 'touchend' | 'touchstart';
|
|
21
21
|
}
|
|
22
22
|
type LayerMapInfo = {
|
|
23
23
|
onMouseMove?: (layer: ILayer, e: any) => void;
|
|
@@ -50,7 +50,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
|
|
|
50
50
|
* 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
|
|
51
51
|
* @protected
|
|
52
52
|
*/
|
|
53
|
-
protected getActualTriggerEvent():
|
|
53
|
+
protected getActualTriggerEvent(): 'hover' | 'click' | 'touchend' | 'touchstart';
|
|
54
54
|
addTo(scene: L7Container): this;
|
|
55
55
|
remove(): this;
|
|
56
56
|
setOptions(option: Partial<ILayerPopupOption>): this;
|
package/lib/popup/layerPopup.js
CHANGED
|
@@ -85,9 +85,8 @@ class LayerPopup extends _popup.default {
|
|
|
85
85
|
* @protected
|
|
86
86
|
*/
|
|
87
87
|
getActualTriggerEvent() {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
} = this.popupOption;
|
|
88
|
+
var _this$popupOption$tri;
|
|
89
|
+
const trigger = (_this$popupOption$tri = this.popupOption.trigger) !== null && _this$popupOption$tri !== void 0 ? _this$popupOption$tri : 'hover';
|
|
91
90
|
if (trigger === 'click') {
|
|
92
91
|
return (0, _l7Utils.isPC)() ? 'click' : 'touchend';
|
|
93
92
|
}
|
|
@@ -120,9 +119,12 @@ class LayerPopup extends _popup.default {
|
|
|
120
119
|
return this;
|
|
121
120
|
}
|
|
122
121
|
getDefault(option) {
|
|
123
|
-
|
|
122
|
+
var _option$trigger;
|
|
123
|
+
// trigger 默认值为 'hover'
|
|
124
|
+
const trigger = (_option$trigger = option.trigger) !== null && _option$trigger !== void 0 ? _option$trigger : 'hover';
|
|
125
|
+
const isHoverTrigger = trigger === 'hover';
|
|
124
126
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
|
|
125
|
-
trigger
|
|
127
|
+
trigger,
|
|
126
128
|
followCursor: isHoverTrigger,
|
|
127
129
|
lngLat: {
|
|
128
130
|
lng: 0,
|
package/lib/popup/popup.d.ts
CHANGED
|
@@ -48,6 +48,11 @@ export default class Popup<O extends IPopupOption = IPopupOption> extends EventE
|
|
|
48
48
|
* @protected
|
|
49
49
|
*/
|
|
50
50
|
protected isShow: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* RAF 节流 ID
|
|
53
|
+
* @protected
|
|
54
|
+
*/
|
|
55
|
+
protected rafId: number | null;
|
|
51
56
|
protected get lngLat(): ILngLat;
|
|
52
57
|
protected set lngLat(newLngLat: ILngLat);
|
|
53
58
|
constructor(cfg?: Partial<O>);
|
package/lib/popup/popup.js
CHANGED
|
@@ -67,6 +67,11 @@ class Popup extends _eventemitter.EventEmitter {
|
|
|
67
67
|
* @protected
|
|
68
68
|
*/
|
|
69
69
|
(0, _defineProperty2.default)(this, "isShow", true);
|
|
70
|
+
/**
|
|
71
|
+
* RAF 节流 ID
|
|
72
|
+
* @protected
|
|
73
|
+
*/
|
|
74
|
+
(0, _defineProperty2.default)(this, "rafId", null);
|
|
70
75
|
(0, _defineProperty2.default)(this, "onMouseMove", e => {
|
|
71
76
|
var _container$getBoundin;
|
|
72
77
|
const container = this.mapsService.getMapContainer();
|
|
@@ -176,7 +181,14 @@ class Popup extends _eventemitter.EventEmitter {
|
|
|
176
181
|
this.updatePosition(ev, true);
|
|
177
182
|
});
|
|
178
183
|
(0, _defineProperty2.default)(this, "update", () => {
|
|
179
|
-
|
|
184
|
+
// 使用 RAF 节流,避免高频事件导致的性能问题
|
|
185
|
+
if (this.rafId !== null) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.rafId = requestAnimationFrame(() => {
|
|
189
|
+
this.rafId = null;
|
|
190
|
+
this.updatePosition(null, false);
|
|
191
|
+
});
|
|
180
192
|
});
|
|
181
193
|
this.popupOption = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
|
|
182
194
|
const {
|
|
@@ -225,6 +237,12 @@ class Popup extends _eventemitter.EventEmitter {
|
|
|
225
237
|
if (!(this !== null && this !== void 0 && this.isOpen())) {
|
|
226
238
|
return;
|
|
227
239
|
}
|
|
240
|
+
|
|
241
|
+
// 取消未执行的 RAF
|
|
242
|
+
if (this.rafId !== null) {
|
|
243
|
+
cancelAnimationFrame(this.rafId);
|
|
244
|
+
this.rafId = null;
|
|
245
|
+
}
|
|
228
246
|
if (this.content) {
|
|
229
247
|
_l7Utils.DOM.remove(this.content);
|
|
230
248
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { IMapService } from '@antv/l7-core';
|
|
2
|
+
type EventHandler = (...args: any[]) => void;
|
|
3
|
+
/**
|
|
4
|
+
* 事件管理器,用于统一管理事件绑定和解绑
|
|
5
|
+
* 解决组件销毁时事件未正确清理导致的内存泄漏问题
|
|
6
|
+
*/
|
|
7
|
+
export declare class EventManager {
|
|
8
|
+
private bindings;
|
|
9
|
+
/**
|
|
10
|
+
* 绑定事件
|
|
11
|
+
* @param target 事件目标对象
|
|
12
|
+
* @param event 事件名称
|
|
13
|
+
* @param handler 事件处理函数
|
|
14
|
+
*/
|
|
15
|
+
on(target: IMapService, event: string, handler: EventHandler): this;
|
|
16
|
+
on(target: HTMLElement, event: string, handler: EventHandler): this;
|
|
17
|
+
on(target: Window, event: string, handler: EventHandler): this;
|
|
18
|
+
on(target: Document, event: string, handler: EventHandler): this;
|
|
19
|
+
/**
|
|
20
|
+
* 解绑指定事件
|
|
21
|
+
* @param target 事件目标对象
|
|
22
|
+
* @param event 事件名称
|
|
23
|
+
* @param handler 事件处理函数
|
|
24
|
+
*/
|
|
25
|
+
off(target: IMapService, event: string, handler: EventHandler): this;
|
|
26
|
+
off(target: HTMLElement, event: string, handler: EventHandler): this;
|
|
27
|
+
off(target: Window, event: string, handler: EventHandler): this;
|
|
28
|
+
off(target: Document, event: string, handler: EventHandler): this;
|
|
29
|
+
/**
|
|
30
|
+
* 清除所有绑定的事件
|
|
31
|
+
*/
|
|
32
|
+
clear(): void;
|
|
33
|
+
/**
|
|
34
|
+
* 获取当前绑定的事件数量
|
|
35
|
+
*/
|
|
36
|
+
size(): number;
|
|
37
|
+
/**
|
|
38
|
+
* 判断目标是否为 MapService
|
|
39
|
+
*/
|
|
40
|
+
private isMapService;
|
|
41
|
+
}
|
|
42
|
+
export default EventManager;
|