@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.
Files changed (82) hide show
  1. package/es/assets/iconfont/iconfont.js +6 -6
  2. package/es/constants/index.js +2 -2
  3. package/es/control/baseControl/buttonControl.js +109 -144
  4. package/es/control/baseControl/control.js +212 -258
  5. package/es/control/baseControl/popperControl.js +67 -95
  6. package/es/control/baseControl/selectControl.js +132 -178
  7. package/es/control/exportImage.js +59 -142
  8. package/es/control/fullscreen.js +69 -100
  9. package/es/control/geoLocate.js +37 -84
  10. package/es/control/layerSwitch.js +111 -154
  11. package/es/control/logo.js +43 -69
  12. package/es/control/mapTheme.js +57 -98
  13. package/es/control/mouseLocation.js +37 -69
  14. package/es/control/scale.js +107 -135
  15. package/es/control/swipe.js +297 -389
  16. package/es/control/zoom.js +80 -112
  17. package/es/css/index.css +10 -7
  18. package/es/index.js +667 -1
  19. package/es/marker-layer.js +275 -326
  20. package/es/marker.js +394 -446
  21. package/es/popup/layerPopup.js +277 -321
  22. package/es/popup/popup.js +422 -482
  23. package/es/utils/anchor.js +6 -6
  24. package/es/utils/icon.js +4 -4
  25. package/es/utils/popper.js +180 -196
  26. package/es/utils/screenfull.js +29 -51
  27. package/lib/assets/iconfont/iconfont.js +6 -6
  28. package/lib/constants/index.d.ts +60 -0
  29. package/lib/constants/index.js +2 -2
  30. package/lib/control/baseControl/buttonControl.d.ts +60 -0
  31. package/lib/control/baseControl/buttonControl.js +110 -143
  32. package/lib/control/baseControl/control.d.ts +112 -0
  33. package/lib/control/baseControl/control.js +213 -257
  34. package/lib/control/baseControl/index.d.ts +4 -0
  35. package/lib/control/baseControl/index.js +5 -5
  36. package/lib/control/baseControl/popperControl.d.ts +28 -0
  37. package/lib/control/baseControl/popperControl.js +68 -94
  38. package/lib/control/baseControl/selectControl.d.ts +53 -0
  39. package/lib/control/baseControl/selectControl.js +133 -177
  40. package/lib/control/exportImage.d.ts +19 -0
  41. package/lib/control/exportImage.js +60 -141
  42. package/lib/control/fullscreen.d.ts +20 -0
  43. package/lib/control/fullscreen.js +70 -99
  44. package/lib/control/geoLocate.d.ts +17 -0
  45. package/lib/control/geoLocate.js +38 -83
  46. package/lib/control/layerSwitch.d.ts +27 -0
  47. package/lib/control/layerSwitch.js +112 -153
  48. package/lib/control/logo.d.ts +14 -0
  49. package/lib/control/logo.js +44 -69
  50. package/lib/control/mapTheme.d.ts +11 -0
  51. package/lib/control/mapTheme.js +58 -97
  52. package/lib/control/mouseLocation.d.ts +16 -0
  53. package/lib/control/mouseLocation.js +38 -68
  54. package/lib/control/scale.d.ts +35 -0
  55. package/lib/control/scale.js +108 -134
  56. package/lib/control/swipe.d.ts +66 -0
  57. package/lib/control/swipe.js +298 -388
  58. package/lib/control/zoom.d.ts +39 -0
  59. package/lib/control/zoom.js +81 -111
  60. package/lib/css/index.css +10 -7
  61. package/lib/index.d.ts +19 -0
  62. package/lib/index.js +683 -17
  63. package/lib/interface.d.ts +18 -0
  64. package/lib/marker-layer.d.ts +55 -0
  65. package/lib/marker-layer.js +277 -324
  66. package/lib/marker.d.ts +58 -0
  67. package/lib/marker.js +395 -445
  68. package/lib/popup/layerPopup.d.ts +99 -0
  69. package/lib/popup/layerPopup.js +278 -320
  70. package/lib/popup/popup.d.ts +142 -0
  71. package/lib/popup/popup.js +423 -481
  72. package/lib/utils/anchor.d.ts +22 -0
  73. package/lib/utils/anchor.js +6 -6
  74. package/lib/utils/icon.d.ts +1 -0
  75. package/lib/utils/icon.js +6 -5
  76. package/lib/utils/popper.d.ts +76 -0
  77. package/lib/utils/popper.js +184 -196
  78. package/lib/utils/screenfull.d.ts +2 -0
  79. package/lib/utils/screenfull.js +29 -52
  80. package/package.json +16 -20
  81. package/CHANGELOG.md +0 -325
  82. package/LICENSE.md +0 -21
@@ -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
- var merge = lodashUtil.merge;
18
- var MarkerLayer = /*#__PURE__*/function (_EventEmitter) {
19
- _inherits(MarkerLayer, _EventEmitter);
20
- var _super = _createSuper(MarkerLayer);
21
- // 聚合后的marker列表
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
- var _this;
26
- _classCallCheck(this, MarkerLayer);
27
- _this = _super.call(this);
28
- _defineProperty(_assertThisInitialized(_this), "markers", []);
29
- _defineProperty(_assertThisInitialized(_this), "points", []);
30
- _defineProperty(_assertThisInitialized(_this), "clusterMarkers", []);
31
- _this.markerLayerOption = merge(_this.getDefault(), option);
32
- bindAll(['update'], _assertThisInitialized(_this));
33
- _this.zoom = ((_this$markerLayerOpti = _this.markerLayerOption.clusterOption) === null || _this$markerLayerOpti === void 0 ? void 0 : _this$markerLayerOpti.zoom) || -99;
34
- return _this;
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
- _createClass(MarkerLayer, [{
37
- key: "getDefault",
38
- value: function getDefault() {
39
- return {
40
- cluster: false,
41
- clusterOption: {
42
- radius: 80,
43
- maxZoom: 20,
44
- minZoom: 0,
45
- zoom: -99,
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
- this.mapsService.on('camerachange', this.setContainerSize.bind(this)); // amap1.x 更新事件
67
- this.mapsService.on('viewchange', this.setContainerSize.bind(this)); // amap2.0 更新事件
68
- this.addMarkers();
69
- this.inited = true;
70
- return this;
71
- }
44
+ };
45
+ }
72
46
 
73
- // 设置容器大小
74
- }, {
75
- key: "setContainerSize",
76
- value: function setContainerSize() {
77
- if (!this.mapsService) {
78
- return;
79
- }
80
- var container = this.mapsService.getContainer();
81
- this.containerSize = {
82
- containerWidth: (container === null || container === void 0 ? void 0 : container.scrollWidth) || 0,
83
- containerHeight: (container === null || container === void 0 ? void 0 : container.scrollHeight) || 0,
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
- key: "getContainerSize",
91
- value: function getContainerSize() {
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
- // 在图层添加单个marker
96
- }, {
97
- key: "addMarker",
98
- value: function addMarker(marker) {
99
- var cluster = this.markerLayerOption.cluster;
100
- marker.getMarkerLayerContainerSize = this.getContainerSize.bind(this);
101
- if (cluster) {
102
- this.addPoint(marker, this.markers.length);
103
- if (this.mapsService) {
104
- // 在新增 marker 的时候需要更新聚合信息(哪怕此时的 zoom 没有发生变化)
105
- var zoom = this.mapsService.getZoom();
106
- var bbox = this.mapsService.getBounds();
107
- this.bbox = padBounds(bbox, 0.5);
108
- this.zoom = Math.floor(zoom);
109
- this.getClusterMarker(this.bbox, this.zoom);
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
- key: "removeMarker",
116
- value: function removeMarker(marker) {
117
- this.markers.indexOf(marker);
118
- var markerIndex = this.markers.indexOf(marker);
119
- if (markerIndex > -1) {
120
- this.markers.splice(markerIndex, 1);
121
- if (this.markerLayerOption.cluster) {
122
- this.removePoint(markerIndex);
123
- if (this.mapsService) {
124
- this.getClusterMarker(this.bbox, this.zoom);
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
- * 隐藏 marker 在每个 marker 上单独修改属性而不是在 markerContainer 上修改(在 markerContainer 修改会有用户在场景加载完之前调用失败的问题)
132
- */
133
- }, {
134
- key: "hide",
135
- value: function hide() {
136
- this.markers.map(function (m) {
137
- m.getElement().style.opacity = '0';
138
- });
139
- this.clusterMarkers.map(function (m) {
140
- m.getElement().style.opacity = '0';
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
- * 显示 marker
146
- */
147
- }, {
148
- key: "show",
149
- value: function show() {
150
- this.markers.map(function (m) {
151
- m.getElement().style.opacity = '1';
152
- });
153
- this.clusterMarkers.map(function (m) {
154
- m.getElement().style.opacity = '1';
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
- // 返回当下的markers数据,有聚合图时返回聚合的marker列表,否则返回原始maerker列表
159
- }, {
160
- key: "getMarkers",
161
- value: function getMarkers() {
162
- var cluster = this.markerLayerOption.cluster;
163
- return cluster ? this.clusterMarkers : this.markers;
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
- // 批量添加marker到scene
172
- }, {
173
- key: "addMarkers",
174
- value: function addMarkers() {
175
- var _this2 = this;
176
- this.getMarkers().forEach(function (marker) {
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
- // 清除图层里的marker
182
- }, {
183
- key: "clear",
184
- value: function clear() {
185
- this.markers.forEach(function (marker) {
186
- marker.remove();
187
- });
188
- this.clusterMarkers.forEach(function (clusterMarker) {
189
- clusterMarker.remove();
190
- });
191
- this.markers = [];
192
- this.points = [];
193
- this.clusterMarkers = [];
194
- }
195
- }, {
196
- key: "destroy",
197
- value: function destroy() {
198
- this.clear();
199
- this.removeAllListeners();
200
- this.mapsService.off('camerachange', this.update);
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
- // 将marker数据保存在point中
207
- }, {
208
- key: "addPoint",
209
- value: function addPoint(marker, id) {
210
- var _marker$getLnglat = marker.getLnglat(),
211
- lng = _marker$getLnglat.lng,
212
- lat = _marker$getLnglat.lat;
213
- var feature = {
214
- geometry: {
215
- type: 'Point',
216
- coordinates: [lng, lat]
217
- },
218
- properties: _objectSpread(_objectSpread({}, marker.getExtData()), {}, {
219
- marker_id: id
220
- })
221
- };
222
- this.points.push(feature);
223
- if (this.clusterIndex) {
224
- // 在新增点的时候需要更新 cluster 的数据
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
- key: "removePoint",
230
- value: function removePoint(id) {
231
- var targetIndex = this.points.findIndex(function (point) {
232
- return point.properties.marker_id === id;
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
- key: "initCluster",
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
- key: "getClusterMarker",
263
- value: function getClusterMarker(viewBounds, zoom) {
264
- var _this3 = this;
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
- key: "getLeaves",
299
- value: function getLeaves(clusterId) {
300
- var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
301
- var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
302
- if (!clusterId) {
303
- return null;
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
- return this.clusterIndex.getLeaves(clusterId, limit, offset);
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
- key: "clusterMarker",
309
- value: function clusterMarker(feature) {
310
- var clusterOption = this.markerLayerOption.clusterOption;
311
- var _ref = clusterOption,
312
- _ref$element = _ref.element,
313
- element = _ref$element === void 0 ? this.generateElement.bind(this) : _ref$element;
314
- var marker = new Marker({
315
- element: element(feature)
316
- }).setLnglat({
317
- lng: feature.geometry.coordinates[0],
318
- lat: feature.geometry.coordinates[1]
319
- });
320
- return marker;
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
- key: "normalMarker",
324
- value: function normalMarker(feature) {
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
- key: "update",
330
- value: function update() {
331
- if (!this.mapsService) {
332
- return;
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
- key: "generateElement",
348
- value: function generateElement(feature) {
349
- var el = DOM.create('div', 'l7-marker-cluster');
350
- var label = DOM.create('div', '', el);
351
- var span = DOM.create('span', '', label);
352
- var _this$markerLayerOpti4 = this.markerLayerOption.clusterOption,
353
- field = _this$markerLayerOpti4.field,
354
- method = _this$markerLayerOpti4.method;
355
- feature.properties.point_count = feature.properties.point_count || 1;
356
- var text = field && method ? feature.properties['point_' + method] || feature.properties[field] : feature.properties.point_count;
357
- span.textContent = text;
358
- return el;
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
+ }