@antv/l7-component 2.25.6 → 2.25.7
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/package.json +5 -5
- package/es/assets/iconfont/iconfont.d.ts +0 -21
- package/es/assets/iconfont/iconfont.js +0 -61
- package/es/constants/index.d.ts +0 -60
- package/es/constants/index.js +0 -60
- package/es/control/baseControl/buttonControl.d.ts +0 -60
- package/es/control/baseControl/buttonControl.js +0 -142
- package/es/control/baseControl/control.d.ts +0 -112
- package/es/control/baseControl/control.js +0 -256
- package/es/control/baseControl/index.d.ts +0 -4
- package/es/control/baseControl/index.js +0 -4
- package/es/control/baseControl/popperControl.d.ts +0 -28
- package/es/control/baseControl/popperControl.js +0 -92
- package/es/control/baseControl/selectControl.d.ts +0 -53
- package/es/control/baseControl/selectControl.js +0 -173
- package/es/control/exportImage.d.ts +0 -19
- package/es/control/exportImage.js +0 -73
- package/es/control/fullscreen.d.ts +0 -20
- package/es/control/fullscreen.js +0 -88
- package/es/control/geoLocate.d.ts +0 -17
- package/es/control/geoLocate.js +0 -60
- package/es/control/layerSwitch.d.ts +0 -27
- package/es/control/layerSwitch.js +0 -155
- package/es/control/logo.d.ts +0 -14
- package/es/control/logo.js +0 -49
- package/es/control/mapTheme.d.ts +0 -11
- package/es/control/mapTheme.js +0 -69
- package/es/control/mouseLocation.d.ts +0 -16
- package/es/control/mouseLocation.js +0 -52
- package/es/control/scale.d.ts +0 -35
- package/es/control/scale.js +0 -121
- package/es/control/swipe.d.ts +0 -66
- package/es/control/swipe.js +0 -392
- package/es/control/zoom.d.ts +0 -39
- package/es/control/zoom.js +0 -100
- package/es/css/button.less +0 -77
- package/es/css/control.less +0 -82
- package/es/css/index.css +0 -653
- package/es/css/index.less +0 -13
- package/es/css/l7.less +0 -69
- package/es/css/layerPopup.less +0 -9
- package/es/css/logo.less +0 -21
- package/es/css/mouseLocation.less +0 -9
- package/es/css/popper.less +0 -74
- package/es/css/popup.less +0 -176
- package/es/css/scale.less +0 -37
- package/es/css/select.less +0 -96
- package/es/css/swipe.less +0 -80
- package/es/css/variables.less +0 -29
- package/es/css/zoom.less +0 -34
- package/es/images/layers.png +0 -0
- package/es/images/layers.svg +0 -1
- package/es/images/logo.png +0 -0
- package/es/images/quanping.svg +0 -12
- package/es/index.d.ts +0 -19
- package/es/index.js +0 -708
- package/es/interface.d.ts +0 -29
- package/es/interface.js +0 -1
- package/es/marker-layer.d.ts +0 -46
- package/es/marker-layer.js +0 -509
- package/es/marker.d.ts +0 -66
- package/es/marker.js +0 -495
- package/es/popup/layerPopup.d.ts +0 -105
- package/es/popup/layerPopup.js +0 -341
- package/es/popup/popup.d.ts +0 -147
- package/es/popup/popup.js +0 -587
- package/es/utils/anchor.d.ts +0 -22
- package/es/utils/anchor.js +0 -31
- package/es/utils/eventManager.d.ts +0 -42
- package/es/utils/eventManager.js +0 -84
- package/es/utils/icon.d.ts +0 -1
- package/es/utils/icon.js +0 -12
- package/es/utils/popper.d.ts +0 -76
- package/es/utils/popper.js +0 -257
- package/es/utils/screenfull.d.ts +0 -2
- package/es/utils/screenfull.js +0 -106
- package/lib/assets/iconfont/iconfont.d.ts +0 -21
- package/lib/assets/iconfont/iconfont.js +0 -68
- package/lib/constants/index.d.ts +0 -60
- package/lib/constants/index.js +0 -66
- package/lib/control/baseControl/buttonControl.d.ts +0 -60
- package/lib/control/baseControl/buttonControl.js +0 -149
- package/lib/control/baseControl/control.d.ts +0 -112
- package/lib/control/baseControl/control.js +0 -269
- package/lib/control/baseControl/index.d.ts +0 -4
- package/lib/control/baseControl/index.js +0 -39
- package/lib/control/baseControl/popperControl.d.ts +0 -28
- package/lib/control/baseControl/popperControl.js +0 -99
- package/lib/control/baseControl/selectControl.d.ts +0 -53
- package/lib/control/baseControl/selectControl.js +0 -180
- package/lib/control/exportImage.d.ts +0 -19
- package/lib/control/exportImage.js +0 -80
- package/lib/control/fullscreen.d.ts +0 -20
- package/lib/control/fullscreen.js +0 -95
- package/lib/control/geoLocate.d.ts +0 -17
- package/lib/control/geoLocate.js +0 -67
- package/lib/control/layerSwitch.d.ts +0 -27
- package/lib/control/layerSwitch.js +0 -162
- package/lib/control/logo.d.ts +0 -14
- package/lib/control/logo.js +0 -55
- package/lib/control/mapTheme.d.ts +0 -11
- package/lib/control/mapTheme.js +0 -76
- package/lib/control/mouseLocation.d.ts +0 -16
- package/lib/control/mouseLocation.js +0 -59
- package/lib/control/scale.d.ts +0 -35
- package/lib/control/scale.js +0 -128
- package/lib/control/swipe.d.ts +0 -66
- package/lib/control/swipe.js +0 -399
- package/lib/control/zoom.d.ts +0 -39
- package/lib/control/zoom.js +0 -107
- package/lib/css/button.less +0 -77
- package/lib/css/control.less +0 -82
- package/lib/css/index.css +0 -653
- package/lib/css/index.less +0 -13
- package/lib/css/l7.less +0 -69
- package/lib/css/layerPopup.less +0 -9
- package/lib/css/logo.less +0 -21
- package/lib/css/mouseLocation.less +0 -9
- package/lib/css/popper.less +0 -74
- package/lib/css/popup.less +0 -176
- package/lib/css/scale.less +0 -37
- package/lib/css/select.less +0 -96
- package/lib/css/swipe.less +0 -80
- package/lib/css/variables.less +0 -29
- package/lib/css/zoom.less +0 -34
- package/lib/images/layers.png +0 -0
- package/lib/images/layers.svg +0 -1
- package/lib/images/logo.png +0 -0
- package/lib/images/quanping.svg +0 -12
- package/lib/index.d.ts +0 -19
- package/lib/index.js +0 -835
- package/lib/interface.d.ts +0 -29
- package/lib/interface.js +0 -5
- package/lib/marker-layer.d.ts +0 -46
- package/lib/marker-layer.js +0 -518
- package/lib/marker.d.ts +0 -66
- package/lib/marker.js +0 -502
- package/lib/popup/layerPopup.d.ts +0 -105
- package/lib/popup/layerPopup.js +0 -348
- package/lib/popup/popup.d.ts +0 -147
- package/lib/popup/popup.js +0 -594
- package/lib/utils/anchor.d.ts +0 -22
- package/lib/utils/anchor.js +0 -38
- package/lib/utils/eventManager.d.ts +0 -42
- package/lib/utils/eventManager.js +0 -92
- package/lib/utils/icon.d.ts +0 -1
- package/lib/utils/icon.js +0 -19
- package/lib/utils/popper.d.ts +0 -76
- package/lib/utils/popper.js +0 -264
- package/lib/utils/screenfull.d.ts +0 -2
- package/lib/utils/screenfull.js +0 -112
package/lib/interface.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/interface.js
DELETED
package/lib/marker-layer.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/marker-layer.js
DELETED
|
@@ -1,518 +0,0 @@
|
|
|
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;
|
package/lib/marker.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
}
|