hy-dispatch-ui-v3 0.2.53 → 0.2.54

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 (116) hide show
  1. package/dist/tailwind.css +53 -0
  2. package/es/components/hyBatchUploadDialog/batchUploadDialog.vue.mjs +39 -10
  3. package/es/components/hyConfirmDialog/confirmDialog.vue.mjs +12 -22
  4. package/es/components/hyDialog/dialog.vue.mjs +9 -7
  5. package/es/components/hyForm/cpns/arrayItem.vue.mjs +5 -5
  6. package/es/components/hyForm/cpns/extraItem.vue.mjs +6 -1
  7. package/es/components/hyForm/cpns/formItem.vue.mjs +29 -14
  8. package/es/components/hyForm/js/index.mjs +29 -25
  9. package/es/components/hyForm/js/useAppForm.mjs +15 -30
  10. package/es/components/hyIconBox/iconBox.vue.mjs +1 -1
  11. package/es/components/hyIconBox/style/iconBox.scss +1 -1
  12. package/es/components/hyMap/index.mjs +6 -0
  13. package/es/components/hyMap/js/index.mjs +59 -0
  14. package/es/components/hyMap/map.vue.mjs +59 -0
  15. package/es/components/hyOrgCascader/js/index.mjs +53 -0
  16. package/es/components/hyOrgCascader/orgCascader.vue.mjs +22 -25
  17. package/es/components/hySearch/search.vue.mjs +6 -8
  18. package/es/components/hyTable/cpns/columnSelect.vue.mjs +10 -18
  19. package/es/components/hyTable/table.vue.mjs +8 -11
  20. package/es/components/hyTableActionButton/tableActionButton.vue.mjs +6 -3
  21. package/es/components/hyTableForm/batchTableForm.vue.mjs +182 -135
  22. package/es/components/hyTableForm/js/index.mjs +2 -2
  23. package/es/components/hyTableForm/tableForm.vue.mjs +29 -20
  24. package/es/components/hyTooltip/tooltip.vue.mjs +1 -1
  25. package/es/components/hyTree/js/index.mjs +5 -4
  26. package/es/components/hyTree/tree.vue.mjs +5 -0
  27. package/es/components/index.mjs +1 -0
  28. package/es/hooks/index.mjs +1 -0
  29. package/es/hooks/useApi.mjs +11 -5
  30. package/es/hooks/useAudioPlayerConfig.mjs +13 -5
  31. package/es/hooks/useEnsureHyIcon.mjs +11 -5
  32. package/es/hooks/useLocale.mjs +6 -5
  33. package/es/hooks/usePermissionMap.mjs +13 -5
  34. package/es/hooks/useSubscribe.mjs +28 -0
  35. package/es/hooks/useTooltipConfig.mjs +11 -5
  36. package/es/hooks/useUserAvatarMap.mjs +13 -5
  37. package/es/hooks/useVideoPlayerConfig.mjs +13 -5
  38. package/es/index.mjs +3 -2
  39. package/es/static/map/CFCASIPInput.min.js +258 -0
  40. package/es/static/map/MarkerCluster.css +75 -0
  41. package/es/static/map/bigemap.css +838 -0
  42. package/es/static/map/bigemap.js +5 -0
  43. package/es/static/map/bm.geometryutil.js +754 -0
  44. package/es/static/map/bmDraw.css +329 -0
  45. package/es/static/map/bmDraw.js +181 -0
  46. package/es/static/map/car.png +0 -0
  47. package/es/static/map/markercluster.js +2679 -0
  48. package/es/static/map/moveMarker.js +74 -0
  49. package/es/utils/form.mjs +38 -2
  50. package/es/utils/index.mjs +1 -2
  51. package/es/utils/map/hook/bigMap.mjs +1136 -0
  52. package/es/utils/map/hook/gaode.mjs +683 -0
  53. package/es/utils/map/hook/leafletjs.mjs +1336 -0
  54. package/es/utils/map/index.mjs +291 -0
  55. package/es/utils/map/js/mapProxy.mjs +38 -0
  56. package/es/utils/map/js/webgis.mjs +153 -0
  57. package/es/version.mjs +1 -1
  58. package/lib/components/hyBatchUploadDialog/batchUploadDialog.vue.js +40 -11
  59. package/lib/components/hyConfirmDialog/confirmDialog.vue.js +13 -23
  60. package/lib/components/hyDialog/dialog.vue.js +9 -7
  61. package/lib/components/hyForm/cpns/arrayItem.vue.js +4 -4
  62. package/lib/components/hyForm/cpns/extraItem.vue.js +6 -1
  63. package/lib/components/hyForm/cpns/formItem.vue.js +26 -11
  64. package/lib/components/hyForm/js/index.js +29 -23
  65. package/lib/components/hyForm/js/useAppForm.js +14 -29
  66. package/lib/components/hyIconBox/iconBox.vue.js +1 -1
  67. package/lib/components/hyIconBox/style/iconBox.scss +1 -1
  68. package/lib/components/hyMap/index.js +11 -0
  69. package/lib/components/hyMap/js/index.js +61 -0
  70. package/lib/components/hyMap/map.vue.js +63 -0
  71. package/lib/components/hyOrgCascader/js/index.js +56 -0
  72. package/lib/components/hyOrgCascader/orgCascader.vue.js +21 -24
  73. package/lib/components/hySearch/search.vue.js +4 -6
  74. package/lib/components/hyTable/cpns/columnSelect.vue.js +12 -20
  75. package/lib/components/hyTable/table.vue.js +17 -20
  76. package/lib/components/hyTableActionButton/tableActionButton.vue.js +5 -2
  77. package/lib/components/hyTableForm/batchTableForm.vue.js +181 -134
  78. package/lib/components/hyTableForm/js/index.js +1 -1
  79. package/lib/components/hyTableForm/tableForm.vue.js +29 -20
  80. package/lib/components/hyTooltip/tooltip.vue.js +1 -1
  81. package/lib/components/hyTree/js/index.js +5 -4
  82. package/lib/components/hyTree/tree.vue.js +5 -0
  83. package/lib/components/index.js +22 -20
  84. package/lib/hooks/index.js +3 -0
  85. package/lib/hooks/useApi.js +10 -4
  86. package/lib/hooks/useAudioPlayerConfig.js +12 -4
  87. package/lib/hooks/useEnsureHyIcon.js +10 -4
  88. package/lib/hooks/useLocale.js +5 -4
  89. package/lib/hooks/usePermissionMap.js +12 -4
  90. package/lib/hooks/useSubscribe.js +31 -0
  91. package/lib/hooks/useTooltipConfig.js +10 -4
  92. package/lib/hooks/useUserAvatarMap.js +12 -4
  93. package/lib/hooks/useVideoPlayerConfig.js +12 -4
  94. package/lib/index.js +27 -22
  95. package/lib/static/map/CFCASIPInput.min.js +258 -0
  96. package/lib/static/map/MarkerCluster.css +75 -0
  97. package/lib/static/map/bigemap.css +838 -0
  98. package/lib/static/map/bigemap.js +5 -0
  99. package/lib/static/map/bm.geometryutil.js +754 -0
  100. package/lib/static/map/bmDraw.css +329 -0
  101. package/lib/static/map/bmDraw.js +181 -0
  102. package/lib/static/map/car.png +0 -0
  103. package/lib/static/map/markercluster.js +2679 -0
  104. package/lib/static/map/moveMarker.js +74 -0
  105. package/lib/utils/form.js +38 -0
  106. package/lib/utils/index.js +2 -2
  107. package/lib/utils/map/hook/bigMap.js +1140 -0
  108. package/lib/utils/map/hook/gaode.js +687 -0
  109. package/lib/utils/map/hook/leafletjs.js +1360 -0
  110. package/lib/utils/map/index.js +298 -0
  111. package/lib/utils/map/js/mapProxy.js +44 -0
  112. package/lib/utils/map/js/webgis.js +162 -0
  113. package/lib/version.js +1 -1
  114. package/package.json +16 -1
  115. package/es/utils/bus.mjs +0 -5
  116. package/lib/utils/bus.js +0 -7
@@ -0,0 +1,2679 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (factory((global.Leaflet = global.Leaflet || {}, global.Leaflet.markercluster = global.Leaflet.markercluster || {})));
5
+ }(this, (function (exports) { 'use strict';
6
+ var MarkerClusterGroup = BM.MarkerClusterGroup = BM.FeatureGroup.extend({
7
+
8
+ options: {
9
+ maxClusterRadius: 80, //A cluster will cover at most this many pixels from its center
10
+ iconCreateFunction: null,
11
+ clusterPane: BM.Marker.prototype.options.pane,
12
+
13
+ spiderfyOnMaxZoom: true,
14
+ showCoverageOnHover: true,
15
+ zoomToBoundsOnClick: true,
16
+ singleMarkerMode: false,
17
+
18
+ disableClusteringAtZoom: null,
19
+
20
+ // Setting this to false prevents the removal of any clusters outside of the viewpoint, which
21
+ // is the default behaviour for performance reasons.
22
+ removeOutsideVisibleBounds: true,
23
+
24
+ // Set to false to disable all animations (zoom and spiderfy).
25
+ // If false, option animateAddingMarkers below has no effect.
26
+ // If BM.DomUtil.TRANSITION is falsy, this option has no effect.
27
+ animate: true,
28
+
29
+ //Whether to animate adding markers after adding the MarkerClusterGroup to the map
30
+ // If you are adding individual markers set to true, if adding bulk markers leave false for massive performance gains.
31
+ animateAddingMarkers: false,
32
+
33
+ //Increase to increase the distance away that spiderfied markers appear from the center
34
+ spiderfyDistanceMultiplier: 1,
35
+
36
+ // Make it possible to specify a polyline options on a spider leg
37
+ spiderLegPolylineOptions: { weight: 1.5, color: '#222', opacity: 0.5 },
38
+
39
+ // When bulk adding layers, adds markers in chunks. Means addLayers may not add all the layers in the call, others will be loaded during setTimeouts
40
+ chunkedLoading: false,
41
+ chunkInterval: 200, // process markers for a maximum of ~ n milliseconds (then trigger the chunkProgress callback)
42
+ chunkDelay: 50, // at the end of each interval, give n milliseconds back to system/browser
43
+ chunkProgress: null, // progress callback: function(processed, total, elapsed) (e.g. for a progress indicator)
44
+
45
+ //Options to pass to the BM.Polygon constructor
46
+ polygonOptions: {}
47
+ },
48
+
49
+ initialize: function (options) {
50
+ BM.Util.setOptions(this, options);
51
+ if (!this.options.iconCreateFunction) {
52
+ this.options.iconCreateFunction = this._defaultIconCreateFunction;
53
+ }
54
+
55
+ this._featureGroup = BM.featureGroup();
56
+ this._featureGroup.addEventParent(this);
57
+
58
+ this._nonPointGroup = BM.featureGroup();
59
+ this._nonPointGroup.addEventParent(this);
60
+
61
+ this._inZoomAnimation = 0;
62
+ this._needsClustering = [];
63
+ this._needsRemoving = []; //Markers removed while we aren't on the map need to be kept track of
64
+ //The bounds of the currently shown area (from _getExpandedVisibleBounds) Updated on zoom/move
65
+ this._currentShownBounds = null;
66
+
67
+ this._queue = [];
68
+
69
+ this._childMarkerEventHandlers = {
70
+ 'dragstart': this._childMarkerDragStart,
71
+ 'move': this._childMarkerMoved,
72
+ 'dragend': this._childMarkerDragEnd,
73
+ };
74
+
75
+ // Hook the appropriate animation methods.
76
+ var animate = BM.DomUtil.TRANSITION && this.options.animate;
77
+ BM.extend(this, animate ? this._withAnimation : this._noAnimation);
78
+ // Remember which MarkerCluster class to instantiate (animated or not).
79
+ this._markerCluster = animate ? BM.MarkerCluster : BM.MarkerClusterNonAnimated;
80
+ },
81
+
82
+ addLayer: function (layer) {
83
+
84
+ if (layer instanceof BM.LayerGroup) {
85
+ return this.addLayers([layer]);
86
+ }
87
+
88
+ //Don't cluster non point data
89
+ if (!layer.getLatLng) {
90
+ this._nonPointGroup.addLayer(layer);
91
+ this.fire('layeradd', { layer: layer });
92
+ return this;
93
+ }
94
+
95
+ if (!this._map) {
96
+ this._needsClustering.push(layer);
97
+ this.fire('layeradd', { layer: layer });
98
+ return this;
99
+ }
100
+
101
+ if (this.hasLayer(layer)) {
102
+ return this;
103
+ }
104
+
105
+
106
+ //If we have already clustered we'll need to add this one to a cluster
107
+
108
+ if (this._unspiderfy) {
109
+ this._unspiderfy();
110
+ }
111
+
112
+ this._addLayer(layer, this._maxZoom);
113
+ this.fire('layeradd', { layer: layer });
114
+
115
+ // Refresh bounds and weighted positions.
116
+ this._topClusterLevel._recalculateBounds();
117
+
118
+ this._refreshClustersIcons();
119
+
120
+ //Work out what is visible
121
+ var visibleLayer = layer,
122
+ currentZoom = this._zoom;
123
+ if (layer.__parent) {
124
+ while (visibleLayer.__parent._zoom >= currentZoom) {
125
+ visibleLayer = visibleLayer.__parent;
126
+ }
127
+ }
128
+
129
+ if (this._currentShownBounds.contains(visibleLayer.getLatLng())) {
130
+ if (this.options.animateAddingMarkers) {
131
+ this._animationAddLayer(layer, visibleLayer);
132
+ } else {
133
+ this._animationAddLayerNonAnimated(layer, visibleLayer);
134
+ }
135
+ }
136
+ return this;
137
+ },
138
+
139
+ removeLayer: function (layer) {
140
+
141
+ if (layer instanceof BM.LayerGroup) {
142
+ return this.removeLayers([layer]);
143
+ }
144
+
145
+ //Non point layers
146
+ if (!layer.getLatLng) {
147
+ this._nonPointGroup.removeLayer(layer);
148
+ this.fire('layerremove', { layer: layer });
149
+ return this;
150
+ }
151
+
152
+ if (!this._map) {
153
+ if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) {
154
+ this._needsRemoving.push({ layer: layer, latlng: layer._latlng });
155
+ }
156
+ this.fire('layerremove', { layer: layer });
157
+ return this;
158
+ }
159
+
160
+ if (!layer.__parent) {
161
+ return this;
162
+ }
163
+
164
+ if (this._unspiderfy) {
165
+ this._unspiderfy();
166
+ this._unspiderfyLayer(layer);
167
+ }
168
+
169
+ //Remove the marker from clusters
170
+ this._removeLayer(layer, true);
171
+ this.fire('layerremove', { layer: layer });
172
+
173
+ // Refresh bounds and weighted positions.
174
+ this._topClusterLevel._recalculateBounds();
175
+
176
+ this._refreshClustersIcons();
177
+
178
+ layer.off(this._childMarkerEventHandlers, this);
179
+
180
+ if (this._featureGroup.hasLayer(layer)) {
181
+ this._featureGroup.removeLayer(layer);
182
+ if (layer.clusterShow) {
183
+ layer.clusterShow();
184
+ }
185
+ }
186
+
187
+ return this;
188
+ },
189
+
190
+ //Takes an array of markers and adds them in bulk
191
+ addLayers: function (layersArray, skipLayerAddEvent) {
192
+ if (!BM.Util.isArray(layersArray)) {
193
+ return this.addLayer(layersArray);
194
+ }
195
+
196
+ var fg = this._featureGroup,
197
+ npg = this._nonPointGroup,
198
+ chunked = this.options.chunkedLoading,
199
+ chunkInterval = this.options.chunkInterval,
200
+ chunkProgress = this.options.chunkProgress,
201
+ l = layersArray.length,
202
+ offset = 0,
203
+ originalArray = true,
204
+ m;
205
+
206
+ if (this._map) {
207
+ var started = (new Date()).getTime();
208
+ var process = BM.bind(function () {
209
+ var start = (new Date()).getTime();
210
+ for (; offset < l; offset++) {
211
+ if (chunked && offset % 200 === 0) {
212
+ // every couple hundred markers, instrument the time elapsed since processing started:
213
+ var elapsed = (new Date()).getTime() - start;
214
+ if (elapsed > chunkInterval) {
215
+ break; // been working too hard, time to take a break :-)
216
+ }
217
+ }
218
+
219
+ m = layersArray[offset];
220
+
221
+ // Group of layers, append children to layersArray and skip.
222
+ // Side effects:
223
+ // - Total increases, so chunkProgress ratio jumps backward.
224
+ // - Groups are not included in this group, only their non-group child layers (hasLayer).
225
+ // Changing array length while looping does not affect performance in current browsers:
226
+ // http://jsperf.com/for-loop-changing-length/6
227
+ if (m instanceof BM.LayerGroup) {
228
+ if (originalArray) {
229
+ layersArray = layersArray.slice();
230
+ originalArray = false;
231
+ }
232
+ this._extractNonGroupLayers(m, layersArray);
233
+ l = layersArray.length;
234
+ continue;
235
+ }
236
+
237
+ //Not point data, can't be clustered
238
+ if (!m.getLatLng) {
239
+ npg.addLayer(m);
240
+ if (!skipLayerAddEvent) {
241
+ this.fire('layeradd', { layer: m });
242
+ }
243
+ continue;
244
+ }
245
+
246
+ if (this.hasLayer(m)) {
247
+ continue;
248
+ }
249
+
250
+ this._addLayer(m, this._maxZoom);
251
+ if (!skipLayerAddEvent) {
252
+ this.fire('layeradd', { layer: m });
253
+ }
254
+
255
+ //If we just made a cluster of size 2 then we need to remove the other marker from the map (if it is) or we never will
256
+ if (m.__parent) {
257
+ if (m.__parent.getChildCount() === 2) {
258
+ var markers = m.__parent.getAllChildMarkers(),
259
+ otherMarker = markers[0] === m ? markers[1] : markers[0];
260
+ fg.removeLayer(otherMarker);
261
+ }
262
+ }
263
+ }
264
+
265
+ if (chunkProgress) {
266
+ // report progress and time elapsed:
267
+ chunkProgress(offset, l, (new Date()).getTime() - started);
268
+ }
269
+
270
+ // Completed processing all markers.
271
+ if (offset === l) {
272
+
273
+ // Refresh bounds and weighted positions.
274
+ this._topClusterLevel._recalculateBounds();
275
+
276
+ this._refreshClustersIcons();
277
+
278
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);
279
+ } else {
280
+ setTimeout(process, this.options.chunkDelay);
281
+ }
282
+ }, this);
283
+
284
+ process();
285
+ } else {
286
+ var needsClustering = this._needsClustering;
287
+
288
+ for (; offset < l; offset++) {
289
+ m = layersArray[offset];
290
+
291
+ // Group of layers, append children to layersArray and skip.
292
+ if (m instanceof BM.LayerGroup) {
293
+ if (originalArray) {
294
+ layersArray = layersArray.slice();
295
+ originalArray = false;
296
+ }
297
+ this._extractNonGroupLayers(m, layersArray);
298
+ l = layersArray.length;
299
+ continue;
300
+ }
301
+
302
+ //Not point data, can't be clustered
303
+ if (!m.getLatLng) {
304
+ npg.addLayer(m);
305
+ continue;
306
+ }
307
+
308
+ if (this.hasLayer(m)) {
309
+ continue;
310
+ }
311
+
312
+ needsClustering.push(m);
313
+ }
314
+ }
315
+ return this;
316
+ },
317
+
318
+ //Takes an array of markers and removes them in bulk
319
+ removeLayers: function (layersArray) {
320
+ var i, m,
321
+ l = layersArray.length,
322
+ fg = this._featureGroup,
323
+ npg = this._nonPointGroup,
324
+ originalArray = true;
325
+
326
+ if (!this._map) {
327
+ for (i = 0; i < l; i++) {
328
+ m = layersArray[i];
329
+
330
+ // Group of layers, append children to layersArray and skip.
331
+ if (m instanceof BM.LayerGroup) {
332
+ if (originalArray) {
333
+ layersArray = layersArray.slice();
334
+ originalArray = false;
335
+ }
336
+ this._extractNonGroupLayers(m, layersArray);
337
+ l = layersArray.length;
338
+ continue;
339
+ }
340
+
341
+ this._arraySplice(this._needsClustering, m);
342
+ npg.removeLayer(m);
343
+ if (this.hasLayer(m)) {
344
+ this._needsRemoving.push({ layer: m, latlng: m._latlng });
345
+ }
346
+ this.fire('layerremove', { layer: m });
347
+ }
348
+ return this;
349
+ }
350
+
351
+ if (this._unspiderfy) {
352
+ this._unspiderfy();
353
+
354
+ // Work on a copy of the array, so that next loop is not affected.
355
+ var layersArray2 = layersArray.slice(),
356
+ l2 = l;
357
+ for (i = 0; i < l2; i++) {
358
+ m = layersArray2[i];
359
+
360
+ // Group of layers, append children to layersArray and skip.
361
+ if (m instanceof BM.LayerGroup) {
362
+ this._extractNonGroupLayers(m, layersArray2);
363
+ l2 = layersArray2.length;
364
+ continue;
365
+ }
366
+
367
+ this._unspiderfyLayer(m);
368
+ }
369
+ }
370
+
371
+ for (i = 0; i < l; i++) {
372
+ m = layersArray[i];
373
+
374
+ // Group of layers, append children to layersArray and skip.
375
+ if (m instanceof BM.LayerGroup) {
376
+ if (originalArray) {
377
+ layersArray = layersArray.slice();
378
+ originalArray = false;
379
+ }
380
+ this._extractNonGroupLayers(m, layersArray);
381
+ l = layersArray.length;
382
+ continue;
383
+ }
384
+
385
+ if (!m.__parent) {
386
+ npg.removeLayer(m);
387
+ this.fire('layerremove', { layer: m });
388
+ continue;
389
+ }
390
+
391
+ this._removeLayer(m, true, true);
392
+ this.fire('layerremove', { layer: m });
393
+
394
+ if (fg.hasLayer(m)) {
395
+ fg.removeLayer(m);
396
+ if (m.clusterShow) {
397
+ m.clusterShow();
398
+ }
399
+ }
400
+ }
401
+
402
+ // Refresh bounds and weighted positions.
403
+ this._topClusterLevel._recalculateBounds();
404
+
405
+ this._refreshClustersIcons();
406
+
407
+ //Fix up the clusters and markers on the map
408
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);
409
+
410
+ return this;
411
+ },
412
+
413
+ //Removes all layers from the MarkerClusterGroup
414
+ clearLayers: function () {
415
+ //Need our own special implementation as the LayerGroup one doesn't work for us
416
+
417
+ //If we aren't on the map (yet), blow away the markers we know of
418
+ if (!this._map) {
419
+ this._needsClustering = [];
420
+ this._needsRemoving = [];
421
+ delete this._gridClusters;
422
+ delete this._gridUnclustered;
423
+ }
424
+
425
+ if (this._noanimationUnspiderfy) {
426
+ this._noanimationUnspiderfy();
427
+ }
428
+
429
+ //Remove all the visible layers
430
+ this._featureGroup.clearLayers();
431
+ this._nonPointGroup.clearLayers();
432
+
433
+ this.eachLayer(function (marker) {
434
+ marker.off(this._childMarkerEventHandlers, this);
435
+ delete marker.__parent;
436
+ }, this);
437
+
438
+ if (this._map) {
439
+ //Reset _topClusterLevel and the DistanceGrids
440
+ this._generateInitialClusters();
441
+ }
442
+
443
+ return this;
444
+ },
445
+
446
+ //Override FeatureGroup.getBounds as it doesn't work
447
+ getBounds: function () {
448
+ var bounds = new BM.LatLngBounds();
449
+
450
+ if (this._topClusterLevel) {
451
+ bounds.extend(this._topClusterLevel._bounds);
452
+ }
453
+
454
+ for (var i = this._needsClustering.length - 1; i >= 0; i--) {
455
+ bounds.extend(this._needsClustering[i].getLatLng());
456
+ }
457
+
458
+ bounds.extend(this._nonPointGroup.getBounds());
459
+
460
+ return bounds;
461
+ },
462
+
463
+ //Overrides LayerGroup.eachLayer
464
+ eachLayer: function (method, context) {
465
+ var markers = this._needsClustering.slice(),
466
+ needsRemoving = this._needsRemoving,
467
+ thisNeedsRemoving, i, j;
468
+
469
+ if (this._topClusterLevel) {
470
+ this._topClusterLevel.getAllChildMarkers(markers);
471
+ }
472
+
473
+ for (i = markers.length - 1; i >= 0; i--) {
474
+ thisNeedsRemoving = true;
475
+
476
+ for (j = needsRemoving.length - 1; j >= 0; j--) {
477
+ if (needsRemoving[j].layer === markers[i]) {
478
+ thisNeedsRemoving = false;
479
+ break;
480
+ }
481
+ }
482
+
483
+ if (thisNeedsRemoving) {
484
+ method.call(context, markers[i]);
485
+ }
486
+ }
487
+
488
+ this._nonPointGroup.eachLayer(method, context);
489
+ },
490
+
491
+ //Overrides LayerGroup.getLayers
492
+ getLayers: function () {
493
+ var layers = [];
494
+ this.eachLayer(function (l) {
495
+ layers.push(l);
496
+ });
497
+ return layers;
498
+ },
499
+
500
+ //Overrides LayerGroup.getLayer, WARNING: Really bad performance
501
+ getLayer: function (id) {
502
+ var result = null;
503
+
504
+ id = parseInt(id, 10);
505
+
506
+ this.eachLayer(function (l) {
507
+ if (BM.stamp(l) === id) {
508
+ result = l;
509
+ }
510
+ });
511
+
512
+ return result;
513
+ },
514
+
515
+ //Returns true if the given layer is in this MarkerClusterGroup
516
+ hasLayer: function (layer) {
517
+ if (!layer) {
518
+ return false;
519
+ }
520
+
521
+ var i, anArray = this._needsClustering;
522
+
523
+ for (i = anArray.length - 1; i >= 0; i--) {
524
+ if (anArray[i] === layer) {
525
+ return true;
526
+ }
527
+ }
528
+
529
+ anArray = this._needsRemoving;
530
+ for (i = anArray.length - 1; i >= 0; i--) {
531
+ if (anArray[i].layer === layer) {
532
+ return false;
533
+ }
534
+ }
535
+
536
+ return !!(layer.__parent && layer.__parent._group === this) || this._nonPointGroup.hasLayer(layer);
537
+ },
538
+
539
+ //Zoom down to show the given layer (spiderfying if necessary) then calls the callback
540
+ zoomToShowLayer: function (layer, callback) {
541
+
542
+ if (typeof callback !== 'function') {
543
+ callback = function () {};
544
+ }
545
+
546
+ var showMarker = function () {
547
+ if ((layer._icon || layer.__parent._icon) && !this._inZoomAnimation) {
548
+ this._map.off('moveend', showMarker, this);
549
+ this.off('animationend', showMarker, this);
550
+
551
+ if (layer._icon) {
552
+ callback();
553
+ } else if (layer.__parent._icon) {
554
+ this.once('spiderfied', callback, this);
555
+ layer.__parent.spiderfy();
556
+ }
557
+ }
558
+ };
559
+
560
+ if (layer._icon && this._map.getBounds().contains(layer.getLatLng())) {
561
+ //Layer is visible ond on screen, immediate return
562
+ callback();
563
+ } else if (layer.__parent._zoom < Math.round(this._map._zoom)) {
564
+ //Layer should be visible at this zoom level. It must not be on screen so just pan over to it
565
+ this._map.on('moveend', showMarker, this);
566
+ this._map.panTo(layer.getLatLng());
567
+ } else {
568
+ this._map.on('moveend', showMarker, this);
569
+ this.on('animationend', showMarker, this);
570
+ layer.__parent.zoomToBounds();
571
+ }
572
+ },
573
+
574
+ //Overrides FeatureGroup.onAdd
575
+ onAdd: function (map) {
576
+ this._map = map;
577
+ var i, l, layer;
578
+
579
+ if (!isFinite(this._map.getMaxZoom())) {
580
+ throw "Map has no maxZoom specified";
581
+ }
582
+
583
+ this._featureGroup.addTo(map);
584
+ this._nonPointGroup.addTo(map);
585
+
586
+ if (!this._gridClusters) {
587
+ this._generateInitialClusters();
588
+ }
589
+
590
+ this._maxLat = map.options.crs.projection.MAX_LATITUDE;
591
+
592
+ //Restore all the positions as they are in the MCG before removing them
593
+ for (i = 0, l = this._needsRemoving.length; i < l; i++) {
594
+ layer = this._needsRemoving[i];
595
+ layer.newlatlng = layer.layer._latlng;
596
+ layer.layer._latlng = layer.latlng;
597
+ }
598
+ //Remove them, then restore their new positions
599
+ for (i = 0, l = this._needsRemoving.length; i < l; i++) {
600
+ layer = this._needsRemoving[i];
601
+ this._removeLayer(layer.layer, true);
602
+ layer.layer._latlng = layer.newlatlng;
603
+ }
604
+ this._needsRemoving = [];
605
+
606
+ //Remember the current zoom level and bounds
607
+ this._zoom = Math.round(this._map._zoom);
608
+ this._currentShownBounds = this._getExpandedVisibleBounds();
609
+
610
+ this._map.on('zoomend', this._zoomEnd, this);
611
+ this._map.on('moveend', this._moveEnd, this);
612
+
613
+ if (this._spiderfierOnAdd) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely
614
+ this._spiderfierOnAdd();
615
+ }
616
+
617
+ this._bindEvents();
618
+
619
+ //Actually add our markers to the map:
620
+ l = this._needsClustering;
621
+ this._needsClustering = [];
622
+ this.addLayers(l, true);
623
+ },
624
+
625
+ //Overrides FeatureGroup.onRemove
626
+ onRemove: function (map) {
627
+ map.off('zoomend', this._zoomEnd, this);
628
+ map.off('moveend', this._moveEnd, this);
629
+
630
+ this._unbindEvents();
631
+
632
+ //In case we are in a cluster animation
633
+ this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', '');
634
+
635
+ if (this._spiderfierOnRemove) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely
636
+ this._spiderfierOnRemove();
637
+ }
638
+
639
+ delete this._maxLat;
640
+
641
+ //Clean up all the layers we added to the map
642
+ this._hideCoverage();
643
+ this._featureGroup.remove();
644
+ this._nonPointGroup.remove();
645
+
646
+ this._featureGroup.clearLayers();
647
+
648
+ this._map = null;
649
+ },
650
+
651
+ getVisibleParent: function (marker) {
652
+ var vMarker = marker;
653
+ while (vMarker && !vMarker._icon) {
654
+ vMarker = vMarker.__parent;
655
+ }
656
+ return vMarker || null;
657
+ },
658
+
659
+ //Remove the given object from the given array
660
+ _arraySplice: function (anArray, obj) {
661
+ for (var i = anArray.length - 1; i >= 0; i--) {
662
+ if (anArray[i] === obj) {
663
+ anArray.splice(i, 1);
664
+ return true;
665
+ }
666
+ }
667
+ },
668
+
669
+ /**
670
+ * Removes a marker from all _gridUnclustered zoom levels, starting at the supplied zoom.
671
+ * @param marker to be removed from _gridUnclustered.
672
+ * @param z integer bottom start zoom level (included)
673
+ * @private
674
+ */
675
+ _removeFromGridUnclustered: function (marker, z) {
676
+ var map = this._map,
677
+ gridUnclustered = this._gridUnclustered,
678
+ minZoom = Math.floor(this._map.getMinZoom());
679
+
680
+ for (; z >= minZoom; z--) {
681
+ if (!gridUnclustered[z].removeObject(marker, map.project(marker.getLatLng(), z))) {
682
+ break;
683
+ }
684
+ }
685
+ },
686
+
687
+ _childMarkerDragStart: function (e) {
688
+ e.target.__dragStart = e.target._latlng;
689
+ },
690
+
691
+ _childMarkerMoved: function (e) {
692
+ if (!this._ignoreMove && !e.target.__dragStart) {
693
+ var isPopupOpen = e.target._popup && e.target._popup.isOpen();
694
+
695
+ this._moveChild(e.target, e.oldLatLng, e.latlng);
696
+
697
+ if (isPopupOpen) {
698
+ e.target.openPopup();
699
+ }
700
+ }
701
+ },
702
+
703
+ _moveChild: function (layer, from, to) {
704
+ layer._latlng = from;
705
+ this.removeLayer(layer);
706
+
707
+ layer._latlng = to;
708
+ this.addLayer(layer);
709
+ },
710
+
711
+ _childMarkerDragEnd: function (e) {
712
+ var dragStart = e.target.__dragStart;
713
+ delete e.target.__dragStart;
714
+ if (dragStart) {
715
+ this._moveChild(e.target, dragStart, e.target._latlng);
716
+ }
717
+ },
718
+
719
+
720
+ //Internal function for removing a marker from everything.
721
+ //dontUpdateMap: set to true if you will handle updating the map manually (for bulk functions)
722
+ _removeLayer: function (marker, removeFromDistanceGrid, dontUpdateMap) {
723
+ var gridClusters = this._gridClusters,
724
+ gridUnclustered = this._gridUnclustered,
725
+ fg = this._featureGroup,
726
+ map = this._map,
727
+ minZoom = Math.floor(this._map.getMinZoom());
728
+
729
+ //Remove the marker from distance clusters it might be in
730
+ if (removeFromDistanceGrid) {
731
+ this._removeFromGridUnclustered(marker, this._maxZoom);
732
+ }
733
+
734
+ //Work our way up the clusters removing them as we go if required
735
+ var cluster = marker.__parent,
736
+ markers = cluster._markers,
737
+ otherMarker;
738
+
739
+ //Remove the marker from the immediate parents marker list
740
+ this._arraySplice(markers, marker);
741
+
742
+ while (cluster) {
743
+ cluster._childCount--;
744
+ cluster._boundsNeedUpdate = true;
745
+
746
+ if (cluster._zoom < minZoom) {
747
+ //Top level, do nothing
748
+ break;
749
+ } else if (removeFromDistanceGrid && cluster._childCount <= 1) { //Cluster no longer required
750
+ //We need to push the other marker up to the parent
751
+ otherMarker = cluster._markers[0] === marker ? cluster._markers[1] : cluster._markers[0];
752
+
753
+ //Update distance grid
754
+ gridClusters[cluster._zoom].removeObject(cluster, map.project(cluster._cLatLng, cluster._zoom));
755
+ gridUnclustered[cluster._zoom].addObject(otherMarker, map.project(otherMarker.getLatLng(), cluster._zoom));
756
+
757
+ //Move otherMarker up to parent
758
+ this._arraySplice(cluster.__parent._childClusters, cluster);
759
+ cluster.__parent._markers.push(otherMarker);
760
+ otherMarker.__parent = cluster.__parent;
761
+
762
+ if (cluster._icon) {
763
+ //Cluster is currently on the map, need to put the marker on the map instead
764
+ fg.removeLayer(cluster);
765
+ if (!dontUpdateMap) {
766
+ fg.addLayer(otherMarker);
767
+ }
768
+ }
769
+ } else {
770
+ cluster._iconNeedsUpdate = true;
771
+ }
772
+
773
+ cluster = cluster.__parent;
774
+ }
775
+
776
+ delete marker.__parent;
777
+ },
778
+
779
+ _isOrIsParent: function (el, oel) {
780
+ while (oel) {
781
+ if (el === oel) {
782
+ return true;
783
+ }
784
+ oel = oel.parentNode;
785
+ }
786
+ return false;
787
+ },
788
+
789
+ //Override BM.Evented.fire
790
+ fire: function (type, data, propagate) {
791
+ if (data && data.layer instanceof BM.MarkerCluster) {
792
+ //Prevent multiple clustermouseover/off events if the icon is made up of stacked divs (Doesn't work in ie <= 8, no relatedTarget)
793
+ if (data.originalEvent && this._isOrIsParent(data.layer._icon, data.originalEvent.relatedTarget)) {
794
+ return;
795
+ }
796
+ type = 'cluster' + type;
797
+ }
798
+
799
+ BM.FeatureGroup.prototype.fire.call(this, type, data, propagate);
800
+ },
801
+
802
+ //Override BM.Evented.listens
803
+ listens: function (type, propagate) {
804
+ return BM.FeatureGroup.prototype.listens.call(this, type, propagate) || BM.FeatureGroup.prototype.listens.call(this, 'cluster' + type, propagate);
805
+ },
806
+
807
+ //Default functionality
808
+ _defaultIconCreateFunction: function (cluster) {
809
+ var childCount = cluster.getChildCount();
810
+
811
+ var c = ' marker-cluster-';
812
+ if (childCount < 10) {
813
+ c += 'small';
814
+ } else if (childCount < 100) {
815
+ c += 'medium';
816
+ } else {
817
+ c += 'large';
818
+ }
819
+
820
+ return new BM.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster' + c, iconSize: new BM.Point(40, 40) });
821
+ },
822
+
823
+ _bindEvents: function () {
824
+ var map = this._map,
825
+ spiderfyOnMaxZoom = this.options.spiderfyOnMaxZoom,
826
+ showCoverageOnHover = this.options.showCoverageOnHover,
827
+ zoomToBoundsOnClick = this.options.zoomToBoundsOnClick;
828
+
829
+ //Zoom on cluster click or spiderfy if we are at the lowest level
830
+ if (spiderfyOnMaxZoom || zoomToBoundsOnClick) {
831
+ this.on('clusterclick', this._zoomOrSpiderfy, this);
832
+ }
833
+
834
+ //Show convex hull (boundary) polygon on mouse over
835
+ if (showCoverageOnHover) {
836
+ this.on('clustermouseover', this._showCoverage, this);
837
+ this.on('clustermouseout', this._hideCoverage, this);
838
+ map.on('zoomend', this._hideCoverage, this);
839
+ }
840
+ },
841
+
842
+ _zoomOrSpiderfy: function (e) {
843
+ var cluster = e.layer,
844
+ bottomCluster = cluster;
845
+
846
+ while (bottomCluster._childClusters.length === 1) {
847
+ bottomCluster = bottomCluster._childClusters[0];
848
+ }
849
+
850
+ if (bottomCluster._zoom === this._maxZoom &&
851
+ bottomCluster._childCount === cluster._childCount &&
852
+ this.options.spiderfyOnMaxZoom) {
853
+
854
+ // All child markers are contained in a single cluster from this._maxZoom to this cluster.
855
+ cluster.spiderfy();
856
+ } else if (this.options.zoomToBoundsOnClick) {
857
+ cluster.zoomToBounds();
858
+ }
859
+
860
+ // Focus the map again for keyboard users.
861
+ if (e.originalEvent && e.originalEvent.keyCode === 13) {
862
+ this._map._container.focus();
863
+ }
864
+ },
865
+
866
+ _showCoverage: function (e) {
867
+ var map = this._map;
868
+ if (this._inZoomAnimation) {
869
+ return;
870
+ }
871
+ if (this._shownPolygon) {
872
+ map.removeLayer(this._shownPolygon);
873
+ }
874
+ if (e.layer.getChildCount() > 2 && e.layer !== this._spiderfied) {
875
+ this._shownPolygon = new BM.Polygon(e.layer.getConvexHull(), this.options.polygonOptions);
876
+ map.addLayer(this._shownPolygon);
877
+ }
878
+ },
879
+
880
+ _hideCoverage: function () {
881
+ if (this._shownPolygon) {
882
+ this._map.removeLayer(this._shownPolygon);
883
+ this._shownPolygon = null;
884
+ }
885
+ },
886
+
887
+ _unbindEvents: function () {
888
+ var spiderfyOnMaxZoom = this.options.spiderfyOnMaxZoom,
889
+ showCoverageOnHover = this.options.showCoverageOnHover,
890
+ zoomToBoundsOnClick = this.options.zoomToBoundsOnClick,
891
+ map = this._map;
892
+
893
+ if (spiderfyOnMaxZoom || zoomToBoundsOnClick) {
894
+ this.off('clusterclick', this._zoomOrSpiderfy, this);
895
+ }
896
+ if (showCoverageOnHover) {
897
+ this.off('clustermouseover', this._showCoverage, this);
898
+ this.off('clustermouseout', this._hideCoverage, this);
899
+ map.off('zoomend', this._hideCoverage, this);
900
+ }
901
+ },
902
+
903
+ _zoomEnd: function () {
904
+ if (!this._map) { //May have been removed from the map by a zoomEnd handler
905
+ return;
906
+ }
907
+ this._mergeSplitClusters();
908
+
909
+ this._zoom = Math.round(this._map._zoom);
910
+ this._currentShownBounds = this._getExpandedVisibleBounds();
911
+ },
912
+
913
+ _moveEnd: function () {
914
+ if (this._inZoomAnimation) {
915
+ return;
916
+ }
917
+
918
+ var newBounds = this._getExpandedVisibleBounds();
919
+
920
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), this._zoom, newBounds);
921
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, Math.round(this._map._zoom), newBounds);
922
+
923
+ this._currentShownBounds = newBounds;
924
+ return;
925
+ },
926
+
927
+ _generateInitialClusters: function () {
928
+ var maxZoom = Math.ceil(this._map.getMaxZoom()),
929
+ minZoom = Math.floor(this._map.getMinZoom()),
930
+ radius = this.options.maxClusterRadius,
931
+ radiusFn = radius;
932
+
933
+ //If we just set maxClusterRadius to a single number, we need to create
934
+ //a simple function to return that number. Otherwise, we just have to
935
+ //use the function we've passed in.
936
+ if (typeof radius !== "function") {
937
+ radiusFn = function () { return radius; };
938
+ }
939
+
940
+ if (this.options.disableClusteringAtZoom !== null) {
941
+ maxZoom = this.options.disableClusteringAtZoom - 1;
942
+ }
943
+ this._maxZoom = maxZoom;
944
+ this._gridClusters = {};
945
+ this._gridUnclustered = {};
946
+
947
+ //Set up DistanceGrids for each zoom
948
+ for (var zoom = maxZoom; zoom >= minZoom; zoom--) {
949
+ this._gridClusters[zoom] = new BM.DistanceGrid(radiusFn(zoom));
950
+ this._gridUnclustered[zoom] = new BM.DistanceGrid(radiusFn(zoom));
951
+ }
952
+
953
+ // Instantiate the appropriate BM.MarkerCluster class (animated or not).
954
+ this._topClusterLevel = new this._markerCluster(this, minZoom - 1);
955
+ },
956
+
957
+ //Zoom: Zoom to start adding at (Pass this._maxZoom to start at the bottom)
958
+ _addLayer: function (layer, zoom) {
959
+ var gridClusters = this._gridClusters,
960
+ gridUnclustered = this._gridUnclustered,
961
+ minZoom = Math.floor(this._map.getMinZoom()),
962
+ markerPoint, z;
963
+
964
+ if (this.options.singleMarkerMode) {
965
+ this._overrideMarkerIcon(layer);
966
+ }
967
+
968
+ layer.on(this._childMarkerEventHandlers, this);
969
+
970
+ //Find the lowest zoom level to slot this one in
971
+ for (; zoom >= minZoom; zoom--) {
972
+ markerPoint = this._map.project(layer.getLatLng(), zoom); // calculate pixel position
973
+
974
+ //Try find a cluster close by
975
+ var closest = gridClusters[zoom].getNearObject(markerPoint);
976
+ if (closest) {
977
+ closest._addChild(layer);
978
+ layer.__parent = closest;
979
+ return;
980
+ }
981
+
982
+ //Try find a marker close by to form a new cluster with
983
+ closest = gridUnclustered[zoom].getNearObject(markerPoint);
984
+ if (closest) {
985
+ var parent = closest.__parent;
986
+ if (parent) {
987
+ this._removeLayer(closest, false);
988
+ }
989
+
990
+ //Create new cluster with these 2 in it
991
+
992
+ var newCluster = new this._markerCluster(this, zoom, closest, layer);
993
+ gridClusters[zoom].addObject(newCluster, this._map.project(newCluster._cLatLng, zoom));
994
+ closest.__parent = newCluster;
995
+ layer.__parent = newCluster;
996
+
997
+ //First create any new intermediate parent clusters that don't exist
998
+ var lastParent = newCluster;
999
+ for (z = zoom - 1; z > parent._zoom; z--) {
1000
+ lastParent = new this._markerCluster(this, z, lastParent);
1001
+ gridClusters[z].addObject(lastParent, this._map.project(closest.getLatLng(), z));
1002
+ }
1003
+ parent._addChild(lastParent);
1004
+
1005
+ //Remove closest from this zoom level and any above that it is in, replace with newCluster
1006
+ this._removeFromGridUnclustered(closest, zoom);
1007
+
1008
+ return;
1009
+ }
1010
+
1011
+ //Didn't manage to cluster in at this zoom, record us as a marker here and continue upwards
1012
+ gridUnclustered[zoom].addObject(layer, markerPoint);
1013
+ }
1014
+
1015
+ //Didn't get in anything, add us to the top
1016
+ this._topClusterLevel._addChild(layer);
1017
+ layer.__parent = this._topClusterLevel;
1018
+ return;
1019
+ },
1020
+
1021
+ /**
1022
+ * Refreshes the icon of all "dirty" visible clusters.
1023
+ * Non-visible "dirty" clusters will be updated when they are added to the map.
1024
+ * @private
1025
+ */
1026
+ _refreshClustersIcons: function () {
1027
+ this._featureGroup.eachLayer(function (c) {
1028
+ if (c instanceof BM.MarkerCluster && c._iconNeedsUpdate) {
1029
+ c._updateIcon();
1030
+ }
1031
+ });
1032
+ },
1033
+
1034
+ //Enqueue code to fire after the marker expand/contract has happened
1035
+ _enqueue: function (fn) {
1036
+ this._queue.push(fn);
1037
+ if (!this._queueTimeout) {
1038
+ this._queueTimeout = setTimeout(BM.bind(this._processQueue, this), 300);
1039
+ }
1040
+ },
1041
+ _processQueue: function () {
1042
+ for (var i = 0; i < this._queue.length; i++) {
1043
+ this._queue[i].call(this);
1044
+ }
1045
+ this._queue.length = 0;
1046
+ clearTimeout(this._queueTimeout);
1047
+ this._queueTimeout = null;
1048
+ },
1049
+
1050
+ //Merge and split any existing clusters that are too big or small
1051
+ _mergeSplitClusters: function () {
1052
+ var mapZoom = Math.round(this._map._zoom);
1053
+
1054
+ //In case we are starting to split before the animation finished
1055
+ this._processQueue();
1056
+
1057
+ if (this._zoom < mapZoom && this._currentShownBounds.intersects(this._getExpandedVisibleBounds())) { //Zoom in, split
1058
+ this._animationStart();
1059
+ //Remove clusters now off screen
1060
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), this._zoom, this._getExpandedVisibleBounds());
1061
+
1062
+ this._animationZoomIn(this._zoom, mapZoom);
1063
+
1064
+ } else if (this._zoom > mapZoom) { //Zoom out, merge
1065
+ this._animationStart();
1066
+
1067
+ this._animationZoomOut(this._zoom, mapZoom);
1068
+ } else {
1069
+ this._moveEnd();
1070
+ }
1071
+ },
1072
+
1073
+ //Gets the maps visible bounds expanded in each direction by the size of the screen (so the user cannot see an area we do not cover in one pan)
1074
+ _getExpandedVisibleBounds: function () {
1075
+ if (!this.options.removeOutsideVisibleBounds) {
1076
+ return this._mapBoundsInfinite;
1077
+ } else if (BM.Browser.mobile) {
1078
+ return this._checkBoundsMaxLat(this._map.getBounds());
1079
+ }
1080
+
1081
+ return this._checkBoundsMaxLat(this._map.getBounds().pad(1)); // Padding expands the bounds by its own dimensions but scaled with the given factor.
1082
+ },
1083
+
1084
+ /**
1085
+ * Expands the latitude to Infinity (or -Infinity) if the input bounds reach the map projection maximum defined latitude
1086
+ * (in the case of Web/Spherical Mercator, it is 85.0511287798 / see https://en.wikipedia.org/wiki/Web_Mercator#Formulas).
1087
+ * Otherwise, the removeOutsideVisibleBounds option will remove markers beyond that limit, whereas the same markers without
1088
+ * this option (or outside MCG) will have their position floored (ceiled) by the projection and rendered at that limit,
1089
+ * making the user think that MCG "eats" them and never displays them again.
1090
+ * @param bounds BM.LatLngBounds
1091
+ * @returns {BM.LatLngBounds}
1092
+ * @private
1093
+ */
1094
+ _checkBoundsMaxLat: function (bounds) {
1095
+ var maxLat = this._maxLat;
1096
+
1097
+ if (maxLat !== undefined) {
1098
+ if (bounds.getNorth() >= maxLat) {
1099
+ bounds._northEast.lat = Infinity;
1100
+ }
1101
+ if (bounds.getSouth() <= -maxLat) {
1102
+ bounds._southWest.lat = -Infinity;
1103
+ }
1104
+ }
1105
+
1106
+ return bounds;
1107
+ },
1108
+
1109
+ //Shared animation code
1110
+ _animationAddLayerNonAnimated: function (layer, newCluster) {
1111
+ if (newCluster === layer) {
1112
+ this._featureGroup.addLayer(layer);
1113
+ } else if (newCluster._childCount === 2) {
1114
+ newCluster._addToMap();
1115
+
1116
+ var markers = newCluster.getAllChildMarkers();
1117
+ this._featureGroup.removeLayer(markers[0]);
1118
+ this._featureGroup.removeLayer(markers[1]);
1119
+ } else {
1120
+ newCluster._updateIcon();
1121
+ }
1122
+ },
1123
+
1124
+ /**
1125
+ * Extracts individual (i.e. non-group) layers from a Layer Group.
1126
+ * @param group to extract layers from.
1127
+ * @param output {Array} in which to store the extracted layers.
1128
+ * @returns {*|Array}
1129
+ * @private
1130
+ */
1131
+ _extractNonGroupLayers: function (group, output) {
1132
+ var layers = group.getLayers(),
1133
+ i = 0,
1134
+ layer;
1135
+
1136
+ output = output || [];
1137
+
1138
+ for (; i < layers.length; i++) {
1139
+ layer = layers[i];
1140
+
1141
+ if (layer instanceof BM.LayerGroup) {
1142
+ this._extractNonGroupLayers(layer, output);
1143
+ continue;
1144
+ }
1145
+
1146
+ output.push(layer);
1147
+ }
1148
+
1149
+ return output;
1150
+ },
1151
+
1152
+ /**
1153
+ * Implements the singleMarkerMode option.
1154
+ * @param layer Marker to re-style using the Clusters iconCreateFunction.
1155
+ * @returns {BM.Icon} The newly created icon.
1156
+ * @private
1157
+ */
1158
+ _overrideMarkerIcon: function (layer) {
1159
+ var icon = layer.options.icon = this.options.iconCreateFunction({
1160
+ getChildCount: function () {
1161
+ return 1;
1162
+ },
1163
+ getAllChildMarkers: function () {
1164
+ return [layer];
1165
+ }
1166
+ });
1167
+
1168
+ return icon;
1169
+ }
1170
+ });
1171
+
1172
+ // Constant bounds used in case option "removeOutsideVisibleBounds" is set to false.
1173
+ BM.MarkerClusterGroup.include({
1174
+ _mapBoundsInfinite: new BM.LatLngBounds(new BM.LatLng(-Infinity, -Infinity), new BM.LatLng(Infinity, Infinity))
1175
+ });
1176
+
1177
+ BM.MarkerClusterGroup.include({
1178
+ _noAnimation: {
1179
+ //Non Animated versions of everything
1180
+ _animationStart: function () {
1181
+ //Do nothing...
1182
+ },
1183
+ _animationZoomIn: function (previousZoomLevel, newZoomLevel) {
1184
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel);
1185
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds());
1186
+
1187
+ //We didn't actually animate, but we use this event to mean "clustering animations have finished"
1188
+ this.fire('animationend');
1189
+ },
1190
+ _animationZoomOut: function (previousZoomLevel, newZoomLevel) {
1191
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel);
1192
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds());
1193
+
1194
+ //We didn't actually animate, but we use this event to mean "clustering animations have finished"
1195
+ this.fire('animationend');
1196
+ },
1197
+ _animationAddLayer: function (layer, newCluster) {
1198
+ this._animationAddLayerNonAnimated(layer, newCluster);
1199
+ }
1200
+ },
1201
+
1202
+ _withAnimation: {
1203
+ //Animated versions here
1204
+ _animationStart: function () {
1205
+ this._map._mapPane.className += ' leaflet-cluster-anim';
1206
+ this._inZoomAnimation++;
1207
+ },
1208
+
1209
+ _animationZoomIn: function (previousZoomLevel, newZoomLevel) {
1210
+ var bounds = this._getExpandedVisibleBounds(),
1211
+ fg = this._featureGroup,
1212
+ minZoom = Math.floor(this._map.getMinZoom()),
1213
+ i;
1214
+
1215
+ this._ignoreMove = true;
1216
+
1217
+ //Add all children of current clusters to map and remove those clusters from map
1218
+ this._topClusterLevel._recursively(bounds, previousZoomLevel, minZoom, function (c) {
1219
+ var startPos = c._latlng,
1220
+ markers = c._markers,
1221
+ m;
1222
+
1223
+ if (!bounds.contains(startPos)) {
1224
+ startPos = null;
1225
+ }
1226
+
1227
+ if (c._isSingleParent() && previousZoomLevel + 1 === newZoomLevel) { //Immediately add the new child and remove us
1228
+ fg.removeLayer(c);
1229
+ c._recursivelyAddChildrenToMap(null, newZoomLevel, bounds);
1230
+ } else {
1231
+ //Fade out old cluster
1232
+ c.clusterHide();
1233
+ c._recursivelyAddChildrenToMap(startPos, newZoomLevel, bounds);
1234
+ }
1235
+
1236
+ //Remove all markers that aren't visible any more
1237
+ //TODO: Do we actually need to do this on the higher levels too?
1238
+ for (i = markers.length - 1; i >= 0; i--) {
1239
+ m = markers[i];
1240
+ if (!bounds.contains(m._latlng)) {
1241
+ fg.removeLayer(m);
1242
+ }
1243
+ }
1244
+
1245
+ });
1246
+
1247
+ this._forceLayout();
1248
+
1249
+ //Update opacities
1250
+ this._topClusterLevel._recursivelyBecomeVisible(bounds, newZoomLevel);
1251
+ //TODO Maybe? Update markers in _recursivelyBecomeVisible
1252
+ fg.eachLayer(function (n) {
1253
+ if (!(n instanceof BM.MarkerCluster) && n._icon) {
1254
+ n.clusterShow();
1255
+ }
1256
+ });
1257
+
1258
+ //update the positions of the just added clusters/markers
1259
+ this._topClusterLevel._recursively(bounds, previousZoomLevel, newZoomLevel, function (c) {
1260
+ c._recursivelyRestoreChildPositions(newZoomLevel);
1261
+ });
1262
+
1263
+ this._ignoreMove = false;
1264
+
1265
+ //Remove the old clusters and close the zoom animation
1266
+ this._enqueue(function () {
1267
+ //update the positions of the just added clusters/markers
1268
+ this._topClusterLevel._recursively(bounds, previousZoomLevel, minZoom, function (c) {
1269
+ fg.removeLayer(c);
1270
+ c.clusterShow();
1271
+ });
1272
+
1273
+ this._animationEnd();
1274
+ });
1275
+ },
1276
+
1277
+ _animationZoomOut: function (previousZoomLevel, newZoomLevel) {
1278
+ this._animationZoomOutSingle(this._topClusterLevel, previousZoomLevel - 1, newZoomLevel);
1279
+
1280
+ //Need to add markers for those that weren't on the map before but are now
1281
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds());
1282
+ //Remove markers that were on the map before but won't be now
1283
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel, this._getExpandedVisibleBounds());
1284
+ },
1285
+
1286
+ _animationAddLayer: function (layer, newCluster) {
1287
+ var me = this,
1288
+ fg = this._featureGroup;
1289
+
1290
+ fg.addLayer(layer);
1291
+ if (newCluster !== layer) {
1292
+ if (newCluster._childCount > 2) { //Was already a cluster
1293
+
1294
+ newCluster._updateIcon();
1295
+ this._forceLayout();
1296
+ this._animationStart();
1297
+
1298
+ layer._setPos(this._map.latLngToLayerPoint(newCluster.getLatLng()));
1299
+ layer.clusterHide();
1300
+
1301
+ this._enqueue(function () {
1302
+ fg.removeLayer(layer);
1303
+ layer.clusterShow();
1304
+
1305
+ me._animationEnd();
1306
+ });
1307
+
1308
+ } else { //Just became a cluster
1309
+ this._forceLayout();
1310
+
1311
+ me._animationStart();
1312
+ me._animationZoomOutSingle(newCluster, this._map.getMaxZoom(), this._zoom);
1313
+ }
1314
+ }
1315
+ }
1316
+ },
1317
+
1318
+ // Private methods for animated versions.
1319
+ _animationZoomOutSingle: function (cluster, previousZoomLevel, newZoomLevel) {
1320
+ var bounds = this._getExpandedVisibleBounds(),
1321
+ minZoom = Math.floor(this._map.getMinZoom());
1322
+
1323
+ //Animate all of the markers in the clusters to move to their cluster center point
1324
+ cluster._recursivelyAnimateChildrenInAndAddSelfToMap(bounds, minZoom, previousZoomLevel + 1, newZoomLevel);
1325
+
1326
+ var me = this;
1327
+
1328
+ //Update the opacity (If we immediately set it they won't animate)
1329
+ this._forceLayout();
1330
+ cluster._recursivelyBecomeVisible(bounds, newZoomLevel);
1331
+
1332
+ //TODO: Maybe use the transition timing stuff to make this more reliable
1333
+ //When the animations are done, tidy up
1334
+ this._enqueue(function () {
1335
+
1336
+ //This cluster stopped being a cluster before the timeout fired
1337
+ if (cluster._childCount === 1) {
1338
+ var m = cluster._markers[0];
1339
+ //If we were in a cluster animation at the time then the opacity and position of our child could be wrong now, so fix it
1340
+ this._ignoreMove = true;
1341
+ m.setLatLng(m.getLatLng());
1342
+ this._ignoreMove = false;
1343
+ if (m.clusterShow) {
1344
+ m.clusterShow();
1345
+ }
1346
+ } else {
1347
+ cluster._recursively(bounds, newZoomLevel, minZoom, function (c) {
1348
+ c._recursivelyRemoveChildrenFromMap(bounds, minZoom, previousZoomLevel + 1);
1349
+ });
1350
+ }
1351
+ me._animationEnd();
1352
+ });
1353
+ },
1354
+
1355
+ _animationEnd: function () {
1356
+ if (this._map) {
1357
+ this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', '');
1358
+ }
1359
+ this._inZoomAnimation--;
1360
+ this.fire('animationend');
1361
+ },
1362
+
1363
+ //Force a browser layout of stuff in the map
1364
+ // Should apply the current opacity and location to all elements so we can update them again for an animation
1365
+ _forceLayout: function () {
1366
+ //In my testing this works, infact offsetWidth of any element seems to work.
1367
+ //Could loop all this._layers and do this for each _icon if it stops working
1368
+
1369
+ BM.Util.falseFn(document.body.offsetWidth);
1370
+ }
1371
+ });
1372
+
1373
+ BM.markerClusterGroup = function (options) {
1374
+ return new BM.MarkerClusterGroup(options);
1375
+ };
1376
+
1377
+ var MarkerCluster = BM.MarkerCluster = BM.Marker.extend({
1378
+ options: BM.Icon.prototype.options,
1379
+
1380
+ initialize: function (group, zoom, a, b) {
1381
+
1382
+ BM.Marker.prototype.initialize.call(this, a ? (a._cLatLng || a.getLatLng()) : new BM.LatLng(0, 0),
1383
+ { icon: this, pane: group.options.clusterPane });
1384
+
1385
+ this._group = group;
1386
+ this._zoom = zoom;
1387
+
1388
+ this._markers = [];
1389
+ this._childClusters = [];
1390
+ this._childCount = 0;
1391
+ this._iconNeedsUpdate = true;
1392
+ this._boundsNeedUpdate = true;
1393
+
1394
+ this._bounds = new BM.LatLngBounds();
1395
+
1396
+ if (a) {
1397
+ this._addChild(a);
1398
+ }
1399
+ if (b) {
1400
+ this._addChild(b);
1401
+ }
1402
+ },
1403
+
1404
+ //Recursively retrieve all child markers of this cluster
1405
+ getAllChildMarkers: function (storageArray, ignoreDraggedMarker) {
1406
+ storageArray = storageArray || [];
1407
+
1408
+ for (var i = this._childClusters.length - 1; i >= 0; i--) {
1409
+ this._childClusters[i].getAllChildMarkers(storageArray);
1410
+ }
1411
+
1412
+ for (var j = this._markers.length - 1; j >= 0; j--) {
1413
+ if (ignoreDraggedMarker && this._markers[j].__dragStart) {
1414
+ continue;
1415
+ }
1416
+ storageArray.push(this._markers[j]);
1417
+ }
1418
+
1419
+ return storageArray;
1420
+ },
1421
+
1422
+ //Returns the count of how many child markers we have
1423
+ getChildCount: function () {
1424
+ return this._childCount;
1425
+ },
1426
+
1427
+ //Zoom to the minimum of showing all of the child markers, or the extents of this cluster
1428
+ zoomToBounds: function (fitBoundsOptions) {
1429
+ var childClusters = this._childClusters.slice(),
1430
+ map = this._group._map,
1431
+ boundsZoom = map.getBoundsZoom(this._bounds),
1432
+ zoom = this._zoom + 1,
1433
+ mapZoom = map.getZoom(),
1434
+ i;
1435
+
1436
+ //calculate how far we need to zoom down to see all of the markers
1437
+ while (childClusters.length > 0 && boundsZoom > zoom) {
1438
+ zoom++;
1439
+ var newClusters = [];
1440
+ for (i = 0; i < childClusters.length; i++) {
1441
+ newClusters = newClusters.concat(childClusters[i]._childClusters);
1442
+ }
1443
+ childClusters = newClusters;
1444
+ }
1445
+
1446
+ if (boundsZoom > zoom) {
1447
+ this._group._map.setView(this._latlng, zoom);
1448
+ } else if (boundsZoom <= mapZoom) { //If fitBounds wouldn't zoom us down, zoom us down instead
1449
+ this._group._map.setView(this._latlng, mapZoom + 1);
1450
+ } else {
1451
+ this._group._map.fitBounds(this._bounds, fitBoundsOptions);
1452
+ }
1453
+ },
1454
+
1455
+ getBounds: function () {
1456
+ var bounds = new BM.LatLngBounds();
1457
+ bounds.extend(this._bounds);
1458
+ return bounds;
1459
+ },
1460
+
1461
+ _updateIcon: function () {
1462
+ this._iconNeedsUpdate = true;
1463
+ if (this._icon) {
1464
+ this.setIcon(this);
1465
+ }
1466
+ },
1467
+
1468
+ //Cludge for Icon, we pretend to be an icon for performance
1469
+ createIcon: function () {
1470
+ if (this._iconNeedsUpdate) {
1471
+ this._iconObj = this._group.options.iconCreateFunction(this);
1472
+ this._iconNeedsUpdate = false;
1473
+ }
1474
+ return this._iconObj.createIcon();
1475
+ },
1476
+ createShadow: function () {
1477
+ return this._iconObj.createShadow();
1478
+ },
1479
+
1480
+
1481
+ _addChild: function (new1, isNotificationFromChild) {
1482
+
1483
+ this._iconNeedsUpdate = true;
1484
+
1485
+ this._boundsNeedUpdate = true;
1486
+ this._setClusterCenter(new1);
1487
+
1488
+ if (new1 instanceof BM.MarkerCluster) {
1489
+ if (!isNotificationFromChild) {
1490
+ this._childClusters.push(new1);
1491
+ new1.__parent = this;
1492
+ }
1493
+ this._childCount += new1._childCount;
1494
+ } else {
1495
+ if (!isNotificationFromChild) {
1496
+ this._markers.push(new1);
1497
+ }
1498
+ this._childCount++;
1499
+ }
1500
+
1501
+ if (this.__parent) {
1502
+ this.__parent._addChild(new1, true);
1503
+ }
1504
+ },
1505
+
1506
+ /**
1507
+ * Makes sure the cluster center is set. If not, uses the child center if it is a cluster, or the marker position.
1508
+ * @param child BM.MarkerCluster|BM.Marker that will be used as cluster center if not defined yet.
1509
+ * @private
1510
+ */
1511
+ _setClusterCenter: function (child) {
1512
+ if (!this._cLatLng) {
1513
+ // when clustering, take position of the first point as the cluster center
1514
+ this._cLatLng = child._cLatLng || child._latlng;
1515
+ }
1516
+ },
1517
+
1518
+ /**
1519
+ * Assigns impossible bounding values so that the next extend entirely determines the new bounds.
1520
+ * This method avoids having to trash the previous BM.LatLngBounds object and to create a new one, which is much slower for this class.
1521
+ * As long as the bounds are not extended, most other methods would probably fail, as they would with bounds initialized but not extended.
1522
+ * @private
1523
+ */
1524
+ _resetBounds: function () {
1525
+ var bounds = this._bounds;
1526
+
1527
+ if (bounds._southWest) {
1528
+ bounds._southWest.lat = Infinity;
1529
+ bounds._southWest.lng = Infinity;
1530
+ }
1531
+ if (bounds._northEast) {
1532
+ bounds._northEast.lat = -Infinity;
1533
+ bounds._northEast.lng = -Infinity;
1534
+ }
1535
+ },
1536
+
1537
+ _recalculateBounds: function () {
1538
+ var markers = this._markers,
1539
+ childClusters = this._childClusters,
1540
+ latSum = 0,
1541
+ lngSum = 0,
1542
+ totalCount = this._childCount,
1543
+ i, child, childLatLng, childCount;
1544
+
1545
+ // Case where all markers are removed from the map and we are left with just an empty _topClusterLevel.
1546
+ if (totalCount === 0) {
1547
+ return;
1548
+ }
1549
+
1550
+ // Reset rather than creating a new object, for performance.
1551
+ this._resetBounds();
1552
+
1553
+ // Child markers.
1554
+ for (i = 0; i < markers.length; i++) {
1555
+ childLatLng = markers[i]._latlng;
1556
+
1557
+ this._bounds.extend(childLatLng);
1558
+
1559
+ latSum += childLatLng.lat;
1560
+ lngSum += childLatLng.lng;
1561
+ }
1562
+
1563
+ // Child clusters.
1564
+ for (i = 0; i < childClusters.length; i++) {
1565
+ child = childClusters[i];
1566
+
1567
+ // Re-compute child bounds and weighted position first if necessary.
1568
+ if (child._boundsNeedUpdate) {
1569
+ child._recalculateBounds();
1570
+ }
1571
+
1572
+ this._bounds.extend(child._bounds);
1573
+
1574
+ childLatLng = child._wLatLng;
1575
+ childCount = child._childCount;
1576
+
1577
+ latSum += childLatLng.lat * childCount;
1578
+ lngSum += childLatLng.lng * childCount;
1579
+ }
1580
+
1581
+ this._latlng = this._wLatLng = new BM.LatLng(latSum / totalCount, lngSum / totalCount);
1582
+
1583
+ // Reset dirty flag.
1584
+ this._boundsNeedUpdate = false;
1585
+ },
1586
+
1587
+ //Set our markers position as given and add it to the map
1588
+ _addToMap: function (startPos) {
1589
+ if (startPos) {
1590
+ this._backupLatlng = this._latlng;
1591
+ this.setLatLng(startPos);
1592
+ }
1593
+ this._group._featureGroup.addLayer(this);
1594
+ },
1595
+
1596
+ _recursivelyAnimateChildrenIn: function (bounds, center, maxZoom) {
1597
+ this._recursively(bounds, this._group._map.getMinZoom(), maxZoom - 1,
1598
+ function (c) {
1599
+ var markers = c._markers,
1600
+ i, m;
1601
+ for (i = markers.length - 1; i >= 0; i--) {
1602
+ m = markers[i];
1603
+
1604
+ //Only do it if the icon is still on the map
1605
+ if (m._icon) {
1606
+ m._setPos(center);
1607
+ m.clusterHide();
1608
+ }
1609
+ }
1610
+ },
1611
+ function (c) {
1612
+ var childClusters = c._childClusters,
1613
+ j, cm;
1614
+ for (j = childClusters.length - 1; j >= 0; j--) {
1615
+ cm = childClusters[j];
1616
+ if (cm._icon) {
1617
+ cm._setPos(center);
1618
+ cm.clusterHide();
1619
+ }
1620
+ }
1621
+ }
1622
+ );
1623
+ },
1624
+
1625
+ _recursivelyAnimateChildrenInAndAddSelfToMap: function (bounds, mapMinZoom, previousZoomLevel, newZoomLevel) {
1626
+ this._recursively(bounds, newZoomLevel, mapMinZoom,
1627
+ function (c) {
1628
+ c._recursivelyAnimateChildrenIn(bounds, c._group._map.latLngToLayerPoint(c.getLatLng()).round(), previousZoomLevel);
1629
+
1630
+ //TODO: depthToAnimateIn affects _isSingleParent, if there is a multizoom we may/may not be.
1631
+ //As a hack we only do a animation free zoom on a single level zoom, if someone does multiple levels then we always animate
1632
+ if (c._isSingleParent() && previousZoomLevel - 1 === newZoomLevel) {
1633
+ c.clusterShow();
1634
+ c._recursivelyRemoveChildrenFromMap(bounds, mapMinZoom, previousZoomLevel); //Immediately remove our children as we are replacing them. TODO previousBounds not bounds
1635
+ } else {
1636
+ c.clusterHide();
1637
+ }
1638
+
1639
+ c._addToMap();
1640
+ }
1641
+ );
1642
+ },
1643
+
1644
+ _recursivelyBecomeVisible: function (bounds, zoomLevel) {
1645
+ this._recursively(bounds, this._group._map.getMinZoom(), zoomLevel, null, function (c) {
1646
+ c.clusterShow();
1647
+ });
1648
+ },
1649
+
1650
+ _recursivelyAddChildrenToMap: function (startPos, zoomLevel, bounds) {
1651
+ this._recursively(bounds, this._group._map.getMinZoom() - 1, zoomLevel,
1652
+ function (c) {
1653
+ if (zoomLevel === c._zoom) {
1654
+ return;
1655
+ }
1656
+
1657
+ //Add our child markers at startPos (so they can be animated out)
1658
+ for (var i = c._markers.length - 1; i >= 0; i--) {
1659
+ var nm = c._markers[i];
1660
+
1661
+ if (!bounds.contains(nm._latlng)) {
1662
+ continue;
1663
+ }
1664
+
1665
+ if (startPos) {
1666
+ nm._backupLatlng = nm.getLatLng();
1667
+
1668
+ nm.setLatLng(startPos);
1669
+ if (nm.clusterHide) {
1670
+ nm.clusterHide();
1671
+ }
1672
+ }
1673
+
1674
+ c._group._featureGroup.addLayer(nm);
1675
+ }
1676
+ },
1677
+ function (c) {
1678
+ c._addToMap(startPos);
1679
+ }
1680
+ );
1681
+ },
1682
+
1683
+ _recursivelyRestoreChildPositions: function (zoomLevel) {
1684
+ //Fix positions of child markers
1685
+ for (var i = this._markers.length - 1; i >= 0; i--) {
1686
+ var nm = this._markers[i];
1687
+ if (nm._backupLatlng) {
1688
+ nm.setLatLng(nm._backupLatlng);
1689
+ delete nm._backupLatlng;
1690
+ }
1691
+ }
1692
+
1693
+ if (zoomLevel - 1 === this._zoom) {
1694
+ //Reposition child clusters
1695
+ for (var j = this._childClusters.length - 1; j >= 0; j--) {
1696
+ this._childClusters[j]._restorePosition();
1697
+ }
1698
+ } else {
1699
+ for (var k = this._childClusters.length - 1; k >= 0; k--) {
1700
+ this._childClusters[k]._recursivelyRestoreChildPositions(zoomLevel);
1701
+ }
1702
+ }
1703
+ },
1704
+
1705
+ _restorePosition: function () {
1706
+ if (this._backupLatlng) {
1707
+ this.setLatLng(this._backupLatlng);
1708
+ delete this._backupLatlng;
1709
+ }
1710
+ },
1711
+
1712
+ //exceptBounds: If set, don't remove any markers/clusters in it
1713
+ _recursivelyRemoveChildrenFromMap: function (previousBounds, mapMinZoom, zoomLevel, exceptBounds) {
1714
+ var m, i;
1715
+ this._recursively(previousBounds, mapMinZoom - 1, zoomLevel - 1,
1716
+ function (c) {
1717
+ //Remove markers at every level
1718
+ for (i = c._markers.length - 1; i >= 0; i--) {
1719
+ m = c._markers[i];
1720
+ if (!exceptBounds || !exceptBounds.contains(m._latlng)) {
1721
+ c._group._featureGroup.removeLayer(m);
1722
+ if (m.clusterShow) {
1723
+ m.clusterShow();
1724
+ }
1725
+ }
1726
+ }
1727
+ },
1728
+ function (c) {
1729
+ //Remove child clusters at just the bottom level
1730
+ for (i = c._childClusters.length - 1; i >= 0; i--) {
1731
+ m = c._childClusters[i];
1732
+ if (!exceptBounds || !exceptBounds.contains(m._latlng)) {
1733
+ c._group._featureGroup.removeLayer(m);
1734
+ if (m.clusterShow) {
1735
+ m.clusterShow();
1736
+ }
1737
+ }
1738
+ }
1739
+ }
1740
+ );
1741
+ },
1742
+
1743
+ //Run the given functions recursively to this and child clusters
1744
+ // boundsToApplyTo: a BM.LatLngBounds representing the bounds of what clusters to recurse in to
1745
+ // zoomLevelToStart: zoom level to start running functions (inclusive)
1746
+ // zoomLevelToStop: zoom level to stop running functions (inclusive)
1747
+ // runAtEveryLevel: function that takes an BM.MarkerCluster as an argument that should be applied on every level
1748
+ // runAtBottomLevel: function that takes an BM.MarkerCluster as an argument that should be applied at only the bottom level
1749
+ _recursively: function (boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel) {
1750
+ var childClusters = this._childClusters,
1751
+ zoom = this._zoom,
1752
+ i, c;
1753
+
1754
+ if (zoomLevelToStart <= zoom) {
1755
+ if (runAtEveryLevel) {
1756
+ runAtEveryLevel(this);
1757
+ }
1758
+ if (runAtBottomLevel && zoom === zoomLevelToStop) {
1759
+ runAtBottomLevel(this);
1760
+ }
1761
+ }
1762
+
1763
+ if (zoom < zoomLevelToStart || zoom < zoomLevelToStop) {
1764
+ for (i = childClusters.length - 1; i >= 0; i--) {
1765
+ c = childClusters[i];
1766
+ if (c._boundsNeedUpdate) {
1767
+ c._recalculateBounds();
1768
+ }
1769
+ if (boundsToApplyTo.intersects(c._bounds)) {
1770
+ c._recursively(boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel);
1771
+ }
1772
+ }
1773
+ }
1774
+ },
1775
+
1776
+ //Returns true if we are the parent of only one cluster and that cluster is the same as us
1777
+ _isSingleParent: function () {
1778
+ //Don't need to check this._markers as the rest won't work if there are any
1779
+ return this._childClusters.length > 0 && this._childClusters[0]._childCount === this._childCount;
1780
+ }
1781
+ });
1782
+
1783
+ /*
1784
+ * Extends BM.Marker to include two extra methods: clusterHide and clusterShow.
1785
+ *
1786
+ * They work as setOpacity(0) and setOpacity(1) respectively, but
1787
+ * don't overwrite the options.opacity
1788
+ *
1789
+ */
1790
+
1791
+ BM.Marker.include({
1792
+ clusterHide: function () {
1793
+ var backup = this.options.opacity;
1794
+ this.setOpacity(0);
1795
+ this.options.opacity = backup;
1796
+ return this;
1797
+ },
1798
+
1799
+ clusterShow: function () {
1800
+ return this.setOpacity(this.options.opacity);
1801
+ }
1802
+ });
1803
+
1804
+ BM.DistanceGrid = function (cellSize) {
1805
+ this._cellSize = cellSize;
1806
+ this._sqCellSize = cellSize * cellSize;
1807
+ this._grid = {};
1808
+ this._objectPoint = { };
1809
+ };
1810
+
1811
+ BM.DistanceGrid.prototype = {
1812
+
1813
+ addObject: function (obj, point) {
1814
+ var x = this._getCoord(point.x),
1815
+ y = this._getCoord(point.y),
1816
+ grid = this._grid,
1817
+ row = grid[y] = grid[y] || {},
1818
+ cell = row[x] = row[x] || [],
1819
+ stamp = BM.Util.stamp(obj);
1820
+
1821
+ this._objectPoint[stamp] = point;
1822
+
1823
+ cell.push(obj);
1824
+ },
1825
+
1826
+ updateObject: function (obj, point) {
1827
+ this.removeObject(obj);
1828
+ this.addObject(obj, point);
1829
+ },
1830
+
1831
+ //Returns true if the object was found
1832
+ removeObject: function (obj, point) {
1833
+ var x = this._getCoord(point.x),
1834
+ y = this._getCoord(point.y),
1835
+ grid = this._grid,
1836
+ row = grid[y] = grid[y] || {},
1837
+ cell = row[x] = row[x] || [],
1838
+ i, len;
1839
+
1840
+ delete this._objectPoint[BM.Util.stamp(obj)];
1841
+
1842
+ for (i = 0, len = cell.length; i < len; i++) {
1843
+ if (cell[i] === obj) {
1844
+
1845
+ cell.splice(i, 1);
1846
+
1847
+ if (len === 1) {
1848
+ delete row[x];
1849
+ }
1850
+
1851
+ return true;
1852
+ }
1853
+ }
1854
+
1855
+ },
1856
+
1857
+ eachObject: function (fn, context) {
1858
+ var i, j, k, len, row, cell, removed,
1859
+ grid = this._grid;
1860
+
1861
+ for (i in grid) {
1862
+ row = grid[i];
1863
+
1864
+ for (j in row) {
1865
+ cell = row[j];
1866
+
1867
+ for (k = 0, len = cell.length; k < len; k++) {
1868
+ removed = fn.call(context, cell[k]);
1869
+ if (removed) {
1870
+ k--;
1871
+ len--;
1872
+ }
1873
+ }
1874
+ }
1875
+ }
1876
+ },
1877
+
1878
+ getNearObject: function (point) {
1879
+ var x = this._getCoord(point.x),
1880
+ y = this._getCoord(point.y),
1881
+ i, j, k, row, cell, len, obj, dist,
1882
+ objectPoint = this._objectPoint,
1883
+ closestDistSq = this._sqCellSize,
1884
+ closest = null;
1885
+
1886
+ for (i = y - 1; i <= y + 1; i++) {
1887
+ row = this._grid[i];
1888
+ if (row) {
1889
+
1890
+ for (j = x - 1; j <= x + 1; j++) {
1891
+ cell = row[j];
1892
+ if (cell) {
1893
+
1894
+ for (k = 0, len = cell.length; k < len; k++) {
1895
+ obj = cell[k];
1896
+ dist = this._sqDist(objectPoint[BM.Util.stamp(obj)], point);
1897
+ if (dist < closestDistSq ||
1898
+ dist <= closestDistSq && closest === null) {
1899
+ closestDistSq = dist;
1900
+ closest = obj;
1901
+ }
1902
+ }
1903
+ }
1904
+ }
1905
+ }
1906
+ }
1907
+ return closest;
1908
+ },
1909
+
1910
+ _getCoord: function (x) {
1911
+ var coord = Math.floor(x / this._cellSize);
1912
+ return isFinite(coord) ? coord : x;
1913
+ },
1914
+
1915
+ _sqDist: function (p, p2) {
1916
+ var dx = p2.x - p.x,
1917
+ dy = p2.y - p.y;
1918
+ return dx * dx + dy * dy;
1919
+ }
1920
+ };
1921
+
1922
+ /* Copyright (c) 2012 the authors listed at the following URL, and/or
1923
+ the authors of referenced articles or incorporated external code:
1924
+ http://en.literateprograms.org/Quickhull_(Javascript)?action=history&offset=20120410175256
1925
+
1926
+ Permission is hereby granted, free of charge, to any person obtaining
1927
+ a copy of this software and associated documentation files (the
1928
+ "Software"), to deal in the Software without restriction, including
1929
+ without limitation the rights to use, copy, modify, merge, publish,
1930
+ distribute, sublicense, and/or sell copies of the Software, and to
1931
+ permit persons to whom the Software is furnished to do so, subject to
1932
+ the following conditions:
1933
+
1934
+ The above copyright notice and this permission notice shall be
1935
+ included in all copies or substantial portions of the Software.
1936
+
1937
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1938
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1939
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1940
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1941
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1942
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1943
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1944
+
1945
+ Retrieved from: http://en.literateprograms.org/Quickhull_(Javascript)?oldid=18434
1946
+ */
1947
+
1948
+ (function () {
1949
+ BM.QuickHull = {
1950
+
1951
+ /*
1952
+ * @param {Object} cpt a point to be measured from the baseline
1953
+ * @param {Array} bl the baseline, as represented by a two-element
1954
+ * array of latlng objects.
1955
+ * @returns {Number} an approximate distance measure
1956
+ */
1957
+ getDistant: function (cpt, bl) {
1958
+ var vY = bl[1].lat - bl[0].lat,
1959
+ vX = bl[0].lng - bl[1].lng;
1960
+ return (vX * (cpt.lat - bl[0].lat) + vY * (cpt.lng - bl[0].lng));
1961
+ },
1962
+
1963
+ /*
1964
+ * @param {Array} baseLine a two-element array of latlng objects
1965
+ * representing the baseline to project from
1966
+ * @param {Array} latLngs an array of latlng objects
1967
+ * @returns {Object} the maximum point and all new points to stay
1968
+ * in consideration for the hull.
1969
+ */
1970
+ findMostDistantPointFromBaseLine: function (baseLine, latLngs) {
1971
+ var maxD = 0,
1972
+ maxPt = null,
1973
+ newPoints = [],
1974
+ i, pt, d;
1975
+
1976
+ for (i = latLngs.length - 1; i >= 0; i--) {
1977
+ pt = latLngs[i];
1978
+ d = this.getDistant(pt, baseLine);
1979
+
1980
+ if (d > 0) {
1981
+ newPoints.push(pt);
1982
+ } else {
1983
+ continue;
1984
+ }
1985
+
1986
+ if (d > maxD) {
1987
+ maxD = d;
1988
+ maxPt = pt;
1989
+ }
1990
+ }
1991
+
1992
+ return { maxPoint: maxPt, newPoints: newPoints };
1993
+ },
1994
+
1995
+
1996
+ /*
1997
+ * Given a baseline, compute the convex hull of latLngs as an array
1998
+ * of latLngs.
1999
+ *
2000
+ * @param {Array} latLngs
2001
+ * @returns {Array}
2002
+ */
2003
+ buildConvexHull: function (baseLine, latLngs) {
2004
+ var convexHullBaseLines = [],
2005
+ t = this.findMostDistantPointFromBaseLine(baseLine, latLngs);
2006
+
2007
+ if (t.maxPoint) { // if there is still a point "outside" the base line
2008
+ convexHullBaseLines =
2009
+ convexHullBaseLines.concat(
2010
+ this.buildConvexHull([baseLine[0], t.maxPoint], t.newPoints)
2011
+ );
2012
+ convexHullBaseLines =
2013
+ convexHullBaseLines.concat(
2014
+ this.buildConvexHull([t.maxPoint, baseLine[1]], t.newPoints)
2015
+ );
2016
+ return convexHullBaseLines;
2017
+ } else { // if there is no more point "outside" the base line, the current base line is part of the convex hull
2018
+ return [baseLine[0]];
2019
+ }
2020
+ },
2021
+
2022
+ /*
2023
+ * Given an array of latlngs, compute a convex hull as an array
2024
+ * of latlngs
2025
+ *
2026
+ * @param {Array} latLngs
2027
+ * @returns {Array}
2028
+ */
2029
+ getConvexHull: function (latLngs) {
2030
+ // find first baseline
2031
+ var maxLat = false, minLat = false,
2032
+ maxLng = false, minLng = false,
2033
+ maxLatPt = null, minLatPt = null,
2034
+ maxLngPt = null, minLngPt = null,
2035
+ maxPt = null, minPt = null,
2036
+ i;
2037
+
2038
+ for (i = latLngs.length - 1; i >= 0; i--) {
2039
+ var pt = latLngs[i];
2040
+ if (maxLat === false || pt.lat > maxLat) {
2041
+ maxLatPt = pt;
2042
+ maxLat = pt.lat;
2043
+ }
2044
+ if (minLat === false || pt.lat < minLat) {
2045
+ minLatPt = pt;
2046
+ minLat = pt.lat;
2047
+ }
2048
+ if (maxLng === false || pt.lng > maxLng) {
2049
+ maxLngPt = pt;
2050
+ maxLng = pt.lng;
2051
+ }
2052
+ if (minLng === false || pt.lng < minLng) {
2053
+ minLngPt = pt;
2054
+ minLng = pt.lng;
2055
+ }
2056
+ }
2057
+
2058
+ if (minLat !== maxLat) {
2059
+ minPt = minLatPt;
2060
+ maxPt = maxLatPt;
2061
+ } else {
2062
+ minPt = minLngPt;
2063
+ maxPt = maxLngPt;
2064
+ }
2065
+
2066
+ var ch = [].concat(this.buildConvexHull([minPt, maxPt], latLngs),
2067
+ this.buildConvexHull([maxPt, minPt], latLngs));
2068
+ return ch;
2069
+ }
2070
+ };
2071
+ }());
2072
+
2073
+ BM.MarkerCluster.include({
2074
+ getConvexHull: function () {
2075
+ var childMarkers = this.getAllChildMarkers(),
2076
+ points = [],
2077
+ p, i;
2078
+
2079
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2080
+ p = childMarkers[i].getLatLng();
2081
+ points.push(p);
2082
+ }
2083
+
2084
+ return BM.QuickHull.getConvexHull(points);
2085
+ }
2086
+ });
2087
+
2088
+ //This code is 100% based on https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet
2089
+ //Huge thanks to jawj for implementing it first to make my job easy :-)
2090
+
2091
+ BM.MarkerCluster.include({
2092
+
2093
+ _2PI: Math.PI * 2,
2094
+ _circleFootSeparation: 25, //related to circumference of circle
2095
+ _circleStartAngle: 0,
2096
+
2097
+ _spiralFootSeparation: 28, //related to size of spiral (experiment!)
2098
+ _spiralLengthStart: 11,
2099
+ _spiralLengthFactor: 5,
2100
+
2101
+ _circleSpiralSwitchover: 9, //show spiral instead of circle from this marker count upwards.
2102
+ // 0 -> always spiral; Infinity -> always circle
2103
+
2104
+ spiderfy: function () {
2105
+ if (this._group._spiderfied === this || this._group._inZoomAnimation) {
2106
+ return;
2107
+ }
2108
+
2109
+ var childMarkers = this.getAllChildMarkers(null, true),
2110
+ group = this._group,
2111
+ map = group._map,
2112
+ center = map.latLngToLayerPoint(this._latlng),
2113
+ positions;
2114
+
2115
+ this._group._unspiderfy();
2116
+ this._group._spiderfied = this;
2117
+
2118
+ //TODO Maybe: childMarkers order by distance to center
2119
+
2120
+ if (childMarkers.length >= this._circleSpiralSwitchover) {
2121
+ positions = this._generatePointsSpiral(childMarkers.length, center);
2122
+ } else {
2123
+ center.y += 10; // Otherwise circles look wrong => hack for standard blue icon, renders differently for other icons.
2124
+ positions = this._generatePointsCircle(childMarkers.length, center);
2125
+ }
2126
+
2127
+ this._animationSpiderfy(childMarkers, positions);
2128
+ },
2129
+
2130
+ unspiderfy: function (zoomDetails) {
2131
+ /// <param Name="zoomDetails">Argument from zoomanim if being called in a zoom animation or null otherwise</param>
2132
+ if (this._group._inZoomAnimation) {
2133
+ return;
2134
+ }
2135
+ this._animationUnspiderfy(zoomDetails);
2136
+
2137
+ this._group._spiderfied = null;
2138
+ },
2139
+
2140
+ _generatePointsCircle: function (count, centerPt) {
2141
+ var circumference = this._group.options.spiderfyDistanceMultiplier * this._circleFootSeparation * (2 + count),
2142
+ legLength = circumference / this._2PI, //radius from circumference
2143
+ angleStep = this._2PI / count,
2144
+ res = [],
2145
+ i, angle;
2146
+
2147
+ legLength = Math.max(legLength, 35); // Minimum distance to get outside the cluster icon.
2148
+
2149
+ res.length = count;
2150
+
2151
+ for (i = 0; i < count; i++) { // Clockwise, like spiral.
2152
+ angle = this._circleStartAngle + i * angleStep;
2153
+ res[i] = new BM.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round();
2154
+ }
2155
+
2156
+ return res;
2157
+ },
2158
+
2159
+ _generatePointsSpiral: function (count, centerPt) {
2160
+ var spiderfyDistanceMultiplier = this._group.options.spiderfyDistanceMultiplier,
2161
+ legLength = spiderfyDistanceMultiplier * this._spiralLengthStart,
2162
+ separation = spiderfyDistanceMultiplier * this._spiralFootSeparation,
2163
+ lengthFactor = spiderfyDistanceMultiplier * this._spiralLengthFactor * this._2PI,
2164
+ angle = 0,
2165
+ res = [],
2166
+ i;
2167
+
2168
+ res.length = count;
2169
+
2170
+ // Higher index, closer position to cluster center.
2171
+ for (i = count; i >= 0; i--) {
2172
+ // Skip the first position, so that we are already farther from center and we avoid
2173
+ // being under the default cluster icon (especially important for Circle Markers).
2174
+ if (i < count) {
2175
+ res[i] = new BM.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round();
2176
+ }
2177
+ angle += separation / legLength + i * 0.0005;
2178
+ legLength += lengthFactor / angle;
2179
+ }
2180
+ return res;
2181
+ },
2182
+
2183
+ _noanimationUnspiderfy: function () {
2184
+ var group = this._group,
2185
+ map = group._map,
2186
+ fg = group._featureGroup,
2187
+ childMarkers = this.getAllChildMarkers(null, true),
2188
+ m, i;
2189
+
2190
+ group._ignoreMove = true;
2191
+
2192
+ this.setOpacity(1);
2193
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2194
+ m = childMarkers[i];
2195
+
2196
+ fg.removeLayer(m);
2197
+
2198
+ if (m._preSpiderfyLatlng) {
2199
+ m.setLatLng(m._preSpiderfyLatlng);
2200
+ delete m._preSpiderfyLatlng;
2201
+ }
2202
+ if (m.setZIndexOffset) {
2203
+ m.setZIndexOffset(0);
2204
+ }
2205
+
2206
+ if (m._spiderLeg) {
2207
+ map.removeLayer(m._spiderLeg);
2208
+ delete m._spiderLeg;
2209
+ }
2210
+ }
2211
+
2212
+ group.fire('unspiderfied', {
2213
+ cluster: this,
2214
+ markers: childMarkers
2215
+ });
2216
+ group._ignoreMove = false;
2217
+ group._spiderfied = null;
2218
+ }
2219
+ });
2220
+
2221
+ //Non Animated versions of everything
2222
+ BM.MarkerClusterNonAnimated = BM.MarkerCluster.extend({
2223
+ _animationSpiderfy: function (childMarkers, positions) {
2224
+ var group = this._group,
2225
+ map = group._map,
2226
+ fg = group._featureGroup,
2227
+ legOptions = this._group.options.spiderLegPolylineOptions,
2228
+ i, m, leg, newPos;
2229
+
2230
+ group._ignoreMove = true;
2231
+
2232
+ // Traverse in ascending order to make sure that inner circleMarkers are on top of further legs. Normal markers are re-ordered by newPosition.
2233
+ // The reverse order trick no longer improves performance on modern browsers.
2234
+ for (i = 0; i < childMarkers.length; i++) {
2235
+ newPos = map.layerPointToLatLng(positions[i]);
2236
+ m = childMarkers[i];
2237
+
2238
+ // Add the leg before the marker, so that in case the latter is a circleMarker, the leg is behind it.
2239
+ leg = new BM.Polyline([this._latlng, newPos], legOptions);
2240
+ map.addLayer(leg);
2241
+ m._spiderLeg = leg;
2242
+
2243
+ // Now add the marker.
2244
+ m._preSpiderfyLatlng = m._latlng;
2245
+ m.setLatLng(newPos);
2246
+ if (m.setZIndexOffset) {
2247
+ m.setZIndexOffset(1000000); //Make these appear on top of EVERYTHING
2248
+ }
2249
+
2250
+ fg.addLayer(m);
2251
+ }
2252
+ this.setOpacity(0.3);
2253
+
2254
+ group._ignoreMove = false;
2255
+ group.fire('spiderfied', {
2256
+ cluster: this,
2257
+ markers: childMarkers
2258
+ });
2259
+ },
2260
+
2261
+ _animationUnspiderfy: function () {
2262
+ this._noanimationUnspiderfy();
2263
+ }
2264
+ });
2265
+
2266
+ //Animated versions here
2267
+ BM.MarkerCluster.include({
2268
+
2269
+ _animationSpiderfy: function (childMarkers, positions) {
2270
+ var me = this,
2271
+ group = this._group,
2272
+ map = group._map,
2273
+ fg = group._featureGroup,
2274
+ thisLayerLatLng = this._latlng,
2275
+ thisLayerPos = map.latLngToLayerPoint(thisLayerLatLng),
2276
+ svg = BM.Path.SVG,
2277
+ legOptions = BM.extend({}, this._group.options.spiderLegPolylineOptions), // Copy the options so that we can modify them for animation.
2278
+ finalLegOpacity = legOptions.opacity,
2279
+ i, m, leg, legPath, legLength, newPos;
2280
+
2281
+ if (finalLegOpacity === undefined) {
2282
+ finalLegOpacity = BM.MarkerClusterGroup.prototype.options.spiderLegPolylineOptions.opacity;
2283
+ }
2284
+
2285
+ if (svg) {
2286
+ // If the initial opacity of the spider leg is not 0 then it appears before the animation starts.
2287
+ legOptions.opacity = 0;
2288
+
2289
+ // Add the class for CSS transitions.
2290
+ legOptions.className = (legOptions.className || '') + ' leaflet-cluster-spider-leg';
2291
+ } else {
2292
+ // Make sure we have a defined opacity.
2293
+ legOptions.opacity = finalLegOpacity;
2294
+ }
2295
+
2296
+ group._ignoreMove = true;
2297
+
2298
+ // Add markers and spider legs to map, hidden at our center point.
2299
+ // Traverse in ascending order to make sure that inner circleMarkers are on top of further legs. Normal markers are re-ordered by newPosition.
2300
+ // The reverse order trick no longer improves performance on modern browsers.
2301
+ for (i = 0; i < childMarkers.length; i++) {
2302
+ m = childMarkers[i];
2303
+
2304
+ newPos = map.layerPointToLatLng(positions[i]);
2305
+
2306
+ // Add the leg before the marker, so that in case the latter is a circleMarker, the leg is behind it.
2307
+ leg = new BM.Polyline([thisLayerLatLng, newPos], legOptions);
2308
+ map.addLayer(leg);
2309
+ m._spiderLeg = leg;
2310
+
2311
+ // Explanations: https://jakearchibald.com/2013/animated-line-drawing-svg/
2312
+ // In our case the transition property is declared in the CSS file.
2313
+ if (svg) {
2314
+ legPath = leg._path;
2315
+ legLength = legPath.getTotalLength() + 0.1; // Need a small extra length to avoid remaining dot in Firefox.
2316
+ legPath.style.strokeDasharray = legLength; // Just 1 length is enough, it will be duplicated.
2317
+ legPath.style.strokeDashoffset = legLength;
2318
+ }
2319
+
2320
+ // If it is a marker, add it now and we'll animate it out
2321
+ if (m.setZIndexOffset) {
2322
+ m.setZIndexOffset(1000000); // Make normal markers appear on top of EVERYTHING
2323
+ }
2324
+ if (m.clusterHide) {
2325
+ m.clusterHide();
2326
+ }
2327
+
2328
+ // Vectors just get immediately added
2329
+ fg.addLayer(m);
2330
+
2331
+ if (m._setPos) {
2332
+ m._setPos(thisLayerPos);
2333
+ }
2334
+ }
2335
+
2336
+ group._forceLayout();
2337
+ group._animationStart();
2338
+
2339
+ // Reveal markers and spider legs.
2340
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2341
+ newPos = map.layerPointToLatLng(positions[i]);
2342
+ m = childMarkers[i];
2343
+
2344
+ //Move marker to new position
2345
+ m._preSpiderfyLatlng = m._latlng;
2346
+ m.setLatLng(newPos);
2347
+
2348
+ if (m.clusterShow) {
2349
+ m.clusterShow();
2350
+ }
2351
+
2352
+ // Animate leg (animation is actually delegated to CSS transition).
2353
+ if (svg) {
2354
+ leg = m._spiderLeg;
2355
+ legPath = leg._path;
2356
+ legPath.style.strokeDashoffset = 0;
2357
+ //legPath.style.strokeOpacity = finalLegOpacity;
2358
+ leg.setStyle({opacity: finalLegOpacity});
2359
+ }
2360
+ }
2361
+ this.setOpacity(0.3);
2362
+
2363
+ group._ignoreMove = false;
2364
+
2365
+ setTimeout(function () {
2366
+ group._animationEnd();
2367
+ group.fire('spiderfied', {
2368
+ cluster: me,
2369
+ markers: childMarkers
2370
+ });
2371
+ }, 200);
2372
+ },
2373
+
2374
+ _animationUnspiderfy: function (zoomDetails) {
2375
+ var me = this,
2376
+ group = this._group,
2377
+ map = group._map,
2378
+ fg = group._featureGroup,
2379
+ thisLayerPos = zoomDetails ? map._latLngToNewLayerPoint(this._latlng, zoomDetails.zoom, zoomDetails.center) : map.latLngToLayerPoint(this._latlng),
2380
+ childMarkers = this.getAllChildMarkers(null, true),
2381
+ svg = BM.Path.SVG,
2382
+ m, i, leg, legPath, legLength, nonAnimatable;
2383
+
2384
+ group._ignoreMove = true;
2385
+ group._animationStart();
2386
+
2387
+ //Make us visible and bring the child markers back in
2388
+ this.setOpacity(1);
2389
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2390
+ m = childMarkers[i];
2391
+
2392
+ //Marker was added to us after we were spiderfied
2393
+ if (!m._preSpiderfyLatlng) {
2394
+ continue;
2395
+ }
2396
+
2397
+ //Close any popup on the marker first, otherwise setting the location of the marker will make the map scroll
2398
+ m.closePopup();
2399
+
2400
+ //Fix up the location to the real one
2401
+ m.setLatLng(m._preSpiderfyLatlng);
2402
+ delete m._preSpiderfyLatlng;
2403
+
2404
+ //Hack override the location to be our center
2405
+ nonAnimatable = true;
2406
+ if (m._setPos) {
2407
+ m._setPos(thisLayerPos);
2408
+ nonAnimatable = false;
2409
+ }
2410
+ if (m.clusterHide) {
2411
+ m.clusterHide();
2412
+ nonAnimatable = false;
2413
+ }
2414
+ if (nonAnimatable) {
2415
+ fg.removeLayer(m);
2416
+ }
2417
+
2418
+ // Animate the spider leg back in (animation is actually delegated to CSS transition).
2419
+ if (svg) {
2420
+ leg = m._spiderLeg;
2421
+ legPath = leg._path;
2422
+ legLength = legPath.getTotalLength() + 0.1;
2423
+ legPath.style.strokeDashoffset = legLength;
2424
+ leg.setStyle({opacity: 0});
2425
+ }
2426
+ }
2427
+
2428
+ group._ignoreMove = false;
2429
+
2430
+ setTimeout(function () {
2431
+ //If we have only <= one child left then that marker will be shown on the map so don't remove it!
2432
+ var stillThereChildCount = 0;
2433
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2434
+ m = childMarkers[i];
2435
+ if (m._spiderLeg) {
2436
+ stillThereChildCount++;
2437
+ }
2438
+ }
2439
+
2440
+
2441
+ for (i = childMarkers.length - 1; i >= 0; i--) {
2442
+ m = childMarkers[i];
2443
+
2444
+ if (!m._spiderLeg) { //Has already been unspiderfied
2445
+ continue;
2446
+ }
2447
+
2448
+ if (m.clusterShow) {
2449
+ m.clusterShow();
2450
+ }
2451
+ if (m.setZIndexOffset) {
2452
+ m.setZIndexOffset(0);
2453
+ }
2454
+
2455
+ if (stillThereChildCount > 1) {
2456
+ fg.removeLayer(m);
2457
+ }
2458
+
2459
+ map.removeLayer(m._spiderLeg);
2460
+ delete m._spiderLeg;
2461
+ }
2462
+ group._animationEnd();
2463
+ group.fire('unspiderfied', {
2464
+ cluster: me,
2465
+ markers: childMarkers
2466
+ });
2467
+ }, 200);
2468
+ }
2469
+ });
2470
+
2471
+
2472
+ BM.MarkerClusterGroup.include({
2473
+ //The MarkerCluster currently spiderfied (if any)
2474
+ _spiderfied: null,
2475
+
2476
+ unspiderfy: function () {
2477
+ this._unspiderfy.apply(this, arguments);
2478
+ },
2479
+
2480
+ _spiderfierOnAdd: function () {
2481
+ this._map.on('click', this._unspiderfyWrapper, this);
2482
+
2483
+ if (this._map.options.zoomAnimation) {
2484
+ this._map.on('zoomstart', this._unspiderfyZoomStart, this);
2485
+ }
2486
+ //Browsers without zoomAnimation or a big zoom don't fire zoomstart
2487
+ this._map.on('zoomend', this._noanimationUnspiderfy, this);
2488
+
2489
+ if (!BM.Browser.touch) {
2490
+ this._map.getRenderer(this);
2491
+ //Needs to happen in the pageload, not after, or animations don't work in webkit
2492
+ // http://stackoverflow.com/questions/8455200/svg-animate-with-dynamically-added-elements
2493
+ //Disable on touch browsers as the animation messes up on a touch zoom and isn't very noticable
2494
+ }
2495
+ },
2496
+
2497
+ _spiderfierOnRemove: function () {
2498
+ this._map.off('click', this._unspiderfyWrapper, this);
2499
+ this._map.off('zoomstart', this._unspiderfyZoomStart, this);
2500
+ this._map.off('zoomanim', this._unspiderfyZoomAnim, this);
2501
+ this._map.off('zoomend', this._noanimationUnspiderfy, this);
2502
+
2503
+ //Ensure that markers are back where they should be
2504
+ // Use no animation to avoid a sticky leaflet-cluster-anim class on mapPane
2505
+ this._noanimationUnspiderfy();
2506
+ },
2507
+
2508
+ //On zoom start we add a zoomanim handler so that we are guaranteed to be last (after markers are animated)
2509
+ //This means we can define the animation they do rather than Markers doing an animation to their actual location
2510
+ _unspiderfyZoomStart: function () {
2511
+ if (!this._map) { //May have been removed from the map by a zoomEnd handler
2512
+ return;
2513
+ }
2514
+
2515
+ this._map.on('zoomanim', this._unspiderfyZoomAnim, this);
2516
+ },
2517
+
2518
+ _unspiderfyZoomAnim: function (zoomDetails) {
2519
+ //Wait until the first zoomanim after the user has finished touch-zooming before running the animation
2520
+ if (BM.DomUtil.hasClass(this._map._mapPane, 'leaflet-touching')) {
2521
+ return;
2522
+ }
2523
+
2524
+ this._map.off('zoomanim', this._unspiderfyZoomAnim, this);
2525
+ this._unspiderfy(zoomDetails);
2526
+ },
2527
+
2528
+ _unspiderfyWrapper: function () {
2529
+ /// <summary>_unspiderfy but passes no arguments</summary>
2530
+ this._unspiderfy();
2531
+ },
2532
+
2533
+ _unspiderfy: function (zoomDetails) {
2534
+ if (this._spiderfied) {
2535
+ this._spiderfied.unspiderfy(zoomDetails);
2536
+ }
2537
+ },
2538
+
2539
+ _noanimationUnspiderfy: function () {
2540
+ if (this._spiderfied) {
2541
+ this._spiderfied._noanimationUnspiderfy();
2542
+ }
2543
+ },
2544
+
2545
+ //If the given layer is currently being spiderfied then we unspiderfy it so it isn't on the map anymore etc
2546
+ _unspiderfyLayer: function (layer) {
2547
+ if (layer._spiderLeg) {
2548
+ this._featureGroup.removeLayer(layer);
2549
+
2550
+ if (layer.clusterShow) {
2551
+ layer.clusterShow();
2552
+ }
2553
+ //Position will be fixed up immediately in _animationUnspiderfy
2554
+ if (layer.setZIndexOffset) {
2555
+ layer.setZIndexOffset(0);
2556
+ }
2557
+
2558
+ this._map.removeLayer(layer._spiderLeg);
2559
+ delete layer._spiderLeg;
2560
+ }
2561
+ }
2562
+ });
2563
+
2564
+ /**
2565
+ * Adds 1 public method to MCG and 1 to BM.Marker to facilitate changing
2566
+ * markers' icon options and refreshing their icon and their parent clusters
2567
+ * accordingly (case where their iconCreateFunction uses data of childMarkers
2568
+ * to make up the cluster icon).
2569
+ */
2570
+
2571
+
2572
+ BM.MarkerClusterGroup.include({
2573
+ /**
2574
+ * Updates the icon of all clusters which are parents of the given marker(s).
2575
+ * In singleMarkerMode, also updates the given marker(s) icon.
2576
+ * @param layers BM.MarkerClusterGroup|BM.LayerGroup|Array(BM.Marker)|Map(BM.Marker)|
2577
+ * BM.MarkerCluster|BM.Marker (optional) list of markers (or single marker) whose parent
2578
+ * clusters need to be updated. If not provided, retrieves all child markers of this.
2579
+ * @returns {BM.MarkerClusterGroup}
2580
+ */
2581
+ refreshClusters: function (layers) {
2582
+ if (!layers) {
2583
+ layers = this._topClusterLevel.getAllChildMarkers();
2584
+ } else if (layers instanceof BM.MarkerClusterGroup) {
2585
+ layers = layers._topClusterLevel.getAllChildMarkers();
2586
+ } else if (layers instanceof BM.LayerGroup) {
2587
+ layers = layers._layers;
2588
+ } else if (layers instanceof BM.MarkerCluster) {
2589
+ layers = layers.getAllChildMarkers();
2590
+ } else if (layers instanceof BM.Marker) {
2591
+ layers = [layers];
2592
+ } // else: must be an Array(BM.Marker)|Map(BM.Marker)
2593
+ this._flagParentsIconsNeedUpdate(layers);
2594
+ this._refreshClustersIcons();
2595
+
2596
+ // In case of singleMarkerMode, also re-draw the markers.
2597
+ if (this.options.singleMarkerMode) {
2598
+ this._refreshSingleMarkerModeMarkers(layers);
2599
+ }
2600
+
2601
+ return this;
2602
+ },
2603
+
2604
+ /**
2605
+ * Simply flags all parent clusters of the given markers as having a "dirty" icon.
2606
+ * @param layers Array(BM.Marker)|Map(BM.Marker) list of markers.
2607
+ * @private
2608
+ */
2609
+ _flagParentsIconsNeedUpdate: function (layers) {
2610
+ var id, parent;
2611
+
2612
+ // Assumes layers is an Array or an Object whose prototype is non-enumerable.
2613
+ for (id in layers) {
2614
+ // Flag parent clusters' icon as "dirty", all the way up.
2615
+ // Dumb process that flags multiple times upper parents, but still
2616
+ // much more efficient than trying to be smart and make short lists,
2617
+ // at least in the case of a hierarchy following a power law:
2618
+ // http://jsperf.com/flag-nodes-in-power-hierarchy/2
2619
+ parent = layers[id].__parent;
2620
+ while (parent) {
2621
+ parent._iconNeedsUpdate = true;
2622
+ parent = parent.__parent;
2623
+ }
2624
+ }
2625
+ },
2626
+
2627
+ /**
2628
+ * Re-draws the icon of the supplied markers.
2629
+ * To be used in singleMarkerMode only.
2630
+ * @param layers Array(BM.Marker)|Map(BM.Marker) list of markers.
2631
+ * @private
2632
+ */
2633
+ _refreshSingleMarkerModeMarkers: function (layers) {
2634
+ var id, layer;
2635
+
2636
+ for (id in layers) {
2637
+ layer = layers[id];
2638
+
2639
+ // Make sure we do not override markers that do not belong to THIS group.
2640
+ if (this.hasLayer(layer)) {
2641
+ // Need to re-create the icon first, then re-draw the marker.
2642
+ layer.setIcon(this._overrideMarkerIcon(layer));
2643
+ }
2644
+ }
2645
+ }
2646
+ });
2647
+
2648
+ BM.Marker.include({
2649
+ /**
2650
+ * Updates the given options in the marker's icon and refreshes the marker.
2651
+ * @param options map object of icon options.
2652
+ * @param directlyRefreshClusters boolean (optional) true to trigger
2653
+ * MCG.refreshClustersOf() right away with this single marker.
2654
+ * @returns {BM.Marker}
2655
+ */
2656
+ refreshIconOptions: function (options, directlyRefreshClusters) {
2657
+ var icon = this.options.icon;
2658
+
2659
+ BM.setOptions(icon, options);
2660
+
2661
+ this.setIcon(icon);
2662
+
2663
+ // Shortcut to refresh the associated MCG clusters right away.
2664
+ // To be used when refreshing a single marker.
2665
+ // Otherwise, better use MCG.refreshClusters() once at the end with
2666
+ // the list of modified markers.
2667
+ if (directlyRefreshClusters && this.__parent) {
2668
+ this.__parent._group.refreshClusters(this);
2669
+ }
2670
+
2671
+ return this;
2672
+ }
2673
+ });
2674
+
2675
+ exports.MarkerClusterGroup = MarkerClusterGroup;
2676
+ exports.MarkerCluster = MarkerCluster;
2677
+
2678
+ })));
2679
+ //# sourceMappingURL=leaflet.markercluster-src.js.map