@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/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;
|
package/lib/marker.d.ts
CHANGED
package/lib/marker.js
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/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;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.EventManager = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
/**
|
|
10
|
+
* 事件管理器,用于统一管理事件绑定和解绑
|
|
11
|
+
* 解决组件销毁时事件未正确清理导致的内存泄漏问题
|
|
12
|
+
*/
|
|
13
|
+
class EventManager {
|
|
14
|
+
constructor() {
|
|
15
|
+
(0, _defineProperty2.default)(this, "bindings", []);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 绑定事件
|
|
19
|
+
* @param target 事件目标对象
|
|
20
|
+
* @param event 事件名称
|
|
21
|
+
* @param handler 事件处理函数
|
|
22
|
+
*/
|
|
23
|
+
on(target, event, handler) {
|
|
24
|
+
this.bindings.push({
|
|
25
|
+
target,
|
|
26
|
+
event,
|
|
27
|
+
handler
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 根据目标类型选择绑定方式
|
|
31
|
+
if (this.isMapService(target)) {
|
|
32
|
+
target.on(event, handler);
|
|
33
|
+
} else {
|
|
34
|
+
target.addEventListener(event, handler);
|
|
35
|
+
}
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 解绑指定事件
|
|
41
|
+
* @param target 事件目标对象
|
|
42
|
+
* @param event 事件名称
|
|
43
|
+
* @param handler 事件处理函数
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
off(target, event, handler) {
|
|
47
|
+
const index = this.bindings.findIndex(b => b.target === target && b.event === event && b.handler === handler);
|
|
48
|
+
if (index > -1) {
|
|
49
|
+
this.bindings.splice(index, 1);
|
|
50
|
+
if (this.isMapService(target)) {
|
|
51
|
+
target.off(event, handler);
|
|
52
|
+
} else {
|
|
53
|
+
target.removeEventListener(event, handler);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 清除所有绑定的事件
|
|
61
|
+
*/
|
|
62
|
+
clear() {
|
|
63
|
+
this.bindings.forEach(({
|
|
64
|
+
target,
|
|
65
|
+
event,
|
|
66
|
+
handler
|
|
67
|
+
}) => {
|
|
68
|
+
if (this.isMapService(target)) {
|
|
69
|
+
target.off(event, handler);
|
|
70
|
+
} else {
|
|
71
|
+
target.removeEventListener(event, handler);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
this.bindings = [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 获取当前绑定的事件数量
|
|
79
|
+
*/
|
|
80
|
+
size() {
|
|
81
|
+
return this.bindings.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 判断目标是否为 MapService
|
|
86
|
+
*/
|
|
87
|
+
isMapService(target) {
|
|
88
|
+
return target && typeof target.on === 'function' && typeof target.off === 'function';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.EventManager = EventManager;
|
|
92
|
+
var _default = exports.default = EventManager;
|
package/lib/utils/popper.js
CHANGED
|
@@ -175,6 +175,14 @@ class Popper extends _eventemitter.EventEmitter {
|
|
|
175
175
|
this.popperDOM.removeEventListener('mousemove', this.onBtnMouseMove);
|
|
176
176
|
this.popperDOM.removeEventListener('mouseleave', this.onBtnMouseLeave);
|
|
177
177
|
_l7Utils.DOM.remove(this.popperDOM);
|
|
178
|
+
|
|
179
|
+
// 从 conflictPopperList 中移除当前实例,防止内存泄漏
|
|
180
|
+
if (this.option.unique) {
|
|
181
|
+
const index = Popper.conflictPopperList.indexOf(this);
|
|
182
|
+
if (index > -1) {
|
|
183
|
+
Popper.conflictPopperList.splice(index, 1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
178
186
|
}
|
|
179
187
|
resetPopperPosition() {
|
|
180
188
|
const popperStyleObj = {};
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/l7-component",
|
|
3
|
-
"version": "2.23.
|
|
3
|
+
"version": "2.23.3-beta.1",
|
|
4
4
|
"description": "Component for L7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "https://github.com/orgs/antvis/people",
|
|
7
|
-
"sideEffects":
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"*.css",
|
|
9
|
+
"*.less"
|
|
10
|
+
],
|
|
8
11
|
"main": "lib/index.js",
|
|
9
12
|
"module": "es/index.js",
|
|
10
13
|
"types": "es/index.d.ts",
|
|
@@ -16,13 +19,13 @@
|
|
|
16
19
|
"@babel/runtime": "^7.7.7",
|
|
17
20
|
"eventemitter3": "^4.0.0",
|
|
18
21
|
"supercluster": "^7.0.0",
|
|
19
|
-
"@antv/l7-core": "2.23.
|
|
20
|
-
"@antv/l7-layers": "2.23.
|
|
21
|
-
"@antv/l7-utils": "2.23.
|
|
22
|
+
"@antv/l7-core": "2.23.3-beta.1",
|
|
23
|
+
"@antv/l7-layers": "2.23.3-beta.1",
|
|
24
|
+
"@antv/l7-utils": "2.23.3-beta.1"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"less": "^4.1.3",
|
|
25
|
-
"@antv/l7-test-utils": "^2.23.
|
|
28
|
+
"@antv/l7-test-utils": "^2.23.3-beta.1"
|
|
26
29
|
},
|
|
27
30
|
"publishConfig": {
|
|
28
31
|
"access": "public",
|
|
@@ -34,7 +37,6 @@
|
|
|
34
37
|
"build": "npm run clean && father build",
|
|
35
38
|
"check-deps": "father doctor",
|
|
36
39
|
"lint": "eslint src __tests__",
|
|
37
|
-
"clean": "rimraf dist es lib"
|
|
38
|
-
"less": "lessc src/css/index.less src/css/index.css"
|
|
40
|
+
"clean": "rimraf dist es lib"
|
|
39
41
|
}
|
|
40
42
|
}
|