@antv/l7-component 2.21.1 → 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 -389
- 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 +275 -326
- package/es/marker.js +394 -446
- 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 -388
- 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 +277 -324
- package/lib/marker.d.ts +58 -0
- package/lib/marker.js +395 -445
- 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,363 +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
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.addMarkers();
|
|
69
|
-
this.inited = true;
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
72
46
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
bounds: this.mapsService.getBounds()
|
|
85
|
-
};
|
|
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 更新事件
|
|
86
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
|
+
}
|
|
87
65
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.containerSize;
|
|
66
|
+
// 设置容器大小
|
|
67
|
+
setContainerSize() {
|
|
68
|
+
if (!this.mapsService) {
|
|
69
|
+
return;
|
|
93
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
|
+
}
|
|
94
78
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
79
|
+
// 获取容器尺寸
|
|
80
|
+
getContainerSize() {
|
|
81
|
+
return this.containerSize;
|
|
82
|
+
}
|
|
83
|
+
|
|
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);
|
|
111
97
|
}
|
|
112
|
-
this.markers.push(marker);
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
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);
|
|
126
110
|
}
|
|
127
111
|
}
|
|
128
112
|
}
|
|
113
|
+
}
|
|
129
114
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
}
|
|
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
|
+
}
|
|
143
126
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
}
|
|
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
|
+
}
|
|
157
138
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
key: "getOriginMarkers",
|
|
167
|
-
value: function getOriginMarkers() {
|
|
168
|
-
return this.markers;
|
|
169
|
-
}
|
|
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
|
+
}
|
|
170
147
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
marker.addTo(_this2.scene);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
148
|
+
// 批量添加marker到scene
|
|
149
|
+
addMarkers() {
|
|
150
|
+
this.getMarkers().forEach(marker => {
|
|
151
|
+
marker.addTo(this.scene);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
180
154
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.mapsService.off('viewchange', this.update);
|
|
202
|
-
this.mapsService.off('camerachange', this.setContainerSize.bind(this));
|
|
203
|
-
this.mapsService.off('viewchange', this.setContainerSize.bind(this));
|
|
204
|
-
}
|
|
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
|
+
}
|
|
205
175
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.clusterIndex.load(this.points);
|
|
226
|
-
}
|
|
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);
|
|
227
195
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
if (targetIndex > -1) {
|
|
235
|
-
this.points.splice(targetIndex, 1);
|
|
236
|
-
}
|
|
237
|
-
if (this.clusterIndex) {
|
|
238
|
-
// 在删除点的时候需要更新 cluster 的数据
|
|
239
|
-
this.clusterIndex.load(this.points);
|
|
240
|
-
}
|
|
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);
|
|
241
201
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
value: function initCluster() {
|
|
245
|
-
if (!this.markerLayerOption.cluster) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
var _this$markerLayerOpti2 = this.markerLayerOption.clusterOption,
|
|
249
|
-
radius = _this$markerLayerOpti2.radius,
|
|
250
|
-
_this$markerLayerOpti3 = _this$markerLayerOpti2.minZoom,
|
|
251
|
-
minZoom = _this$markerLayerOpti3 === void 0 ? 0 : _this$markerLayerOpti3,
|
|
252
|
-
maxZoom = _this$markerLayerOpti2.maxZoom;
|
|
253
|
-
this.clusterIndex = new Supercluster({
|
|
254
|
-
radius: radius,
|
|
255
|
-
minZoom: minZoom,
|
|
256
|
-
maxZoom: maxZoom
|
|
257
|
-
});
|
|
258
|
-
// @ts-ignore
|
|
202
|
+
if (this.clusterIndex) {
|
|
203
|
+
// 在删除点的时候需要更新 cluster 的数据
|
|
259
204
|
this.clusterIndex.load(this.points);
|
|
260
205
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
var viewBBox = viewBounds[0].concat(viewBounds[1]);
|
|
266
|
-
var clusterPoint = this.clusterIndex.getClusters(viewBBox, zoom);
|
|
267
|
-
this.clusterMarkers.forEach(function (marker) {
|
|
268
|
-
marker.remove();
|
|
269
|
-
});
|
|
270
|
-
this.clusterMarkers = [];
|
|
271
|
-
clusterPoint.forEach(function (feature) {
|
|
272
|
-
var _feature$properties;
|
|
273
|
-
var _this3$markerLayerOpt = _this3.markerLayerOption.clusterOption,
|
|
274
|
-
field = _this3$markerLayerOpt.field,
|
|
275
|
-
method = _this3$markerLayerOpt.method;
|
|
276
|
-
// 处理聚合数据
|
|
277
|
-
if ((_feature$properties = feature.properties) !== null && _feature$properties !== void 0 && _feature$properties.cluster_id) {
|
|
278
|
-
var _feature$properties2;
|
|
279
|
-
var clusterData = _this3.getLeaves((_feature$properties2 = feature.properties) === null || _feature$properties2 === void 0 ? void 0 : _feature$properties2.cluster_id);
|
|
280
|
-
feature.properties.clusterData = clusterData;
|
|
281
|
-
if (field && method) {
|
|
282
|
-
var columnData = clusterData === null || clusterData === void 0 ? void 0 : clusterData.map(function (item) {
|
|
283
|
-
var data = _defineProperty({}, field, item.properties[field]);
|
|
284
|
-
return data;
|
|
285
|
-
});
|
|
286
|
-
var column = Satistics.getColumn(columnData, field);
|
|
287
|
-
var stat = Satistics.getSatByColumn(method, column);
|
|
288
|
-
var fieldName = 'point_' + method;
|
|
289
|
-
feature.properties[fieldName] = stat.toFixed(2);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
var marker = _this3.clusterMarker(feature);
|
|
293
|
-
_this3.clusterMarkers.push(marker);
|
|
294
|
-
marker.addTo(_this3.scene);
|
|
295
|
-
});
|
|
206
|
+
}
|
|
207
|
+
initCluster() {
|
|
208
|
+
if (!this.markerLayerOption.cluster) {
|
|
209
|
+
return;
|
|
296
210
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
+
}
|
|
304
254
|
}
|
|
305
|
-
|
|
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;
|
|
306
263
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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;
|
|
321
286
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
var marker_id = feature.properties.marker_id;
|
|
326
|
-
return this.markers[marker_id];
|
|
287
|
+
// 当图层中无marker时,无需更新
|
|
288
|
+
if (this.markers.length === 0) {
|
|
289
|
+
return;
|
|
327
290
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
// 当图层中无marker时,无需更新
|
|
335
|
-
if (this.markers.length === 0) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
var zoom = this.mapsService.getZoom();
|
|
339
|
-
var bbox = this.mapsService.getBounds();
|
|
340
|
-
if (!this.bbox || Math.abs(zoom - this.zoom) >= 1 || !boundsContains(this.bbox, bbox)) {
|
|
341
|
-
this.bbox = padBounds(bbox, 0.5);
|
|
342
|
-
this.zoom = Math.floor(zoom);
|
|
343
|
-
this.getClusterMarker(this.bbox, this.zoom);
|
|
344
|
-
}
|
|
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);
|
|
345
297
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return MarkerLayer;
|
|
362
|
-
}(EventEmitter);
|
|
363
|
-
export { MarkerLayer as default };
|
|
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
|
+
}
|