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