@antv/l7-component 2.23.0 → 2.23.2
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/control/layerSwitch.js +5 -1
- package/es/index.js +150 -28
- package/es/interface.d.ts +11 -0
- package/es/marker-layer.d.ts +1 -0
- package/es/marker-layer.js +206 -9
- package/es/marker.d.ts +10 -1
- package/es/marker.js +44 -10
- package/es/popup/layerPopup.d.ts +8 -2
- package/es/popup/layerPopup.js +24 -9
- package/es/popup/popup.js +0 -1
- package/lib/control/layerSwitch.js +5 -1
- package/lib/index.js +150 -28
- package/lib/interface.d.ts +11 -0
- package/lib/marker-layer.d.ts +1 -0
- package/lib/marker-layer.js +206 -9
- package/lib/marker.d.ts +10 -1
- package/lib/marker.js +44 -10
- package/lib/popup/layerPopup.d.ts +8 -2
- package/lib/popup/layerPopup.js +23 -8
- package/lib/popup/popup.js +0 -1
- package/package.json +5 -5
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
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;
|
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,13 +498,9 @@ class Marker extends _eventemitter.EventEmitter {
|
|
|
460
498
|
}
|
|
461
499
|
}
|
|
462
500
|
}
|
|
463
|
-
|
|
464
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
465
501
|
addDragHandler(e) {
|
|
466
502
|
return null;
|
|
467
503
|
}
|
|
468
|
-
|
|
469
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
470
504
|
onUp(e) {
|
|
471
505
|
throw new Error('Method not implemented.');
|
|
472
506
|
}
|
|
@@ -17,7 +17,7 @@ export type LayerPopupConfigItem = {
|
|
|
17
17
|
export interface ILayerPopupOption extends IPopupOption {
|
|
18
18
|
config?: LayerPopupConfigItem[];
|
|
19
19
|
items?: LayerPopupConfigItem[];
|
|
20
|
-
trigger: 'hover' | 'click';
|
|
20
|
+
trigger: 'hover' | 'click' | 'touchend' | 'touchstart';
|
|
21
21
|
}
|
|
22
22
|
type LayerMapInfo = {
|
|
23
23
|
onMouseMove?: (layer: ILayer, e: any) => void;
|
|
@@ -45,6 +45,12 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
|
|
|
45
45
|
featureId: number;
|
|
46
46
|
};
|
|
47
47
|
protected get layerConfigItems(): LayerPopupConfigItem[];
|
|
48
|
+
/**
|
|
49
|
+
* 根据环境获取实际的触发事件
|
|
50
|
+
* 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
|
|
51
|
+
* @protected
|
|
52
|
+
*/
|
|
53
|
+
protected getActualTriggerEvent(): "hover" | "click" | "touchstart" | "touchend";
|
|
48
54
|
addTo(scene: L7Container): this;
|
|
49
55
|
remove(): this;
|
|
50
56
|
setOptions(option: Partial<ILayerPopupOption>): this;
|
|
@@ -60,7 +66,7 @@ export default class LayerPopup extends Popup<ILayerPopupOption> {
|
|
|
60
66
|
*/
|
|
61
67
|
protected unbindLayerEvent(): void;
|
|
62
68
|
protected onLayerMouseMove(layer: ILayer, e: any): void;
|
|
63
|
-
protected onLayerMouseOut(layer: ILayer
|
|
69
|
+
protected onLayerMouseOut(layer: ILayer): void;
|
|
64
70
|
protected onLayerClick: (layer: ILayer, e: any) => void;
|
|
65
71
|
protected onSceneClick: () => void;
|
|
66
72
|
protected onSourceUpdate(): void;
|
package/lib/popup/layerPopup.js
CHANGED
|
@@ -78,6 +78,21 @@ class LayerPopup extends _popup.default {
|
|
|
78
78
|
} = this.popupOption;
|
|
79
79
|
return (_ref = config !== null && config !== void 0 ? config : items) !== null && _ref !== void 0 ? _ref : [];
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 根据环境获取实际的触发事件
|
|
84
|
+
* 当 trigger 为 'click' 时,移动端使用 'touchend',PC 端使用 'click'
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
87
|
+
getActualTriggerEvent() {
|
|
88
|
+
const {
|
|
89
|
+
trigger
|
|
90
|
+
} = this.popupOption;
|
|
91
|
+
if (trigger === 'click') {
|
|
92
|
+
return (0, _l7Utils.isPC)() ? 'click' : 'touchend';
|
|
93
|
+
}
|
|
94
|
+
return trigger;
|
|
95
|
+
}
|
|
81
96
|
addTo(scene) {
|
|
82
97
|
super.addTo(scene);
|
|
83
98
|
this.bindLayerEvent();
|
|
@@ -105,7 +120,7 @@ class LayerPopup extends _popup.default {
|
|
|
105
120
|
return this;
|
|
106
121
|
}
|
|
107
122
|
getDefault(option) {
|
|
108
|
-
const isHoverTrigger = option.trigger
|
|
123
|
+
const isHoverTrigger = option.trigger === 'hover';
|
|
109
124
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, super.getDefault(option)), {}, {
|
|
110
125
|
trigger: 'hover',
|
|
111
126
|
followCursor: isHoverTrigger,
|
|
@@ -130,6 +145,7 @@ class LayerPopup extends _popup.default {
|
|
|
130
145
|
trigger,
|
|
131
146
|
closeOnClick
|
|
132
147
|
} = this.popupOption;
|
|
148
|
+
const actualTrigger = this.getActualTriggerEvent();
|
|
133
149
|
this.layerConfigItems.forEach(configItem => {
|
|
134
150
|
var _layer$getSource;
|
|
135
151
|
const layer = this.getLayerByConfig(configItem);
|
|
@@ -148,10 +164,10 @@ class LayerPopup extends _popup.default {
|
|
|
148
164
|
var _this$mapsService;
|
|
149
165
|
const onLayerClick = this.onLayerClick.bind(this, layer);
|
|
150
166
|
layerInfo.onClick = onLayerClick;
|
|
151
|
-
layer === null || layer === void 0 || layer.on(
|
|
167
|
+
layer === null || layer === void 0 || layer.on(actualTrigger, onLayerClick);
|
|
152
168
|
const mapContainer = (_this$mapsService = this.mapsService) === null || _this$mapsService === void 0 ? void 0 : _this$mapsService.getMapContainer();
|
|
153
169
|
if (mapContainer && closeOnClick) {
|
|
154
|
-
mapContainer.addEventListener(
|
|
170
|
+
mapContainer.addEventListener(actualTrigger, this.onSceneClick);
|
|
155
171
|
}
|
|
156
172
|
}
|
|
157
173
|
const source = layer === null || layer === void 0 || (_layer$getSource = layer.getSource) === null || _layer$getSource === void 0 ? void 0 : _layer$getSource.call(layer);
|
|
@@ -167,6 +183,7 @@ class LayerPopup extends _popup.default {
|
|
|
167
183
|
* @protected
|
|
168
184
|
*/
|
|
169
185
|
unbindLayerEvent() {
|
|
186
|
+
const actualTrigger = this.getActualTriggerEvent();
|
|
170
187
|
this.layerConfigItems.forEach(configItem => {
|
|
171
188
|
var _this$mapsService2;
|
|
172
189
|
const layer = this.getLayerByConfig(configItem);
|
|
@@ -187,7 +204,7 @@ class LayerPopup extends _popup.default {
|
|
|
187
204
|
layer.off('mouseout', onMouseOut);
|
|
188
205
|
}
|
|
189
206
|
if (onClick) {
|
|
190
|
-
layer.off(
|
|
207
|
+
layer.off(actualTrigger, onClick);
|
|
191
208
|
}
|
|
192
209
|
if (onSourceUpdate) {
|
|
193
210
|
var _layer$getSource2;
|
|
@@ -195,7 +212,7 @@ class LayerPopup extends _popup.default {
|
|
|
195
212
|
}
|
|
196
213
|
const mapContainer = (_this$mapsService2 = this.mapsService) === null || _this$mapsService2 === void 0 ? void 0 : _this$mapsService2.getMapContainer();
|
|
197
214
|
if (mapContainer) {
|
|
198
|
-
mapContainer.removeEventListener(
|
|
215
|
+
mapContainer.removeEventListener(actualTrigger, this.onSceneClick);
|
|
199
216
|
}
|
|
200
217
|
});
|
|
201
218
|
}
|
|
@@ -214,9 +231,7 @@ class LayerPopup extends _popup.default {
|
|
|
214
231
|
this.show();
|
|
215
232
|
}
|
|
216
233
|
}
|
|
217
|
-
|
|
218
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
219
|
-
onLayerMouseOut(layer, e) {
|
|
234
|
+
onLayerMouseOut(layer) {
|
|
220
235
|
this.setDisplayFeatureInfo(undefined);
|
|
221
236
|
if (this.isShow) {
|
|
222
237
|
this.hide();
|
package/lib/popup/popup.js
CHANGED
|
@@ -442,7 +442,6 @@ class Popup extends _eventemitter.EventEmitter {
|
|
|
442
442
|
isOpen() {
|
|
443
443
|
return !!this.mapsService;
|
|
444
444
|
}
|
|
445
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
446
445
|
getDefault(option) {
|
|
447
446
|
// tslint:disable-next-line:no-object-literal-type-assertion
|
|
448
447
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/l7-component",
|
|
3
|
-
"version": "2.23.
|
|
3
|
+
"version": "2.23.2",
|
|
4
4
|
"description": "Component for L7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "https://github.com/orgs/antvis/people",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"@babel/runtime": "^7.7.7",
|
|
17
17
|
"eventemitter3": "^4.0.0",
|
|
18
18
|
"supercluster": "^7.0.0",
|
|
19
|
-
"@antv/l7-core": "2.23.
|
|
20
|
-
"@antv/l7-layers": "2.23.
|
|
21
|
-
"@antv/l7-utils": "2.23.
|
|
19
|
+
"@antv/l7-core": "2.23.2",
|
|
20
|
+
"@antv/l7-layers": "2.23.2",
|
|
21
|
+
"@antv/l7-utils": "2.23.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"less": "^4.1.3",
|
|
25
|
-
"@antv/l7-test-utils": "^2.23.
|
|
25
|
+
"@antv/l7-test-utils": "^2.23.2"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|