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