@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.
@@ -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;
@@ -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.css';
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';