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