@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/es/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/es/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/es/marker-layer.js
CHANGED
|
@@ -56,6 +56,9 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
56
56
|
this.mapsService.on('camerachange', this.update); // amap1.x 更新事件
|
|
57
57
|
this.mapsService.on('viewchange', this.update); // amap2.0 更新事件
|
|
58
58
|
}
|
|
59
|
+
// 统一由 layer 管理 marker 的位置更新,避免每个 marker 单独注册地图事件
|
|
60
|
+
this.mapsService.on('camerachange', this.updateMarkers.bind(this));
|
|
61
|
+
this.mapsService.on('viewchange', this.updateMarkers.bind(this));
|
|
59
62
|
this.mapsService.on('camerachange', this.setContainerSize.bind(this)); // amap1.x 更新事件
|
|
60
63
|
this.mapsService.on('viewchange', this.setContainerSize.bind(this)); // amap2.0 更新事件
|
|
61
64
|
this.addMarkers();
|
|
@@ -85,6 +88,54 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
85
88
|
addMarker(marker) {
|
|
86
89
|
const cluster = this.markerLayerOption.cluster;
|
|
87
90
|
marker.getMarkerLayerContainerSize = this.getContainerSize.bind(this);
|
|
91
|
+
|
|
92
|
+
// apply default markerOption if provided by layer
|
|
93
|
+
try {
|
|
94
|
+
const mOpt = this.markerLayerOption.markerOption;
|
|
95
|
+
if (mOpt && marker && typeof marker.getElement === 'function') {
|
|
96
|
+
const el = marker.getElement();
|
|
97
|
+
if (el) {
|
|
98
|
+
// apply className
|
|
99
|
+
if (mOpt.className) {
|
|
100
|
+
// DOM helper available
|
|
101
|
+
try {
|
|
102
|
+
DOM.addClass(el, mOpt.className);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
el.className = `${el.className || ''} ${mOpt.className}`.trim();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// apply style properties
|
|
108
|
+
if (mOpt.style && typeof mOpt.style === 'object') {
|
|
109
|
+
Object.keys(mOpt.style).forEach(k => {
|
|
110
|
+
try {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
el.style[k] = mOpt.style[k];
|
|
113
|
+
} catch (e) {
|
|
114
|
+
// ignore invalid styles
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// apply color: try find svg path inside marker element and set fill
|
|
119
|
+
if (mOpt.color) {
|
|
120
|
+
try {
|
|
121
|
+
// querySelector can return SVGPathElement; coerce to any for attribute access
|
|
122
|
+
const svgPath = el.querySelector ? el.querySelector('path') : null;
|
|
123
|
+
if (svgPath && typeof svgPath.setAttribute === 'function') {
|
|
124
|
+
svgPath.setAttribute('fill', mOpt.color);
|
|
125
|
+
} else {
|
|
126
|
+
// fallback: set background color
|
|
127
|
+
el.style.background = mOpt.color;
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
// ignore
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
// be defensive — don't block marker addition on errors applying defaults
|
|
137
|
+
void err;
|
|
138
|
+
}
|
|
88
139
|
if (cluster) {
|
|
89
140
|
this.addPoint(marker, this.markers.length);
|
|
90
141
|
if (this.mapsService) {
|
|
@@ -97,11 +148,36 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
97
148
|
}
|
|
98
149
|
}
|
|
99
150
|
this.markers.push(marker);
|
|
151
|
+
|
|
152
|
+
// if layer has been added to a scene, immediately add marker's element into scene
|
|
153
|
+
// this ensures addMarker works both before and after addTo(scene)
|
|
154
|
+
try {
|
|
155
|
+
if (this.inited && this.scene && typeof marker.addTo === 'function') {
|
|
156
|
+
// When cluster mode is enabled, defer actual DOM mounting of original markers
|
|
157
|
+
// to the clustering render pass so that only cluster markers (or the chosen
|
|
158
|
+
// original marker for single-point clusters) are attached. This prevents
|
|
159
|
+
// duplicate DOM nodes / missing event handlers caused by pre-mounting originals.
|
|
160
|
+
if (!this.markerLayerOption.cluster) {
|
|
161
|
+
marker.addTo(this.scene);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
// defensive: do not break on addTo errors
|
|
166
|
+
void e;
|
|
167
|
+
}
|
|
100
168
|
}
|
|
101
169
|
removeMarker(marker) {
|
|
102
170
|
this.markers.indexOf(marker);
|
|
103
171
|
const markerIndex = this.markers.indexOf(marker);
|
|
104
172
|
if (markerIndex > -1) {
|
|
173
|
+
// remove visual element and unbind handlers
|
|
174
|
+
try {
|
|
175
|
+
if (typeof marker.remove === 'function') {
|
|
176
|
+
marker.remove();
|
|
177
|
+
}
|
|
178
|
+
} catch (e) {
|
|
179
|
+
void e;
|
|
180
|
+
}
|
|
105
181
|
this.markers.splice(markerIndex, 1);
|
|
106
182
|
if (this.markerLayerOption.cluster) {
|
|
107
183
|
this.removePoint(markerIndex);
|
|
@@ -116,11 +192,27 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
116
192
|
* 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
|
|
117
193
|
*/
|
|
118
194
|
hide() {
|
|
119
|
-
this.markers.
|
|
120
|
-
|
|
195
|
+
this.markers.forEach(m => {
|
|
196
|
+
try {
|
|
197
|
+
if (typeof m.hide === 'function') {
|
|
198
|
+
m.hide();
|
|
199
|
+
} else {
|
|
200
|
+
m.getElement().style.opacity = '0';
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
void e;
|
|
204
|
+
}
|
|
121
205
|
});
|
|
122
|
-
this.clusterMarkers.
|
|
123
|
-
|
|
206
|
+
this.clusterMarkers.forEach(m => {
|
|
207
|
+
try {
|
|
208
|
+
if (typeof m.hide === 'function') {
|
|
209
|
+
m.hide();
|
|
210
|
+
} else {
|
|
211
|
+
m.getElement().style.opacity = '0';
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
void e;
|
|
215
|
+
}
|
|
124
216
|
});
|
|
125
217
|
}
|
|
126
218
|
|
|
@@ -128,11 +220,27 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
128
220
|
* 显示 marker
|
|
129
221
|
*/
|
|
130
222
|
show() {
|
|
131
|
-
this.markers.
|
|
132
|
-
|
|
223
|
+
this.markers.forEach(m => {
|
|
224
|
+
try {
|
|
225
|
+
if (typeof m.show === 'function') {
|
|
226
|
+
m.show();
|
|
227
|
+
} else {
|
|
228
|
+
m.getElement().style.opacity = '1';
|
|
229
|
+
}
|
|
230
|
+
} catch (e) {
|
|
231
|
+
void e;
|
|
232
|
+
}
|
|
133
233
|
});
|
|
134
|
-
this.clusterMarkers.
|
|
135
|
-
|
|
234
|
+
this.clusterMarkers.forEach(m => {
|
|
235
|
+
try {
|
|
236
|
+
if (typeof m.show === 'function') {
|
|
237
|
+
m.show();
|
|
238
|
+
} else {
|
|
239
|
+
m.getElement().style.opacity = '1';
|
|
240
|
+
}
|
|
241
|
+
} catch (e) {
|
|
242
|
+
void e;
|
|
243
|
+
}
|
|
136
244
|
});
|
|
137
245
|
}
|
|
138
246
|
|
|
@@ -171,6 +279,25 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
171
279
|
this.mapsService.off('viewchange', this.update);
|
|
172
280
|
this.mapsService.off('camerachange', this.setContainerSize.bind(this));
|
|
173
281
|
this.mapsService.off('viewchange', this.setContainerSize.bind(this));
|
|
282
|
+
this.mapsService.off('camerachange', this.updateMarkers.bind(this));
|
|
283
|
+
this.mapsService.off('viewchange', this.updateMarkers.bind(this));
|
|
284
|
+
}
|
|
285
|
+
updateMarkers() {
|
|
286
|
+
// update positions for both origin markers and cluster markers
|
|
287
|
+
try {
|
|
288
|
+
this.markers.forEach(m => {
|
|
289
|
+
if (m && typeof m.update === 'function') {
|
|
290
|
+
m.update();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
this.clusterMarkers.forEach(m => {
|
|
294
|
+
if (m && typeof m.update === 'function') {
|
|
295
|
+
m.update();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} catch (e) {
|
|
299
|
+
void e;
|
|
300
|
+
}
|
|
174
301
|
}
|
|
175
302
|
|
|
176
303
|
// 将marker数据保存在point中
|
|
@@ -253,6 +380,27 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
253
380
|
}
|
|
254
381
|
}
|
|
255
382
|
const marker = this.clusterMarker(feature);
|
|
383
|
+
// attach layer-level re-emission so consumers can listen to cluster marker events
|
|
384
|
+
try {
|
|
385
|
+
// IMarker type may not declare EventEmitter methods; cast to any for runtime attach
|
|
386
|
+
const anyMarker = marker;
|
|
387
|
+
if (anyMarker && typeof anyMarker.on === 'function') {
|
|
388
|
+
anyMarker.on('click', ev => {
|
|
389
|
+
try {
|
|
390
|
+
this.emit('marker:click', {
|
|
391
|
+
marker: anyMarker,
|
|
392
|
+
data: anyMarker.getExtData ? anyMarker.getExtData() : null,
|
|
393
|
+
lngLat: anyMarker.getLnglat ? anyMarker.getLnglat() : null,
|
|
394
|
+
originalEvent: ev
|
|
395
|
+
});
|
|
396
|
+
} catch (e) {
|
|
397
|
+
void e;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
} catch (e) {
|
|
402
|
+
void e;
|
|
403
|
+
}
|
|
256
404
|
this.clusterMarkers.push(marker);
|
|
257
405
|
marker.addTo(this.scene);
|
|
258
406
|
});
|
|
@@ -264,16 +412,65 @@ export default class MarkerLayer extends EventEmitter {
|
|
|
264
412
|
return this.clusterIndex.getLeaves(clusterId, limit, offset);
|
|
265
413
|
}
|
|
266
414
|
clusterMarker(feature) {
|
|
415
|
+
var _feature$properties3, _feature$properties4;
|
|
267
416
|
const clusterOption = this.markerLayerOption.clusterOption;
|
|
268
417
|
const {
|
|
269
418
|
element = this.generateElement.bind(this)
|
|
270
419
|
} = clusterOption;
|
|
420
|
+
|
|
421
|
+
// determine cluster count
|
|
422
|
+
let pointCount = (_feature$properties3 = feature.properties) === null || _feature$properties3 === void 0 ? void 0 : _feature$properties3.point_count;
|
|
423
|
+
if (pointCount === undefined && (_feature$properties4 = feature.properties) !== null && _feature$properties4 !== void 0 && _feature$properties4.cluster_id) {
|
|
424
|
+
const leaves = this.getLeaves(feature.properties.cluster_id, Infinity, 0) || [];
|
|
425
|
+
pointCount = leaves.length;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// if this cluster effectively contains only one original marker, return the original marker
|
|
429
|
+
if ((pointCount === 1 || pointCount === '1') && feature.properties) {
|
|
430
|
+
// try to get the original marker by marker_id from leaves or properties
|
|
431
|
+
let leaf = null;
|
|
432
|
+
if (feature.properties.cluster_id) {
|
|
433
|
+
const leaves = this.getLeaves(feature.properties.cluster_id, 1, 0);
|
|
434
|
+
leaf = leaves && leaves[0];
|
|
435
|
+
} else if (feature.properties.marker_id !== undefined) {
|
|
436
|
+
leaf = feature;
|
|
437
|
+
}
|
|
438
|
+
if (leaf && leaf.properties && typeof leaf.properties.marker_id === 'number') {
|
|
439
|
+
const origin = this.normalMarker(leaf);
|
|
440
|
+
if (origin) {
|
|
441
|
+
// ensure aggregated properties are available on the original marker
|
|
442
|
+
try {
|
|
443
|
+
if (feature && feature.properties && typeof origin.setExtData === 'function') {
|
|
444
|
+
origin.setExtData(feature.properties);
|
|
445
|
+
}
|
|
446
|
+
} catch (e) {
|
|
447
|
+
void e;
|
|
448
|
+
}
|
|
449
|
+
return origin;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
// fallback: if no marker_id, continue to render cluster element
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// for real clusters (count > 1) or fallback, create cluster marker element
|
|
456
|
+
let el;
|
|
457
|
+
if (typeof element === 'function') {
|
|
458
|
+
el = element(feature);
|
|
459
|
+
} else {
|
|
460
|
+
// element may be a DOM node already
|
|
461
|
+
el = element;
|
|
462
|
+
}
|
|
271
463
|
const marker = new Marker({
|
|
272
|
-
element:
|
|
464
|
+
element: el
|
|
273
465
|
}).setLnglat({
|
|
274
466
|
lng: feature.geometry.coordinates[0],
|
|
275
467
|
lat: feature.geometry.coordinates[1]
|
|
276
468
|
});
|
|
469
|
+
// attach aggregated properties to the cluster marker so getExtData() returns useful info
|
|
470
|
+
if (feature && feature.properties) {
|
|
471
|
+
// @ts-ignore
|
|
472
|
+
marker.setExtData(feature.properties);
|
|
473
|
+
}
|
|
277
474
|
return marker;
|
|
278
475
|
}
|
|
279
476
|
normalMarker(feature) {
|
package/es/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/es/marker.js
CHANGED
|
@@ -19,6 +19,7 @@ export default class Marker extends EventEmitter {
|
|
|
19
19
|
lng: 0,
|
|
20
20
|
lat: 0
|
|
21
21
|
});
|
|
22
|
+
_defineProperty(this, "visible", true);
|
|
22
23
|
_defineProperty(this, "onMarkerDragStart", e => {
|
|
23
24
|
const mapContainer = this.mapsService.getContainer();
|
|
24
25
|
if (!mapContainer) {
|
|
@@ -105,7 +106,8 @@ export default class Marker extends EventEmitter {
|
|
|
105
106
|
} = this.markerOption;
|
|
106
107
|
this.mapsService.getMarkerContainer().appendChild(element);
|
|
107
108
|
this.registerMarkerEvent(element);
|
|
108
|
-
|
|
109
|
+
// marker 不再在自身注册地图相机事件,以避免为每个 marker 注册大量底层 map 监听器。
|
|
110
|
+
// 由 MarkerLayer 在 addTo 时统一注册并在相机变化时调用每个 marker.update()。
|
|
109
111
|
this.update();
|
|
110
112
|
this.updateDraggable();
|
|
111
113
|
this.added = true;
|
|
@@ -114,10 +116,7 @@ export default class Marker extends EventEmitter {
|
|
|
114
116
|
}
|
|
115
117
|
remove() {
|
|
116
118
|
if (this.mapsService) {
|
|
117
|
-
|
|
118
|
-
this.mapsService.off('move', this.update);
|
|
119
|
-
this.mapsService.off('moveend', this.update);
|
|
120
|
-
this.mapsService.off('camerachange', this.update);
|
|
119
|
+
// 不再负责移除地图级别的 update 监听(由 MarkerLayer 管理),移除地图事件请统一通过 layer
|
|
121
120
|
}
|
|
122
121
|
this.unRegisterMarkerEvent();
|
|
123
122
|
this.removeAllListeners();
|
|
@@ -132,6 +131,36 @@ export default class Marker extends EventEmitter {
|
|
|
132
131
|
}
|
|
133
132
|
return this;
|
|
134
133
|
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Hide the marker visually but keep it in the layer's data structures.
|
|
137
|
+
*/
|
|
138
|
+
hide() {
|
|
139
|
+
const {
|
|
140
|
+
element
|
|
141
|
+
} = this.markerOption;
|
|
142
|
+
if (element) {
|
|
143
|
+
element.style.display = 'none';
|
|
144
|
+
}
|
|
145
|
+
this.visible = false;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Show the marker if it was hidden.
|
|
151
|
+
*/
|
|
152
|
+
show() {
|
|
153
|
+
const {
|
|
154
|
+
element
|
|
155
|
+
} = this.markerOption;
|
|
156
|
+
if (element) {
|
|
157
|
+
element.style.display = 'block';
|
|
158
|
+
}
|
|
159
|
+
this.visible = true;
|
|
160
|
+
// re-position after showing
|
|
161
|
+
this.update();
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
135
164
|
setLnglat(lngLat) {
|
|
136
165
|
this.lngLat = lngLat;
|
|
137
166
|
if (Array.isArray(lngLat)) {
|
|
@@ -262,6 +291,9 @@ export default class Marker extends EventEmitter {
|
|
|
262
291
|
lng,
|
|
263
292
|
lat
|
|
264
293
|
} = this.lngLat;
|
|
294
|
+
if (!this.visible) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
265
297
|
if (element) {
|
|
266
298
|
element.style.display = 'block';
|
|
267
299
|
element.style.whiteSpace = 'nowrap';
|
|
@@ -300,7 +332,6 @@ export default class Marker extends EventEmitter {
|
|
|
300
332
|
element.style.transition = 'left 0.25s cubic-bezier(0,0,0.25,1), top 0.25s cubic-bezier(0,0,0.25,1)';
|
|
301
333
|
}
|
|
302
334
|
}
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
304
335
|
onMapClick(e) {
|
|
305
336
|
const {
|
|
306
337
|
element
|
|
@@ -341,6 +372,13 @@ export default class Marker extends EventEmitter {
|
|
|
341
372
|
lat
|
|
342
373
|
} = this.lngLat;
|
|
343
374
|
const pos = this.mapsService.lngLatToContainer([lng, lat]);
|
|
375
|
+
if (!this.visible) {
|
|
376
|
+
// remain hidden until show() is called
|
|
377
|
+
if (element) {
|
|
378
|
+
element.style.display = 'none';
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
344
382
|
if (element) {
|
|
345
383
|
element.style.display = 'block';
|
|
346
384
|
element.style.whiteSpace = 'nowrap';
|
|
@@ -454,14 +492,4 @@ export default class Marker extends EventEmitter {
|
|
|
454
492
|
}
|
|
455
493
|
}
|
|
456
494
|
}
|
|
457
|
-
|
|
458
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
459
|
-
addDragHandler(e) {
|
|
460
|
-
return null;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
464
|
-
onUp(e) {
|
|
465
|
-
throw new Error('Method not implemented.');
|
|
466
|
-
}
|
|
467
495
|
}
|
package/es/popup/layerPopup.d.ts
CHANGED
|
@@ -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/es/popup/layerPopup.js
CHANGED
|
@@ -79,9 +79,8 @@ export default class LayerPopup extends Popup {
|
|
|
79
79
|
* @protected
|
|
80
80
|
*/
|
|
81
81
|
getActualTriggerEvent() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} = this.popupOption;
|
|
82
|
+
var _this$popupOption$tri;
|
|
83
|
+
const trigger = (_this$popupOption$tri = this.popupOption.trigger) !== null && _this$popupOption$tri !== void 0 ? _this$popupOption$tri : 'hover';
|
|
85
84
|
if (trigger === 'click') {
|
|
86
85
|
return isPC() ? 'click' : 'touchend';
|
|
87
86
|
}
|
|
@@ -114,9 +113,12 @@ export default class LayerPopup extends Popup {
|
|
|
114
113
|
return this;
|
|
115
114
|
}
|
|
116
115
|
getDefault(option) {
|
|
117
|
-
|
|
116
|
+
var _option$trigger;
|
|
117
|
+
// trigger 默认值为 'hover'
|
|
118
|
+
const trigger = (_option$trigger = option.trigger) !== null && _option$trigger !== void 0 ? _option$trigger : 'hover';
|
|
119
|
+
const isHoverTrigger = trigger === 'hover';
|
|
118
120
|
return _objectSpread(_objectSpread({}, super.getDefault(option)), {}, {
|
|
119
|
-
trigger
|
|
121
|
+
trigger,
|
|
120
122
|
followCursor: isHoverTrigger,
|
|
121
123
|
lngLat: {
|
|
122
124
|
lng: 0,
|
package/es/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/es/popup/popup.js
CHANGED
|
@@ -61,6 +61,11 @@ export default class Popup extends EventEmitter {
|
|
|
61
61
|
* @protected
|
|
62
62
|
*/
|
|
63
63
|
_defineProperty(this, "isShow", true);
|
|
64
|
+
/**
|
|
65
|
+
* RAF 节流 ID
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
_defineProperty(this, "rafId", null);
|
|
64
69
|
_defineProperty(this, "onMouseMove", e => {
|
|
65
70
|
var _container$getBoundin;
|
|
66
71
|
const container = this.mapsService.getMapContainer();
|
|
@@ -170,7 +175,14 @@ export default class Popup extends EventEmitter {
|
|
|
170
175
|
this.updatePosition(ev, true);
|
|
171
176
|
});
|
|
172
177
|
_defineProperty(this, "update", () => {
|
|
173
|
-
|
|
178
|
+
// 使用 RAF 节流,避免高频事件导致的性能问题
|
|
179
|
+
if (this.rafId !== null) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.rafId = requestAnimationFrame(() => {
|
|
183
|
+
this.rafId = null;
|
|
184
|
+
this.updatePosition(null, false);
|
|
185
|
+
});
|
|
174
186
|
});
|
|
175
187
|
this.popupOption = _objectSpread(_objectSpread({}, this.getDefault(cfg !== null && cfg !== void 0 ? cfg : {})), cfg);
|
|
176
188
|
const {
|
|
@@ -219,6 +231,12 @@ export default class Popup extends EventEmitter {
|
|
|
219
231
|
if (!(this !== null && this !== void 0 && this.isOpen())) {
|
|
220
232
|
return;
|
|
221
233
|
}
|
|
234
|
+
|
|
235
|
+
// 取消未执行的 RAF
|
|
236
|
+
if (this.rafId !== null) {
|
|
237
|
+
cancelAnimationFrame(this.rafId);
|
|
238
|
+
this.rafId = null;
|
|
239
|
+
}
|
|
222
240
|
if (this.content) {
|
|
223
241
|
DOM.remove(this.content);
|
|
224
242
|
}
|
|
@@ -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;
|