@antv/l7-component 2.25.7 → 2.25.10

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.
Files changed (151) hide show
  1. package/es/assets/iconfont/iconfont.d.ts +21 -0
  2. package/es/assets/iconfont/iconfont.js +61 -0
  3. package/es/constants/index.d.ts +60 -0
  4. package/es/constants/index.js +60 -0
  5. package/es/control/baseControl/buttonControl.d.ts +60 -0
  6. package/es/control/baseControl/buttonControl.js +142 -0
  7. package/es/control/baseControl/control.d.ts +112 -0
  8. package/es/control/baseControl/control.js +256 -0
  9. package/es/control/baseControl/index.d.ts +4 -0
  10. package/es/control/baseControl/index.js +4 -0
  11. package/es/control/baseControl/popperControl.d.ts +28 -0
  12. package/es/control/baseControl/popperControl.js +92 -0
  13. package/es/control/baseControl/selectControl.d.ts +53 -0
  14. package/es/control/baseControl/selectControl.js +173 -0
  15. package/es/control/exportImage.d.ts +19 -0
  16. package/es/control/exportImage.js +73 -0
  17. package/es/control/fullscreen.d.ts +20 -0
  18. package/es/control/fullscreen.js +88 -0
  19. package/es/control/geoLocate.d.ts +17 -0
  20. package/es/control/geoLocate.js +60 -0
  21. package/es/control/layerSwitch.d.ts +27 -0
  22. package/es/control/layerSwitch.js +155 -0
  23. package/es/control/logo.d.ts +14 -0
  24. package/es/control/logo.js +49 -0
  25. package/es/control/mapTheme.d.ts +11 -0
  26. package/es/control/mapTheme.js +69 -0
  27. package/es/control/mouseLocation.d.ts +16 -0
  28. package/es/control/mouseLocation.js +52 -0
  29. package/es/control/scale.d.ts +35 -0
  30. package/es/control/scale.js +121 -0
  31. package/es/control/swipe.d.ts +66 -0
  32. package/es/control/swipe.js +392 -0
  33. package/es/control/zoom.d.ts +39 -0
  34. package/es/control/zoom.js +100 -0
  35. package/es/css/button.less +77 -0
  36. package/es/css/control.less +82 -0
  37. package/es/css/index.css +653 -0
  38. package/es/css/index.less +13 -0
  39. package/es/css/l7.less +69 -0
  40. package/es/css/layerPopup.less +9 -0
  41. package/es/css/logo.less +21 -0
  42. package/es/css/mouseLocation.less +9 -0
  43. package/es/css/popper.less +74 -0
  44. package/es/css/popup.less +176 -0
  45. package/es/css/scale.less +37 -0
  46. package/es/css/select.less +96 -0
  47. package/es/css/swipe.less +80 -0
  48. package/es/css/variables.less +29 -0
  49. package/es/css/zoom.less +34 -0
  50. package/es/images/layers.png +0 -0
  51. package/es/images/layers.svg +1 -0
  52. package/es/images/logo.png +0 -0
  53. package/es/images/quanping.svg +12 -0
  54. package/es/index.d.ts +19 -0
  55. package/es/index.js +717 -0
  56. package/es/interface.d.ts +29 -0
  57. package/es/interface.js +1 -0
  58. package/es/marker-layer.d.ts +46 -0
  59. package/es/marker-layer.js +509 -0
  60. package/es/marker.d.ts +66 -0
  61. package/es/marker.js +495 -0
  62. package/es/popup/layerPopup.d.ts +105 -0
  63. package/es/popup/layerPopup.js +341 -0
  64. package/es/popup/popup.d.ts +147 -0
  65. package/es/popup/popup.js +587 -0
  66. package/es/utils/anchor.d.ts +22 -0
  67. package/es/utils/anchor.js +31 -0
  68. package/es/utils/eventManager.d.ts +42 -0
  69. package/es/utils/eventManager.js +84 -0
  70. package/es/utils/icon.d.ts +1 -0
  71. package/es/utils/icon.js +12 -0
  72. package/es/utils/popper.d.ts +76 -0
  73. package/es/utils/popper.js +257 -0
  74. package/es/utils/screenfull.d.ts +2 -0
  75. package/es/utils/screenfull.js +106 -0
  76. package/lib/assets/iconfont/iconfont.d.ts +21 -0
  77. package/lib/assets/iconfont/iconfont.js +68 -0
  78. package/lib/constants/index.d.ts +60 -0
  79. package/lib/constants/index.js +66 -0
  80. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  81. package/lib/control/baseControl/buttonControl.js +149 -0
  82. package/lib/control/baseControl/control.d.ts +112 -0
  83. package/lib/control/baseControl/control.js +269 -0
  84. package/lib/control/baseControl/index.d.ts +4 -0
  85. package/lib/control/baseControl/index.js +39 -0
  86. package/lib/control/baseControl/popperControl.d.ts +28 -0
  87. package/lib/control/baseControl/popperControl.js +99 -0
  88. package/lib/control/baseControl/selectControl.d.ts +53 -0
  89. package/lib/control/baseControl/selectControl.js +180 -0
  90. package/lib/control/exportImage.d.ts +19 -0
  91. package/lib/control/exportImage.js +80 -0
  92. package/lib/control/fullscreen.d.ts +20 -0
  93. package/lib/control/fullscreen.js +95 -0
  94. package/lib/control/geoLocate.d.ts +17 -0
  95. package/lib/control/geoLocate.js +67 -0
  96. package/lib/control/layerSwitch.d.ts +27 -0
  97. package/lib/control/layerSwitch.js +162 -0
  98. package/lib/control/logo.d.ts +14 -0
  99. package/lib/control/logo.js +55 -0
  100. package/lib/control/mapTheme.d.ts +11 -0
  101. package/lib/control/mapTheme.js +76 -0
  102. package/lib/control/mouseLocation.d.ts +16 -0
  103. package/lib/control/mouseLocation.js +59 -0
  104. package/lib/control/scale.d.ts +35 -0
  105. package/lib/control/scale.js +128 -0
  106. package/lib/control/swipe.d.ts +66 -0
  107. package/lib/control/swipe.js +399 -0
  108. package/lib/control/zoom.d.ts +39 -0
  109. package/lib/control/zoom.js +107 -0
  110. package/lib/css/button.less +77 -0
  111. package/lib/css/control.less +82 -0
  112. package/lib/css/index.css +653 -0
  113. package/lib/css/index.less +13 -0
  114. package/lib/css/l7.less +69 -0
  115. package/lib/css/layerPopup.less +9 -0
  116. package/lib/css/logo.less +21 -0
  117. package/lib/css/mouseLocation.less +9 -0
  118. package/lib/css/popper.less +74 -0
  119. package/lib/css/popup.less +176 -0
  120. package/lib/css/scale.less +37 -0
  121. package/lib/css/select.less +96 -0
  122. package/lib/css/swipe.less +80 -0
  123. package/lib/css/variables.less +29 -0
  124. package/lib/css/zoom.less +34 -0
  125. package/lib/images/layers.png +0 -0
  126. package/lib/images/layers.svg +1 -0
  127. package/lib/images/logo.png +0 -0
  128. package/lib/images/quanping.svg +12 -0
  129. package/lib/index.d.ts +19 -0
  130. package/lib/index.js +844 -0
  131. package/lib/interface.d.ts +29 -0
  132. package/lib/interface.js +5 -0
  133. package/lib/marker-layer.d.ts +46 -0
  134. package/lib/marker-layer.js +518 -0
  135. package/lib/marker.d.ts +66 -0
  136. package/lib/marker.js +502 -0
  137. package/lib/popup/layerPopup.d.ts +105 -0
  138. package/lib/popup/layerPopup.js +348 -0
  139. package/lib/popup/popup.d.ts +147 -0
  140. package/lib/popup/popup.js +594 -0
  141. package/lib/utils/anchor.d.ts +22 -0
  142. package/lib/utils/anchor.js +38 -0
  143. package/lib/utils/eventManager.d.ts +42 -0
  144. package/lib/utils/eventManager.js +92 -0
  145. package/lib/utils/icon.d.ts +1 -0
  146. package/lib/utils/icon.js +19 -0
  147. package/lib/utils/popper.d.ts +76 -0
  148. package/lib/utils/popper.js +264 -0
  149. package/lib/utils/screenfull.d.ts +2 -0
  150. package/lib/utils/screenfull.js +112 -0
  151. package/package.json +5 -5
@@ -0,0 +1,29 @@
1
+ export type ControlEvent = 'show' | 'hide' | 'add' | 'remove' | string;
2
+ export interface IMarkerStyleOption {
3
+ element?: (...args: any[]) => any;
4
+ style: {
5
+ [key: string]: any;
6
+ } | ((...args: any[]) => any);
7
+ className: string;
8
+ field?: string;
9
+ method?: 'sum' | 'max' | 'min' | 'mean';
10
+ radius: number;
11
+ maxZoom: number;
12
+ minZoom: number;
13
+ zoom: number;
14
+ }
15
+ export interface IMarkerLayerOption {
16
+ cluster: boolean;
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
+ }>;
29
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,46 @@
1
+ import type { IMarker, L7Container } from '@antv/l7-core';
2
+ import { EventEmitter } from 'eventemitter3';
3
+ import type { IMarkerLayerOption } from './interface';
4
+ export default class MarkerLayer extends EventEmitter {
5
+ private markers;
6
+ private markerLayerOption;
7
+ private clusterIndex;
8
+ private points;
9
+ private clusterMarkers;
10
+ private mapsService;
11
+ private scene;
12
+ private zoom;
13
+ private bbox;
14
+ private inited;
15
+ private containerSize;
16
+ constructor(option?: Partial<IMarkerLayerOption>);
17
+ getDefault(): IMarkerLayerOption;
18
+ addTo(scene: L7Container): this;
19
+ private setContainerSize;
20
+ private getContainerSize;
21
+ addMarker(marker: IMarker): void;
22
+ removeMarker(marker: IMarker): void;
23
+ /**
24
+ * 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
25
+ */
26
+ hide(): void;
27
+ /**
28
+ * 显示 marker
29
+ */
30
+ show(): void;
31
+ getMarkers(): IMarker[];
32
+ getOriginMarkers(): IMarker[];
33
+ addMarkers(): void;
34
+ clear(): void;
35
+ destroy(): void;
36
+ private updateMarkers;
37
+ private addPoint;
38
+ private removePoint;
39
+ private initCluster;
40
+ private getClusterMarker;
41
+ private getLeaves;
42
+ private clusterMarker;
43
+ private normalMarker;
44
+ private update;
45
+ private generateElement;
46
+ }
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _l7Utils = require("@antv/l7-utils");
11
+ var _eventemitter = require("eventemitter3");
12
+ var _supercluster = _interopRequireDefault(require("supercluster/dist/supercluster"));
13
+ var _marker = _interopRequireDefault(require("./marker"));
14
+ // @ts-ignore
15
+ // tslint:disable-next-line:no-submodule-imports
16
+
17
+ const {
18
+ merge
19
+ } = _l7Utils.lodashUtil;
20
+ class MarkerLayer extends _eventemitter.EventEmitter {
21
+ constructor(option) {
22
+ var _this$markerLayerOpti;
23
+ super();
24
+ (0, _defineProperty2.default)(this, "markers", []);
25
+ // 原始的marker列表
26
+ (0, _defineProperty2.default)(this, "markerLayerOption", void 0);
27
+ (0, _defineProperty2.default)(this, "clusterIndex", void 0);
28
+ (0, _defineProperty2.default)(this, "points", []);
29
+ (0, _defineProperty2.default)(this, "clusterMarkers", []);
30
+ // 聚合后的marker列表
31
+ (0, _defineProperty2.default)(this, "mapsService", void 0);
32
+ (0, _defineProperty2.default)(this, "scene", void 0);
33
+ (0, _defineProperty2.default)(this, "zoom", void 0);
34
+ (0, _defineProperty2.default)(this, "bbox", void 0);
35
+ (0, _defineProperty2.default)(this, "inited", void 0);
36
+ (0, _defineProperty2.default)(this, "containerSize", void 0);
37
+ this.markerLayerOption = merge(this.getDefault(), option);
38
+ (0, _l7Utils.bindAll)(['update'], this);
39
+ this.zoom = ((_this$markerLayerOpti = this.markerLayerOption.clusterOption) === null || _this$markerLayerOpti === void 0 ? void 0 : _this$markerLayerOpti.zoom) || -99;
40
+ }
41
+ getDefault() {
42
+ return {
43
+ cluster: false,
44
+ clusterOption: {
45
+ radius: 80,
46
+ maxZoom: 20,
47
+ minZoom: 0,
48
+ zoom: -99,
49
+ style: {},
50
+ className: ''
51
+ }
52
+ };
53
+ }
54
+
55
+ // 执行scene.addMarkerLayer时调用
56
+ addTo(scene) {
57
+ // this.remove();
58
+ this.scene = scene;
59
+ this.mapsService = scene.mapService;
60
+ if (this.markerLayerOption.cluster) {
61
+ this.initCluster();
62
+ this.update();
63
+ // 地图视野变化时,重新计算视野内的聚合点。
64
+ this.mapsService.on('camerachange', this.update); // amap1.x 更新事件
65
+ this.mapsService.on('viewchange', this.update); // amap2.0 更新事件
66
+ }
67
+ // 统一由 layer 管理 marker 的位置更新,避免每个 marker 单独注册地图事件
68
+ this.mapsService.on('camerachange', this.updateMarkers.bind(this));
69
+ this.mapsService.on('viewchange', this.updateMarkers.bind(this));
70
+ this.mapsService.on('camerachange', this.setContainerSize.bind(this)); // amap1.x 更新事件
71
+ this.mapsService.on('viewchange', this.setContainerSize.bind(this)); // amap2.0 更新事件
72
+ this.addMarkers();
73
+ this.inited = true;
74
+ return this;
75
+ }
76
+
77
+ // 设置容器大小
78
+ setContainerSize() {
79
+ if (!this.mapsService) {
80
+ return;
81
+ }
82
+ const container = this.mapsService.getContainer();
83
+ this.containerSize = {
84
+ containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
85
+ containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
86
+ bounds: this.mapsService.getBounds()
87
+ };
88
+ }
89
+
90
+ // 获取容器尺寸
91
+ getContainerSize() {
92
+ return this.containerSize;
93
+ }
94
+
95
+ // 在图层添加单个marker
96
+ addMarker(marker) {
97
+ const cluster = this.markerLayerOption.cluster;
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
+ }
147
+ if (cluster) {
148
+ this.addPoint(marker, this.markers.length);
149
+ if (this.mapsService) {
150
+ // 在新增 marker 的时候需要更新聚合信息(哪怕此时的 zoom 没有发生变化)
151
+ const zoom = this.mapsService.getZoom();
152
+ const bbox = this.mapsService.getBounds();
153
+ this.bbox = (0, _l7Utils.padBounds)(bbox, 0.5);
154
+ this.zoom = Math.floor(zoom);
155
+ this.getClusterMarker(this.bbox, this.zoom);
156
+ }
157
+ }
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
+ }
176
+ }
177
+ removeMarker(marker) {
178
+ this.markers.indexOf(marker);
179
+ const markerIndex = this.markers.indexOf(marker);
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
+ }
189
+ this.markers.splice(markerIndex, 1);
190
+ if (this.markerLayerOption.cluster) {
191
+ this.removePoint(markerIndex);
192
+ if (this.mapsService) {
193
+ this.getClusterMarker(this.bbox, this.zoom);
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ /**
200
+ * 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
201
+ */
202
+ hide() {
203
+ this.markers.forEach(m => {
204
+ try {
205
+ if (typeof m.hide === 'function') {
206
+ m.hide();
207
+ } else {
208
+ m.getElement().style.display = 'none';
209
+ }
210
+ } catch (e) {
211
+ void e;
212
+ }
213
+ });
214
+ this.clusterMarkers.forEach(m => {
215
+ try {
216
+ if (typeof m.hide === 'function') {
217
+ m.hide();
218
+ } else {
219
+ m.getElement().style.display = 'none';
220
+ }
221
+ } catch (e) {
222
+ void e;
223
+ }
224
+ });
225
+ }
226
+
227
+ /**
228
+ * 显示 marker
229
+ */
230
+ show() {
231
+ this.markers.forEach(m => {
232
+ try {
233
+ if (typeof m.show === 'function') {
234
+ m.show();
235
+ } else {
236
+ m.getElement().style.display = 'block';
237
+ }
238
+ } catch (e) {
239
+ void e;
240
+ }
241
+ });
242
+ this.clusterMarkers.forEach(m => {
243
+ try {
244
+ if (typeof m.show === 'function') {
245
+ m.show();
246
+ } else {
247
+ m.getElement().style.display = 'block';
248
+ }
249
+ } catch (e) {
250
+ void e;
251
+ }
252
+ });
253
+ }
254
+
255
+ // 返回当下的markers数据,有聚合图时返回聚合的marker列表,否则返回原始maerker列表
256
+ getMarkers() {
257
+ const cluster = this.markerLayerOption.cluster;
258
+ return cluster ? this.clusterMarkers : this.markers;
259
+ }
260
+ getOriginMarkers() {
261
+ return this.markers;
262
+ }
263
+
264
+ // 批量添加marker到scene
265
+ addMarkers() {
266
+ this.getMarkers().forEach(marker => {
267
+ marker.addTo(this.scene);
268
+ });
269
+ }
270
+
271
+ // 清除图层里的marker
272
+ clear() {
273
+ this.markers.forEach(marker => {
274
+ marker.remove();
275
+ });
276
+ this.clusterMarkers.forEach(clusterMarker => {
277
+ clusterMarker.remove();
278
+ });
279
+ this.markers = [];
280
+ this.points = [];
281
+ this.clusterMarkers = [];
282
+ }
283
+ destroy() {
284
+ this.clear();
285
+ this.removeAllListeners();
286
+ this.mapsService.off('camerachange', this.update);
287
+ this.mapsService.off('viewchange', this.update);
288
+ this.mapsService.off('camerachange', this.setContainerSize.bind(this));
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
+ }
309
+ }
310
+
311
+ // 将marker数据保存在point中
312
+ addPoint(marker, id) {
313
+ const {
314
+ lng,
315
+ lat
316
+ } = marker.getLnglat();
317
+ const feature = {
318
+ geometry: {
319
+ type: 'Point',
320
+ coordinates: [lng, lat]
321
+ },
322
+ properties: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, marker.getExtData()), {}, {
323
+ marker_id: id
324
+ })
325
+ };
326
+ this.points.push(feature);
327
+ if (this.clusterIndex) {
328
+ // 在新增点的时候需要更新 cluster 的数据
329
+ this.clusterIndex.load(this.points);
330
+ }
331
+ }
332
+ removePoint(id) {
333
+ const targetIndex = this.points.findIndex(point => point.properties.marker_id === id);
334
+ if (targetIndex > -1) {
335
+ this.points.splice(targetIndex, 1);
336
+ }
337
+ if (this.clusterIndex) {
338
+ // 在删除点的时候需要更新 cluster 的数据
339
+ this.clusterIndex.load(this.points);
340
+ }
341
+ }
342
+ initCluster() {
343
+ if (!this.markerLayerOption.cluster) {
344
+ return;
345
+ }
346
+ const {
347
+ radius,
348
+ minZoom = 0,
349
+ maxZoom
350
+ } = this.markerLayerOption.clusterOption;
351
+ this.clusterIndex = new _supercluster.default({
352
+ radius,
353
+ minZoom,
354
+ maxZoom
355
+ });
356
+ // @ts-ignore
357
+ this.clusterIndex.load(this.points);
358
+ }
359
+ getClusterMarker(viewBounds, zoom) {
360
+ const viewBBox = viewBounds[0].concat(viewBounds[1]);
361
+ const clusterPoint = this.clusterIndex.getClusters(viewBBox, zoom);
362
+ this.clusterMarkers.forEach(marker => {
363
+ marker.remove();
364
+ });
365
+ this.clusterMarkers = [];
366
+ clusterPoint.forEach(feature => {
367
+ var _feature$properties;
368
+ const {
369
+ field,
370
+ method
371
+ } = this.markerLayerOption.clusterOption;
372
+ // 处理聚合数据
373
+ if ((_feature$properties = feature.properties) !== null && _feature$properties !== void 0 && _feature$properties.cluster_id) {
374
+ var _feature$properties2;
375
+ const clusterData = this.getLeaves((_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2.cluster_id);
376
+ feature.properties.clusterData = clusterData;
377
+ if (field && method) {
378
+ const columnData = clusterData === null || clusterData === void 0 ? void 0 : clusterData.map(item => {
379
+ const data = {
380
+ [field]: item.properties[field]
381
+ };
382
+ return data;
383
+ });
384
+ const column = _l7Utils.Satistics.getColumn(columnData, field);
385
+ const stat = _l7Utils.Satistics.getSatByColumn(method, column);
386
+ const fieldName = 'point_' + method;
387
+ feature.properties[fieldName] = stat.toFixed(2);
388
+ }
389
+ }
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
+ }
412
+ this.clusterMarkers.push(marker);
413
+ marker.addTo(this.scene);
414
+ });
415
+ }
416
+ getLeaves(clusterId, limit = Infinity, offset = 0) {
417
+ if (!clusterId) {
418
+ return null;
419
+ }
420
+ return this.clusterIndex.getLeaves(clusterId, limit, offset);
421
+ }
422
+ clusterMarker(feature) {
423
+ var _feature$properties3, _feature$properties4;
424
+ const clusterOption = this.markerLayerOption.clusterOption;
425
+ const {
426
+ element = this.generateElement.bind(this)
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
+ }
471
+ const marker = new _marker.default({
472
+ element: el
473
+ }).setLnglat({
474
+ lng: feature.geometry.coordinates[0],
475
+ lat: feature.geometry.coordinates[1]
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
+ }
482
+ return marker;
483
+ }
484
+ normalMarker(feature) {
485
+ const marker_id = feature.properties.marker_id;
486
+ return this.markers[marker_id];
487
+ }
488
+ update() {
489
+ if (!this.mapsService) {
490
+ return;
491
+ }
492
+ // 当图层中无marker时,无需更新
493
+ if (this.markers.length === 0) {
494
+ return;
495
+ }
496
+ const zoom = this.mapsService.getZoom();
497
+ const bbox = this.mapsService.getBounds();
498
+ if (!this.bbox || Math.abs(zoom - this.zoom) >= 1 || !(0, _l7Utils.boundsContains)(this.bbox, bbox)) {
499
+ this.bbox = (0, _l7Utils.padBounds)(bbox, 0.5);
500
+ this.zoom = Math.floor(zoom);
501
+ this.getClusterMarker(this.bbox, this.zoom);
502
+ }
503
+ }
504
+ generateElement(feature) {
505
+ const el = _l7Utils.DOM.create('div', 'l7-marker-cluster');
506
+ const label = _l7Utils.DOM.create('div', '', el);
507
+ const span = _l7Utils.DOM.create('span', '', label);
508
+ const {
509
+ field,
510
+ method
511
+ } = this.markerLayerOption.clusterOption;
512
+ feature.properties.point_count = feature.properties.point_count || 1;
513
+ const text = field && method ? feature.properties['point_' + method] || feature.properties[field] : feature.properties.point_count;
514
+ span.textContent = text;
515
+ return el;
516
+ }
517
+ }
518
+ exports.default = MarkerLayer;
@@ -0,0 +1,66 @@
1
+ import type { ILngLat, IMarkerContainerAndBounds, IMarkerOption, IPoint, IPopup, L7Container } from '@antv/l7-core';
2
+ import { anchorType } from '@antv/l7-utils';
3
+ import { EventEmitter } from 'eventemitter3';
4
+ export default class Marker extends EventEmitter {
5
+ private markerOption;
6
+ private popup;
7
+ private mapsService;
8
+ private lngLat;
9
+ private scene;
10
+ private added;
11
+ private preLngLat;
12
+ private visible;
13
+ getMarkerLayerContainerSize(): IMarkerContainerAndBounds | void;
14
+ constructor(option?: Partial<IMarkerOption>);
15
+ getDefault(): {
16
+ element: undefined;
17
+ anchor: anchorType;
18
+ offsets: number[];
19
+ color: string;
20
+ draggable: boolean;
21
+ overflowHide: boolean;
22
+ };
23
+ addTo(scene: L7Container): this;
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;
33
+ setLnglat(lngLat: ILngLat | IPoint): this;
34
+ getLnglat(): ILngLat;
35
+ getElement(): HTMLElement;
36
+ setElement(el: HTMLElement): this;
37
+ openPopup(): this;
38
+ closePopup(): this;
39
+ setPopup(popup: IPopup): this;
40
+ togglePopup(): this;
41
+ getPopup(): IPopup;
42
+ getOffset(): number[];
43
+ setDraggable(draggable: boolean): void;
44
+ getDraggable(): boolean;
45
+ getExtData(): any;
46
+ setExtData(data: any): void;
47
+ update(): void;
48
+ private updatePositionWhenZoom;
49
+ private onMapClick;
50
+ private getCurrentContainerSize;
51
+ private updateDraggable;
52
+ private onMarkerDragStart;
53
+ private onMarkerDragMove;
54
+ private onMarkerDragEnd;
55
+ private updatePosition;
56
+ private init;
57
+ private registerMarkerEvent;
58
+ private unRegisterMarkerEvent;
59
+ private eventHandle;
60
+ /**
61
+ * 高德 2.x 使用了 fastClick.js 避免延迟,导致 IOS 移动端的 click 事件不会正常触发,需要手动触发
62
+ * @param e
63
+ */
64
+ private touchStartTime;
65
+ private polyfillEvent;
66
+ }