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