@antv/l7-component 2.23.2 → 2.23.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -827
- package/es/marker-layer.d.ts +1 -11
- package/es/marker.d.ts +0 -2
- package/es/marker.js +0 -6
- 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/marker-layer.d.ts +1 -11
- package/lib/marker.d.ts +0 -2
- package/lib/marker.js +0 -6
- 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/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;
|
package/es/marker.d.ts
CHANGED
package/es/marker.js
CHANGED
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;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
/**
|
|
3
|
+
* 事件管理器,用于统一管理事件绑定和解绑
|
|
4
|
+
* 解决组件销毁时事件未正确清理导致的内存泄漏问题
|
|
5
|
+
*/
|
|
6
|
+
export class EventManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
_defineProperty(this, "bindings", []);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 绑定事件
|
|
12
|
+
* @param target 事件目标对象
|
|
13
|
+
* @param event 事件名称
|
|
14
|
+
* @param handler 事件处理函数
|
|
15
|
+
*/
|
|
16
|
+
on(target, event, handler) {
|
|
17
|
+
this.bindings.push({
|
|
18
|
+
target,
|
|
19
|
+
event,
|
|
20
|
+
handler
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// 根据目标类型选择绑定方式
|
|
24
|
+
if (this.isMapService(target)) {
|
|
25
|
+
target.on(event, handler);
|
|
26
|
+
} else {
|
|
27
|
+
target.addEventListener(event, handler);
|
|
28
|
+
}
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 解绑指定事件
|
|
34
|
+
* @param target 事件目标对象
|
|
35
|
+
* @param event 事件名称
|
|
36
|
+
* @param handler 事件处理函数
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
off(target, event, handler) {
|
|
40
|
+
const index = this.bindings.findIndex(b => b.target === target && b.event === event && b.handler === handler);
|
|
41
|
+
if (index > -1) {
|
|
42
|
+
this.bindings.splice(index, 1);
|
|
43
|
+
if (this.isMapService(target)) {
|
|
44
|
+
target.off(event, handler);
|
|
45
|
+
} else {
|
|
46
|
+
target.removeEventListener(event, handler);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 清除所有绑定的事件
|
|
54
|
+
*/
|
|
55
|
+
clear() {
|
|
56
|
+
this.bindings.forEach(({
|
|
57
|
+
target,
|
|
58
|
+
event,
|
|
59
|
+
handler
|
|
60
|
+
}) => {
|
|
61
|
+
if (this.isMapService(target)) {
|
|
62
|
+
target.off(event, handler);
|
|
63
|
+
} else {
|
|
64
|
+
target.removeEventListener(event, handler);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
this.bindings = [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 获取当前绑定的事件数量
|
|
72
|
+
*/
|
|
73
|
+
size() {
|
|
74
|
+
return this.bindings.length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 判断目标是否为 MapService
|
|
79
|
+
*/
|
|
80
|
+
isMapService(target) {
|
|
81
|
+
return target && typeof target.on === 'function' && typeof target.off === 'function';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export default EventManager;
|
package/es/utils/popper.js
CHANGED
|
@@ -169,6 +169,14 @@ export class Popper extends EventEmitter {
|
|
|
169
169
|
this.popperDOM.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
170
170
|
this.popperDOM.removeEventListener('mouseleave', this.onBtnMouseLeave);
|
|
171
171
|
DOM.remove(this.popperDOM);
|
|
172
|
+
|
|
173
|
+
// 从 conflictPopperList 中移除当前实例,防止内存泄漏
|
|
174
|
+
if (this.option.unique) {
|
|
175
|
+
const index = Popper.conflictPopperList.indexOf(this);
|
|
176
|
+
if (index > -1) {
|
|
177
|
+
Popper.conflictPopperList.splice(index, 1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
172
180
|
}
|
|
173
181
|
resetPopperPosition() {
|
|
174
182
|
const popperStyleObj = {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Marker from './marker';
|
|
2
2
|
import MarkerLayer from './marker-layer';
|
|
3
3
|
import './assets/iconfont/iconfont.js';
|
|
4
|
-
import './css/index.
|
|
4
|
+
import './css/index.less';
|
|
5
5
|
export * from './control/baseControl';
|
|
6
6
|
export { ExportImage, type IExportImageControlOption } from './control/exportImage';
|
|
7
7
|
export { Fullscreen, type IFullscreenControlOption } from './control/fullscreen';
|