@antv/l7-component 2.21.0 → 2.21.2
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/assets/iconfont/iconfont.js +6 -6
- package/es/constants/index.js +2 -2
- package/es/control/baseControl/buttonControl.js +109 -144
- package/es/control/baseControl/control.js +212 -258
- package/es/control/baseControl/popperControl.js +67 -95
- package/es/control/baseControl/selectControl.js +132 -178
- package/es/control/exportImage.js +59 -142
- package/es/control/fullscreen.js +69 -100
- package/es/control/geoLocate.js +37 -84
- package/es/control/layerSwitch.js +111 -154
- package/es/control/logo.js +43 -69
- package/es/control/mapTheme.js +57 -98
- package/es/control/mouseLocation.js +37 -69
- package/es/control/scale.js +107 -135
- package/es/control/swipe.js +297 -393
- package/es/control/zoom.js +80 -112
- package/es/css/index.css +10 -7
- package/es/index.js +667 -1
- package/es/marker-layer.js +274 -326
- package/es/marker.d.ts +0 -2
- package/es/marker.js +394 -453
- package/es/popup/layerPopup.js +277 -321
- package/es/popup/popup.js +422 -482
- package/es/utils/anchor.js +6 -6
- package/es/utils/icon.js +4 -4
- package/es/utils/popper.js +180 -196
- package/es/utils/screenfull.js +29 -51
- package/lib/assets/iconfont/iconfont.js +6 -6
- package/lib/constants/index.d.ts +60 -0
- package/lib/constants/index.js +2 -2
- package/lib/control/baseControl/buttonControl.d.ts +60 -0
- package/lib/control/baseControl/buttonControl.js +110 -143
- package/lib/control/baseControl/control.d.ts +112 -0
- package/lib/control/baseControl/control.js +213 -257
- package/lib/control/baseControl/index.d.ts +4 -0
- package/lib/control/baseControl/index.js +5 -5
- package/lib/control/baseControl/popperControl.d.ts +28 -0
- package/lib/control/baseControl/popperControl.js +68 -94
- package/lib/control/baseControl/selectControl.d.ts +53 -0
- package/lib/control/baseControl/selectControl.js +133 -177
- package/lib/control/exportImage.d.ts +19 -0
- package/lib/control/exportImage.js +60 -141
- package/lib/control/fullscreen.d.ts +20 -0
- package/lib/control/fullscreen.js +70 -99
- package/lib/control/geoLocate.d.ts +17 -0
- package/lib/control/geoLocate.js +38 -83
- package/lib/control/layerSwitch.d.ts +27 -0
- package/lib/control/layerSwitch.js +112 -153
- package/lib/control/logo.d.ts +14 -0
- package/lib/control/logo.js +44 -69
- package/lib/control/mapTheme.d.ts +11 -0
- package/lib/control/mapTheme.js +58 -97
- package/lib/control/mouseLocation.d.ts +16 -0
- package/lib/control/mouseLocation.js +38 -68
- package/lib/control/scale.d.ts +35 -0
- package/lib/control/scale.js +108 -134
- package/lib/control/swipe.d.ts +66 -0
- package/lib/control/swipe.js +298 -392
- package/lib/control/zoom.d.ts +39 -0
- package/lib/control/zoom.js +81 -111
- package/lib/css/index.css +10 -7
- package/lib/index.d.ts +19 -0
- package/lib/index.js +683 -17
- package/lib/interface.d.ts +18 -0
- package/lib/marker-layer.d.ts +55 -0
- package/lib/marker-layer.js +276 -324
- package/lib/marker.d.ts +58 -0
- package/lib/marker.js +395 -452
- package/lib/popup/layerPopup.d.ts +99 -0
- package/lib/popup/layerPopup.js +278 -320
- package/lib/popup/popup.d.ts +142 -0
- package/lib/popup/popup.js +423 -481
- package/lib/utils/anchor.d.ts +22 -0
- package/lib/utils/anchor.js +6 -6
- package/lib/utils/icon.d.ts +1 -0
- package/lib/utils/icon.js +6 -5
- package/lib/utils/popper.d.ts +76 -0
- package/lib/utils/popper.js +184 -196
- package/lib/utils/screenfull.d.ts +2 -0
- package/lib/utils/screenfull.js +29 -52
- package/package.json +16 -20
- package/CHANGELOG.md +0 -325
- package/LICENSE.md +0 -21
package/es/marker-layer.js
CHANGED
|
@@ -1,364 +1,312 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
5
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
6
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
7
|
-
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
8
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
3
|
import { DOM, Satistics, bindAll, boundsContains, lodashUtil, padBounds } from '@antv/l7-utils';
|
|
12
4
|
import { EventEmitter } from 'eventemitter3';
|
|
13
5
|
// @ts-ignore
|
|
14
6
|
// tslint:disable-next-line:no-submodule-imports
|
|
15
7
|
import Supercluster from 'supercluster/dist/supercluster';
|
|
16
8
|
import Marker from "./marker";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function MarkerLayer(option) {
|
|
9
|
+
const {
|
|
10
|
+
merge
|
|
11
|
+
} = lodashUtil;
|
|
12
|
+
export default class MarkerLayer extends EventEmitter {
|
|
13
|
+
constructor(option) {
|
|
24
14
|
var _this$markerLayerOpti;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_defineProperty(
|
|
29
|
-
_defineProperty(
|
|
30
|
-
_defineProperty(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
super();
|
|
16
|
+
_defineProperty(this, "markers", []);
|
|
17
|
+
// 原始的marker列表
|
|
18
|
+
_defineProperty(this, "markerLayerOption", void 0);
|
|
19
|
+
_defineProperty(this, "clusterIndex", void 0);
|
|
20
|
+
_defineProperty(this, "points", []);
|
|
21
|
+
_defineProperty(this, "clusterMarkers", []);
|
|
22
|
+
// 聚合后的marker列表
|
|
23
|
+
_defineProperty(this, "mapsService", void 0);
|
|
24
|
+
_defineProperty(this, "scene", void 0);
|
|
25
|
+
_defineProperty(this, "zoom", void 0);
|
|
26
|
+
_defineProperty(this, "bbox", void 0);
|
|
27
|
+
_defineProperty(this, "inited", void 0);
|
|
28
|
+
_defineProperty(this, "containerSize", void 0);
|
|
29
|
+
this.markerLayerOption = merge(this.getDefault(), option);
|
|
30
|
+
bindAll(['update'], this);
|
|
31
|
+
this.zoom = ((_this$markerLayerOpti = this.markerLayerOption.clusterOption) === null || _this$markerLayerOpti === void 0 ? void 0 : _this$markerLayerOpti.zoom) || -99;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
style: {},
|
|
47
|
-
className: ''
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 执行scene.addMarkerLayer时调用
|
|
53
|
-
}, {
|
|
54
|
-
key: "addTo",
|
|
55
|
-
value: function addTo(scene) {
|
|
56
|
-
// this.remove();
|
|
57
|
-
this.scene = scene;
|
|
58
|
-
this.mapsService = scene.mapService;
|
|
59
|
-
if (this.markerLayerOption.cluster) {
|
|
60
|
-
this.initCluster();
|
|
61
|
-
this.update();
|
|
62
|
-
// 地图视野变化时,重新计算视野内的聚合点。
|
|
63
|
-
this.mapsService.on('camerachange', this.update); // amap1.x 更新事件
|
|
64
|
-
this.mapsService.on('viewchange', this.update); // amap2.0 更新事件
|
|
33
|
+
getDefault() {
|
|
34
|
+
return {
|
|
35
|
+
cluster: false,
|
|
36
|
+
clusterOption: {
|
|
37
|
+
radius: 80,
|
|
38
|
+
maxZoom: 20,
|
|
39
|
+
minZoom: 0,
|
|
40
|
+
zoom: -99,
|
|
41
|
+
style: {},
|
|
42
|
+
className: ''
|
|
65
43
|
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
66
46
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
// 执行scene.addMarkerLayer时调用
|
|
48
|
+
addTo(scene) {
|
|
49
|
+
// this.remove();
|
|
50
|
+
this.scene = scene;
|
|
51
|
+
this.mapsService = scene.mapService;
|
|
52
|
+
if (this.markerLayerOption.cluster) {
|
|
53
|
+
this.initCluster();
|
|
54
|
+
this.update();
|
|
55
|
+
// 地图视野变化时,重新计算视野内的聚合点。
|
|
56
|
+
this.mapsService.on('camerachange', this.update); // amap1.x 更新事件
|
|
57
|
+
this.mapsService.on('viewchange', this.update); // amap2.0 更新事件
|
|
72
58
|
}
|
|
59
|
+
this.mapsService.on('camerachange', this.setContainerSize.bind(this)); // amap1.x 更新事件
|
|
60
|
+
this.mapsService.on('viewchange', this.setContainerSize.bind(this)); // amap2.0 更新事件
|
|
61
|
+
this.addMarkers();
|
|
62
|
+
this.inited = true;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!this.mapsService) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
var container = this.mapsService.getContainer();
|
|
82
|
-
this.containerSize = {
|
|
83
|
-
containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
|
|
84
|
-
containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
|
|
85
|
-
bounds: this.mapsService.getBounds()
|
|
86
|
-
};
|
|
66
|
+
// 设置容器大小
|
|
67
|
+
setContainerSize() {
|
|
68
|
+
if (!this.mapsService) {
|
|
69
|
+
return;
|
|
87
70
|
}
|
|
71
|
+
const container = this.mapsService.getContainer();
|
|
72
|
+
this.containerSize = {
|
|
73
|
+
containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
|
|
74
|
+
containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
|
|
75
|
+
bounds: this.mapsService.getBounds()
|
|
76
|
+
};
|
|
77
|
+
}
|
|
88
78
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return this.containerSize;
|
|
94
|
-
}
|
|
79
|
+
// 获取容器尺寸
|
|
80
|
+
getContainerSize() {
|
|
81
|
+
return this.containerSize;
|
|
82
|
+
}
|
|
95
83
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
marker
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.zoom = Math.floor(zoom);
|
|
110
|
-
this.getClusterMarker(this.bbox, this.zoom);
|
|
111
|
-
}
|
|
84
|
+
// 在图层添加单个marker
|
|
85
|
+
addMarker(marker) {
|
|
86
|
+
const cluster = this.markerLayerOption.cluster;
|
|
87
|
+
marker.getMarkerLayerContainerSize = this.getContainerSize.bind(this);
|
|
88
|
+
if (cluster) {
|
|
89
|
+
this.addPoint(marker, this.markers.length);
|
|
90
|
+
if (this.mapsService) {
|
|
91
|
+
// 在新增 marker 的时候需要更新聚合信息(哪怕此时的 zoom 没有发生变化)
|
|
92
|
+
const zoom = this.mapsService.getZoom();
|
|
93
|
+
const bbox = this.mapsService.getBounds();
|
|
94
|
+
this.bbox = padBounds(bbox, 0.5);
|
|
95
|
+
this.zoom = Math.floor(zoom);
|
|
96
|
+
this.getClusterMarker(this.bbox, this.zoom);
|
|
112
97
|
}
|
|
113
|
-
this.markers.push(marker);
|
|
114
98
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
99
|
+
this.markers.push(marker);
|
|
100
|
+
}
|
|
101
|
+
removeMarker(marker) {
|
|
102
|
+
this.markers.indexOf(marker);
|
|
103
|
+
const markerIndex = this.markers.indexOf(marker);
|
|
104
|
+
if (markerIndex > -1) {
|
|
105
|
+
this.markers.splice(markerIndex, 1);
|
|
106
|
+
if (this.markerLayerOption.cluster) {
|
|
107
|
+
this.removePoint(markerIndex);
|
|
108
|
+
if (this.mapsService) {
|
|
109
|
+
this.getClusterMarker(this.bbox, this.zoom);
|
|
127
110
|
}
|
|
128
111
|
}
|
|
129
112
|
}
|
|
113
|
+
}
|
|
130
114
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
}
|
|
115
|
+
/**
|
|
116
|
+
* 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
|
|
117
|
+
*/
|
|
118
|
+
hide() {
|
|
119
|
+
this.markers.map(m => {
|
|
120
|
+
m.getElement().style.opacity = '0';
|
|
121
|
+
});
|
|
122
|
+
this.clusterMarkers.map(m => {
|
|
123
|
+
m.getElement().style.opacity = '0';
|
|
124
|
+
});
|
|
125
|
+
}
|
|
144
126
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
}
|
|
127
|
+
/**
|
|
128
|
+
* 显示 marker
|
|
129
|
+
*/
|
|
130
|
+
show() {
|
|
131
|
+
this.markers.map(m => {
|
|
132
|
+
m.getElement().style.opacity = '1';
|
|
133
|
+
});
|
|
134
|
+
this.clusterMarkers.map(m => {
|
|
135
|
+
m.getElement().style.opacity = '1';
|
|
136
|
+
});
|
|
137
|
+
}
|
|
158
138
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
key: "getOriginMarkers",
|
|
168
|
-
value: function getOriginMarkers() {
|
|
169
|
-
return this.markers;
|
|
170
|
-
}
|
|
139
|
+
// 返回当下的markers数据,有聚合图时返回聚合的marker列表,否则返回原始maerker列表
|
|
140
|
+
getMarkers() {
|
|
141
|
+
const cluster = this.markerLayerOption.cluster;
|
|
142
|
+
return cluster ? this.clusterMarkers : this.markers;
|
|
143
|
+
}
|
|
144
|
+
getOriginMarkers() {
|
|
145
|
+
return this.markers;
|
|
146
|
+
}
|
|
171
147
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
marker.addTo(_this2.scene);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
148
|
+
// 批量添加marker到scene
|
|
149
|
+
addMarkers() {
|
|
150
|
+
this.getMarkers().forEach(marker => {
|
|
151
|
+
marker.addTo(this.scene);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
181
154
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.mapsService.off('viewchange', this.update);
|
|
203
|
-
this.mapsService.off('camerachange', this.setContainerSize.bind(this));
|
|
204
|
-
this.mapsService.off('viewchange', this.setContainerSize.bind(this));
|
|
205
|
-
}
|
|
155
|
+
// 清除图层里的marker
|
|
156
|
+
clear() {
|
|
157
|
+
this.markers.forEach(marker => {
|
|
158
|
+
marker.remove();
|
|
159
|
+
});
|
|
160
|
+
this.clusterMarkers.forEach(clusterMarker => {
|
|
161
|
+
clusterMarker.remove();
|
|
162
|
+
});
|
|
163
|
+
this.markers = [];
|
|
164
|
+
this.points = [];
|
|
165
|
+
this.clusterMarkers = [];
|
|
166
|
+
}
|
|
167
|
+
destroy() {
|
|
168
|
+
this.clear();
|
|
169
|
+
this.removeAllListeners();
|
|
170
|
+
this.mapsService.off('camerachange', this.update);
|
|
171
|
+
this.mapsService.off('viewchange', this.update);
|
|
172
|
+
this.mapsService.off('camerachange', this.setContainerSize.bind(this));
|
|
173
|
+
this.mapsService.off('viewchange', this.setContainerSize.bind(this));
|
|
174
|
+
}
|
|
206
175
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.clusterIndex.load(this.points);
|
|
227
|
-
}
|
|
176
|
+
// 将marker数据保存在point中
|
|
177
|
+
addPoint(marker, id) {
|
|
178
|
+
const {
|
|
179
|
+
lng,
|
|
180
|
+
lat
|
|
181
|
+
} = marker.getLnglat();
|
|
182
|
+
const feature = {
|
|
183
|
+
geometry: {
|
|
184
|
+
type: 'Point',
|
|
185
|
+
coordinates: [lng, lat]
|
|
186
|
+
},
|
|
187
|
+
properties: _objectSpread(_objectSpread({}, marker.getExtData()), {}, {
|
|
188
|
+
marker_id: id
|
|
189
|
+
})
|
|
190
|
+
};
|
|
191
|
+
this.points.push(feature);
|
|
192
|
+
if (this.clusterIndex) {
|
|
193
|
+
// 在新增点的时候需要更新 cluster 的数据
|
|
194
|
+
this.clusterIndex.load(this.points);
|
|
228
195
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
if (targetIndex > -1) {
|
|
236
|
-
this.points.splice(targetIndex, 1);
|
|
237
|
-
}
|
|
238
|
-
if (this.clusterIndex) {
|
|
239
|
-
// 在删除点的时候需要更新 cluster 的数据
|
|
240
|
-
this.clusterIndex.load(this.points);
|
|
241
|
-
}
|
|
196
|
+
}
|
|
197
|
+
removePoint(id) {
|
|
198
|
+
const targetIndex = this.points.findIndex(point => point.properties.marker_id === id);
|
|
199
|
+
if (targetIndex > -1) {
|
|
200
|
+
this.points.splice(targetIndex, 1);
|
|
242
201
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
value: function initCluster() {
|
|
246
|
-
if (!this.markerLayerOption.cluster) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
var _this$markerLayerOpti2 = this.markerLayerOption.clusterOption,
|
|
250
|
-
radius = _this$markerLayerOpti2.radius,
|
|
251
|
-
_this$markerLayerOpti3 = _this$markerLayerOpti2.minZoom,
|
|
252
|
-
minZoom = _this$markerLayerOpti3 === void 0 ? 0 : _this$markerLayerOpti3,
|
|
253
|
-
maxZoom = _this$markerLayerOpti2.maxZoom;
|
|
254
|
-
this.clusterIndex = new Supercluster({
|
|
255
|
-
radius: radius,
|
|
256
|
-
minZoom: minZoom,
|
|
257
|
-
maxZoom: maxZoom
|
|
258
|
-
});
|
|
259
|
-
// @ts-ignore
|
|
202
|
+
if (this.clusterIndex) {
|
|
203
|
+
// 在删除点的时候需要更新 cluster 的数据
|
|
260
204
|
this.clusterIndex.load(this.points);
|
|
261
205
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var viewBBox = viewBounds[0].concat(viewBounds[1]);
|
|
267
|
-
var clusterPoint = this.clusterIndex.getClusters(viewBBox, zoom);
|
|
268
|
-
this.clusterMarkers.forEach(function (marker) {
|
|
269
|
-
marker.remove();
|
|
270
|
-
});
|
|
271
|
-
this.clusterMarkers = [];
|
|
272
|
-
clusterPoint.forEach(function (feature) {
|
|
273
|
-
var _feature$properties;
|
|
274
|
-
var _this3$markerLayerOpt = _this3.markerLayerOption.clusterOption,
|
|
275
|
-
field = _this3$markerLayerOpt.field,
|
|
276
|
-
method = _this3$markerLayerOpt.method;
|
|
277
|
-
// 处理聚合数据
|
|
278
|
-
if ((_feature$properties = feature.properties) !== null && _feature$properties !== void 0 && _feature$properties.cluster_id) {
|
|
279
|
-
var _feature$properties2;
|
|
280
|
-
var clusterData = _this3.getLeaves((_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2.cluster_id);
|
|
281
|
-
feature.properties.clusterData = clusterData;
|
|
282
|
-
if (field && method) {
|
|
283
|
-
var columnData = clusterData === null || clusterData === void 0 ? void 0 : clusterData.map(function (item) {
|
|
284
|
-
var data = _defineProperty({}, field, item.properties[field]);
|
|
285
|
-
return data;
|
|
286
|
-
});
|
|
287
|
-
var column = Satistics.getColumn(columnData, field);
|
|
288
|
-
var stat = Satistics.getSatByColumn(method, column);
|
|
289
|
-
var fieldName = 'point_' + method;
|
|
290
|
-
feature.properties[fieldName] = stat.toFixed(2);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
var marker = _this3.clusterMarker(feature);
|
|
294
|
-
_this3.clusterMarkers.push(marker);
|
|
295
|
-
marker.addTo(_this3.scene);
|
|
296
|
-
});
|
|
206
|
+
}
|
|
207
|
+
initCluster() {
|
|
208
|
+
if (!this.markerLayerOption.cluster) {
|
|
209
|
+
return;
|
|
297
210
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
211
|
+
const {
|
|
212
|
+
radius,
|
|
213
|
+
minZoom = 0,
|
|
214
|
+
maxZoom
|
|
215
|
+
} = this.markerLayerOption.clusterOption;
|
|
216
|
+
this.clusterIndex = new Supercluster({
|
|
217
|
+
radius,
|
|
218
|
+
minZoom,
|
|
219
|
+
maxZoom
|
|
220
|
+
});
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
this.clusterIndex.load(this.points);
|
|
223
|
+
}
|
|
224
|
+
getClusterMarker(viewBounds, zoom) {
|
|
225
|
+
const viewBBox = viewBounds[0].concat(viewBounds[1]);
|
|
226
|
+
const clusterPoint = this.clusterIndex.getClusters(viewBBox, zoom);
|
|
227
|
+
this.clusterMarkers.forEach(marker => {
|
|
228
|
+
marker.remove();
|
|
229
|
+
});
|
|
230
|
+
this.clusterMarkers = [];
|
|
231
|
+
clusterPoint.forEach(feature => {
|
|
232
|
+
var _feature$properties;
|
|
233
|
+
const {
|
|
234
|
+
field,
|
|
235
|
+
method
|
|
236
|
+
} = this.markerLayerOption.clusterOption;
|
|
237
|
+
// 处理聚合数据
|
|
238
|
+
if ((_feature$properties = feature.properties) !== null && _feature$properties !== void 0 && _feature$properties.cluster_id) {
|
|
239
|
+
var _feature$properties2;
|
|
240
|
+
const clusterData = this.getLeaves((_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2.cluster_id);
|
|
241
|
+
feature.properties.clusterData = clusterData;
|
|
242
|
+
if (field && method) {
|
|
243
|
+
const columnData = clusterData === null || clusterData === void 0 ? void 0 : clusterData.map(item => {
|
|
244
|
+
const data = {
|
|
245
|
+
[field]: item.properties[field]
|
|
246
|
+
};
|
|
247
|
+
return data;
|
|
248
|
+
});
|
|
249
|
+
const column = Satistics.getColumn(columnData, field);
|
|
250
|
+
const stat = Satistics.getSatByColumn(method, column);
|
|
251
|
+
const fieldName = 'point_' + method;
|
|
252
|
+
feature.properties[fieldName] = stat.toFixed(2);
|
|
253
|
+
}
|
|
305
254
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
element = _ref$element === void 0 ? this.generateElement.bind(this) : _ref$element;
|
|
315
|
-
var marker = new Marker({
|
|
316
|
-
element: element(feature)
|
|
317
|
-
}).setLnglat({
|
|
318
|
-
lng: feature.geometry.coordinates[0],
|
|
319
|
-
lat: feature.geometry.coordinates[1]
|
|
320
|
-
});
|
|
321
|
-
return marker;
|
|
255
|
+
const marker = this.clusterMarker(feature);
|
|
256
|
+
this.clusterMarkers.push(marker);
|
|
257
|
+
marker.addTo(this.scene);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
getLeaves(clusterId, limit = Infinity, offset = 0) {
|
|
261
|
+
if (!clusterId) {
|
|
262
|
+
return null;
|
|
322
263
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
264
|
+
return this.clusterIndex.getLeaves(clusterId, limit, offset);
|
|
265
|
+
}
|
|
266
|
+
clusterMarker(feature) {
|
|
267
|
+
const clusterOption = this.markerLayerOption.clusterOption;
|
|
268
|
+
const {
|
|
269
|
+
element = this.generateElement.bind(this)
|
|
270
|
+
} = clusterOption;
|
|
271
|
+
const marker = new Marker({
|
|
272
|
+
element: element(feature)
|
|
273
|
+
}).setLnglat({
|
|
274
|
+
lng: feature.geometry.coordinates[0],
|
|
275
|
+
lat: feature.geometry.coordinates[1]
|
|
276
|
+
});
|
|
277
|
+
return marker;
|
|
278
|
+
}
|
|
279
|
+
normalMarker(feature) {
|
|
280
|
+
const marker_id = feature.properties.marker_id;
|
|
281
|
+
return this.markers[marker_id];
|
|
282
|
+
}
|
|
283
|
+
update() {
|
|
284
|
+
if (!this.mapsService) {
|
|
285
|
+
return;
|
|
328
286
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (!this.mapsService) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
// 当图层中无marker时,无需更新
|
|
336
|
-
if (this.markers.length === 0) {
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
var zoom = this.mapsService.getZoom();
|
|
340
|
-
var bbox = this.mapsService.getBounds();
|
|
341
|
-
if (!this.bbox || Math.abs(zoom - this.zoom) >= 1 || !boundsContains(this.bbox, bbox)) {
|
|
342
|
-
this.bbox = padBounds(bbox, 0.5);
|
|
343
|
-
this.zoom = Math.floor(zoom);
|
|
344
|
-
this.getClusterMarker(this.bbox, this.zoom);
|
|
345
|
-
}
|
|
287
|
+
// 当图层中无marker时,无需更新
|
|
288
|
+
if (this.markers.length === 0) {
|
|
289
|
+
return;
|
|
346
290
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
var _this$markerLayerOpti4 = this.markerLayerOption.clusterOption,
|
|
354
|
-
field = _this$markerLayerOpti4.field,
|
|
355
|
-
method = _this$markerLayerOpti4.method;
|
|
356
|
-
feature.properties.point_count = feature.properties.point_count || 1;
|
|
357
|
-
var text = field && method ? feature.properties['point_' + method] || feature.properties[field] : feature.properties.point_count;
|
|
358
|
-
span.textContent = text;
|
|
359
|
-
return el;
|
|
291
|
+
const zoom = this.mapsService.getZoom();
|
|
292
|
+
const bbox = this.mapsService.getBounds();
|
|
293
|
+
if (!this.bbox || Math.abs(zoom - this.zoom) >= 1 || !boundsContains(this.bbox, bbox)) {
|
|
294
|
+
this.bbox = padBounds(bbox, 0.5);
|
|
295
|
+
this.zoom = Math.floor(zoom);
|
|
296
|
+
this.getClusterMarker(this.bbox, this.zoom);
|
|
360
297
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
298
|
+
}
|
|
299
|
+
generateElement(feature) {
|
|
300
|
+
const el = DOM.create('div', 'l7-marker-cluster');
|
|
301
|
+
const label = DOM.create('div', '', el);
|
|
302
|
+
const span = DOM.create('span', '', label);
|
|
303
|
+
const {
|
|
304
|
+
field,
|
|
305
|
+
method
|
|
306
|
+
} = this.markerLayerOption.clusterOption;
|
|
307
|
+
feature.properties.point_count = feature.properties.point_count || 1;
|
|
308
|
+
const text = field && method ? feature.properties['point_' + method] || feature.properties[field] : feature.properties.point_count;
|
|
309
|
+
span.textContent = text;
|
|
310
|
+
return el;
|
|
311
|
+
}
|
|
312
|
+
}
|
package/es/marker.d.ts
CHANGED
|
@@ -3,10 +3,8 @@ import { anchorType } from '@antv/l7-utils';
|
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
export default class Marker extends EventEmitter {
|
|
5
5
|
private markerOption;
|
|
6
|
-
private defaultMarker;
|
|
7
6
|
private popup;
|
|
8
7
|
private mapsService;
|
|
9
|
-
private sceneSerive;
|
|
10
8
|
private lngLat;
|
|
11
9
|
private scene;
|
|
12
10
|
private added;
|