Changeset 315 for binary-improvements/webserver/leaflet/markercluster
- Timestamp:
- Jan 31, 2018, 2:52:42 PM (7 years ago)
- Location:
- binary-improvements/webserver/leaflet/markercluster
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/webserver/leaflet/markercluster/MarkerCluster.css
r173 r315 4 4 -o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in; 5 5 transition: transform 0.3s ease-out, opacity 0.3s ease-in; 6 } 6 } 7 8 .leaflet-cluster-spider-leg { 9 /* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */ 10 -webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in; 11 -moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in; 12 -o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in; 13 transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in; 14 } -
binary-improvements/webserver/leaflet/markercluster/leaflet.markercluster-src.js
r173 r315 2 2 Leaflet.markercluster, Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps. 3 3 https://github.com/Leaflet/Leaflet.markercluster 4 (c) 2012-201 3, Dave Leaver, smartrak4 (c) 2012-2017, Dave Leaver 5 5 */ 6 6 (function (window, document, undefined) {/* … … 13 13 maxClusterRadius: 80, //A cluster will cover at most this many pixels from its center 14 14 iconCreateFunction: null, 15 clusterPane: L.Marker.prototype.options.pane, 15 16 16 17 spiderfyOnMaxZoom: true, … … 25 26 removeOutsideVisibleBounds: true, 26 27 28 // Set to false to disable all animations (zoom and spiderfy). 29 // If false, option animateAddingMarkers below has no effect. 30 // If L.DomUtil.TRANSITION is falsy, this option has no effect. 31 animate: true, 32 27 33 //Whether to animate adding markers after adding the MarkerClusterGroup to the map 28 34 // If you are adding individual markers set to true, if adding bulk markers leave false for massive performance gains. … … 31 37 //Increase to increase the distance away that spiderfied markers appear from the center 32 38 spiderfyDistanceMultiplier: 1, 39 40 // Make it possible to specify a polyline options on a spider leg 41 spiderLegPolylineOptions: { weight: 1.5, color: '#222', opacity: 0.5 }, 33 42 34 43 // 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 … … 49 58 50 59 this._featureGroup = L.featureGroup(); 51 this._featureGroup. on(L.FeatureGroup.EVENTS, this._propagateEvent,this);60 this._featureGroup.addEventParent(this); 52 61 53 62 this._nonPointGroup = L.featureGroup(); 54 this._nonPointGroup. on(L.FeatureGroup.EVENTS, this._propagateEvent,this);63 this._nonPointGroup.addEventParent(this); 55 64 56 65 this._inZoomAnimation = 0; … … 61 70 62 71 this._queue = []; 72 73 this._childMarkerEventHandlers = { 74 'dragstart': this._childMarkerDragStart, 75 'move': this._childMarkerMoved, 76 'dragend': this._childMarkerDragEnd, 77 }; 78 79 // Hook the appropriate animation methods. 80 var animate = L.DomUtil.TRANSITION && this.options.animate; 81 L.extend(this, animate ? this._withAnimation : this._noAnimation); 82 // Remember which MarkerCluster class to instantiate (animated or not). 83 this._markerCluster = animate ? L.MarkerCluster : L.MarkerClusterNonAnimated; 63 84 }, 64 85 … … 66 87 67 88 if (layer instanceof L.LayerGroup) { 68 var array = []; 69 for (var i in layer._layers) { 70 array.push(layer._layers[i]); 71 } 72 return this.addLayers(array); 89 return this.addLayers([layer]); 73 90 } 74 91 … … 76 93 if (!layer.getLatLng) { 77 94 this._nonPointGroup.addLayer(layer); 95 this.fire('layeradd', { layer: layer }); 78 96 return this; 79 97 } … … 81 99 if (!this._map) { 82 100 this._needsClustering.push(layer); 101 this.fire('layeradd', { layer: layer }); 83 102 return this; 84 103 } … … 96 115 97 116 this._addLayer(layer, this._maxZoom); 117 this.fire('layeradd', { layer: layer }); 118 119 // Refresh bounds and weighted positions. 120 this._topClusterLevel._recalculateBounds(); 121 122 this._refreshClustersIcons(); 98 123 99 124 //Work out what is visible 100 125 var visibleLayer = layer, 101 currentZoom = this._map.getZoom();126 currentZoom = this._zoom; 102 127 if (layer.__parent) { 103 128 while (visibleLayer.__parent._zoom >= currentZoom) { … … 118 143 removeLayer: function (layer) { 119 144 120 if (layer instanceof L.LayerGroup) 121 { 122 var array = []; 123 for (var i in layer._layers) { 124 array.push(layer._layers[i]); 125 } 126 return this.removeLayers(array); 145 if (layer instanceof L.LayerGroup) { 146 return this.removeLayers([layer]); 127 147 } 128 148 … … 130 150 if (!layer.getLatLng) { 131 151 this._nonPointGroup.removeLayer(layer); 152 this.fire('layerremove', { layer: layer }); 132 153 return this; 133 154 } … … 135 156 if (!this._map) { 136 157 if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) { 137 this._needsRemoving.push(layer); 138 } 158 this._needsRemoving.push({ layer: layer, latlng: layer._latlng }); 159 } 160 this.fire('layerremove', { layer: layer }); 139 161 return this; 140 162 } … … 151 173 //Remove the marker from clusters 152 174 this._removeLayer(layer, true); 175 this.fire('layerremove', { layer: layer }); 176 177 // Refresh bounds and weighted positions. 178 this._topClusterLevel._recalculateBounds(); 179 180 this._refreshClustersIcons(); 181 182 layer.off(this._childMarkerEventHandlers, this); 153 183 154 184 if (this._featureGroup.hasLayer(layer)) { 155 185 this._featureGroup.removeLayer(layer); 156 if (layer. setOpacity) {157 layer. setOpacity(1);186 if (layer.clusterShow) { 187 layer.clusterShow(); 158 188 } 159 189 } … … 163 193 164 194 //Takes an array of markers and adds them in bulk 165 addLayers: function (layersArray) { 195 addLayers: function (layersArray, skipLayerAddEvent) { 196 if (!L.Util.isArray(layersArray)) { 197 return this.addLayer(layersArray); 198 } 199 166 200 var fg = this._featureGroup, 167 npg = this._nonPointGroup, 168 chunked = this.options.chunkedLoading, 169 chunkInterval = this.options.chunkInterval, 170 chunkProgress = this.options.chunkProgress, 171 newMarkers, i, l, m; 201 npg = this._nonPointGroup, 202 chunked = this.options.chunkedLoading, 203 chunkInterval = this.options.chunkInterval, 204 chunkProgress = this.options.chunkProgress, 205 l = layersArray.length, 206 offset = 0, 207 originalArray = true, 208 m; 172 209 173 210 if (this._map) { 174 var offset = 0, 175 started = (new Date()).getTime(); 211 var started = (new Date()).getTime(); 176 212 var process = L.bind(function () { 177 213 var start = (new Date()).getTime(); 178 for (; offset < l ayersArray.length; offset++) {214 for (; offset < l; offset++) { 179 215 if (chunked && offset % 200 === 0) { 180 216 // every couple hundred markers, instrument the time elapsed since processing started: … … 187 223 m = layersArray[offset]; 188 224 225 // Group of layers, append children to layersArray and skip. 226 // Side effects: 227 // - Total increases, so chunkProgress ratio jumps backward. 228 // - Groups are not included in this group, only their non-group child layers (hasLayer). 229 // Changing array length while looping does not affect performance in current browsers: 230 // http://jsperf.com/for-loop-changing-length/6 231 if (m instanceof L.LayerGroup) { 232 if (originalArray) { 233 layersArray = layersArray.slice(); 234 originalArray = false; 235 } 236 this._extractNonGroupLayers(m, layersArray); 237 l = layersArray.length; 238 continue; 239 } 240 189 241 //Not point data, can't be clustered 190 242 if (!m.getLatLng) { 191 243 npg.addLayer(m); 244 if (!skipLayerAddEvent) { 245 this.fire('layeradd', { layer: m }); 246 } 192 247 continue; 193 248 } … … 198 253 199 254 this._addLayer(m, this._maxZoom); 255 if (!skipLayerAddEvent) { 256 this.fire('layeradd', { layer: m }); 257 } 200 258 201 259 //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 … … 203 261 if (m.__parent.getChildCount() === 2) { 204 262 var markers = m.__parent.getAllChildMarkers(), 205 263 otherMarker = markers[0] === m ? markers[1] : markers[0]; 206 264 fg.removeLayer(otherMarker); 207 265 } … … 211 269 if (chunkProgress) { 212 270 // report progress and time elapsed: 213 chunkProgress(offset, l ayersArray.length, (new Date()).getTime() - started);214 } 215 216 if (offset === layersArray.length) {217 //Update the icons of all those visible clusters that were affected218 this._featureGroup.eachLayer(function (c) { 219 if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) {220 c._updateIcon();221 } 222 });271 chunkProgress(offset, l, (new Date()).getTime() - started); 272 } 273 274 // Completed processing all markers. 275 if (offset === l) { 276 277 // Refresh bounds and weighted positions. 278 this._topClusterLevel._recalculateBounds(); 279 280 this._refreshClustersIcons(); 223 281 224 282 this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); … … 230 288 process(); 231 289 } else { 232 newMarkers = []; 233 for (i = 0, l = layersArray.length; i < l; i++) { 234 m = layersArray[i]; 290 var needsClustering = this._needsClustering; 291 292 for (; offset < l; offset++) { 293 m = layersArray[offset]; 294 295 // Group of layers, append children to layersArray and skip. 296 if (m instanceof L.LayerGroup) { 297 if (originalArray) { 298 layersArray = layersArray.slice(); 299 originalArray = false; 300 } 301 this._extractNonGroupLayers(m, layersArray); 302 l = layersArray.length; 303 continue; 304 } 235 305 236 306 //Not point data, can't be clustered … … 244 314 } 245 315 246 newMarkers.push(m); 247 } 248 this._needsClustering = this._needsClustering.concat(newMarkers); 316 needsClustering.push(m); 317 } 249 318 } 250 319 return this; … … 253 322 //Takes an array of markers and removes them in bulk 254 323 removeLayers: function (layersArray) { 255 var i, l, m, 256 fg = this._featureGroup, 257 npg = this._nonPointGroup; 324 var i, m, 325 l = layersArray.length, 326 fg = this._featureGroup, 327 npg = this._nonPointGroup, 328 originalArray = true; 258 329 259 330 if (!this._map) { 260 for (i = 0 , l = layersArray.length; i < l; i++) {331 for (i = 0; i < l; i++) { 261 332 m = layersArray[i]; 333 334 // Group of layers, append children to layersArray and skip. 335 if (m instanceof L.LayerGroup) { 336 if (originalArray) { 337 layersArray = layersArray.slice(); 338 originalArray = false; 339 } 340 this._extractNonGroupLayers(m, layersArray); 341 l = layersArray.length; 342 continue; 343 } 344 262 345 this._arraySplice(this._needsClustering, m); 263 346 npg.removeLayer(m); 347 if (this.hasLayer(m)) { 348 this._needsRemoving.push({ layer: m, latlng: m._latlng }); 349 } 350 this.fire('layerremove', { layer: m }); 264 351 } 265 352 return this; 266 353 } 267 354 268 for (i = 0, l = layersArray.length; i < l; i++) { 355 if (this._unspiderfy) { 356 this._unspiderfy(); 357 358 // Work on a copy of the array, so that next loop is not affected. 359 var layersArray2 = layersArray.slice(), 360 l2 = l; 361 for (i = 0; i < l2; i++) { 362 m = layersArray2[i]; 363 364 // Group of layers, append children to layersArray and skip. 365 if (m instanceof L.LayerGroup) { 366 this._extractNonGroupLayers(m, layersArray2); 367 l2 = layersArray2.length; 368 continue; 369 } 370 371 this._unspiderfyLayer(m); 372 } 373 } 374 375 for (i = 0; i < l; i++) { 269 376 m = layersArray[i]; 377 378 // Group of layers, append children to layersArray and skip. 379 if (m instanceof L.LayerGroup) { 380 if (originalArray) { 381 layersArray = layersArray.slice(); 382 originalArray = false; 383 } 384 this._extractNonGroupLayers(m, layersArray); 385 l = layersArray.length; 386 continue; 387 } 270 388 271 389 if (!m.__parent) { 272 390 npg.removeLayer(m); 391 this.fire('layerremove', { layer: m }); 273 392 continue; 274 393 } 275 394 276 395 this._removeLayer(m, true, true); 396 this.fire('layerremove', { layer: m }); 277 397 278 398 if (fg.hasLayer(m)) { 279 399 fg.removeLayer(m); 280 if (m.setOpacity) { 281 m.setOpacity(1); 282 } 283 } 284 } 400 if (m.clusterShow) { 401 m.clusterShow(); 402 } 403 } 404 } 405 406 // Refresh bounds and weighted positions. 407 this._topClusterLevel._recalculateBounds(); 408 409 this._refreshClustersIcons(); 285 410 286 411 //Fix up the clusters and markers on the map 287 412 this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); 288 289 fg.eachLayer(function (c) {290 if (c instanceof L.MarkerCluster) {291 c._updateIcon();292 }293 });294 413 295 414 return this; … … 316 435 317 436 this.eachLayer(function (marker) { 437 marker.off(this._childMarkerEventHandlers, this); 318 438 delete marker.__parent; 319 } );439 }, this); 320 440 321 441 if (this._map) { … … 347 467 eachLayer: function (method, context) { 348 468 var markers = this._needsClustering.slice(), 349 i; 469 needsRemoving = this._needsRemoving, 470 thisNeedsRemoving, i, j; 350 471 351 472 if (this._topClusterLevel) { … … 354 475 355 476 for (i = markers.length - 1; i >= 0; i--) { 356 method.call(context, markers[i]); 477 thisNeedsRemoving = true; 478 479 for (j = needsRemoving.length - 1; j >= 0; j--) { 480 if (needsRemoving[j].layer === markers[i]) { 481 thisNeedsRemoving = false; 482 break; 483 } 484 } 485 486 if (thisNeedsRemoving) { 487 method.call(context, markers[i]); 488 } 357 489 } 358 490 … … 372 504 getLayer: function (id) { 373 505 var result = null; 506 507 id = parseInt(id, 10); 374 508 375 509 this.eachLayer(function (l) { … … 398 532 anArray = this._needsRemoving; 399 533 for (i = anArray.length - 1; i >= 0; i--) { 400 if (anArray[i] === layer) {534 if (anArray[i].layer === layer) { 401 535 return false; 402 536 } … … 408 542 //Zoom down to show the given layer (spiderfying if necessary) then calls the callback 409 543 zoomToShowLayer: function (layer, callback) { 544 545 if (typeof callback !== 'function') { 546 callback = function () {}; 547 } 410 548 411 549 var showMarker = function () { … … 417 555 callback(); 418 556 } else if (layer.__parent._icon) { 419 var afterSpiderfy = function () { 420 this.off('spiderfied', afterSpiderfy, this); 421 callback(); 422 }; 423 424 this.on('spiderfied', afterSpiderfy, this); 557 this.once('spiderfied', callback, this); 425 558 layer.__parent.spiderfy(); 426 559 } … … 431 564 //Layer is visible ond on screen, immediate return 432 565 callback(); 433 } else if (layer.__parent._zoom < this._map.getZoom()) {566 } else if (layer.__parent._zoom < Math.round(this._map._zoom)) { 434 567 //Layer should be visible at this zoom level. It must not be on screen so just pan over to it 435 568 this._map.on('moveend', showMarker, this); 436 569 this._map.panTo(layer.getLatLng()); 437 570 } else { 438 var moveStart = function () {439 this._map.off('movestart', moveStart, this);440 moveStart = null;441 };442 443 this._map.on('movestart', moveStart, this);444 571 this._map.on('moveend', showMarker, this); 445 572 this.on('animationend', showMarker, this); 446 573 layer.__parent.zoomToBounds(); 447 448 if (moveStart) {449 //Never started moving, must already be there, probably need clustering however450 showMarker.call(this);451 }452 574 } 453 575 }, … … 462 584 } 463 585 464 this._featureGroup. onAdd(map);465 this._nonPointGroup. onAdd(map);586 this._featureGroup.addTo(map); 587 this._nonPointGroup.addTo(map); 466 588 467 589 if (!this._gridClusters) { … … 469 591 } 470 592 593 this._maxLat = map.options.crs.projection.MAX_LATITUDE; 594 595 //Restore all the positions as they are in the MCG before removing them 471 596 for (i = 0, l = this._needsRemoving.length; i < l; i++) { 472 597 layer = this._needsRemoving[i]; 473 this._removeLayer(layer, true); 598 layer.newlatlng = layer.layer._latlng; 599 layer.layer._latlng = layer.latlng; 600 } 601 //Remove them, then restore their new positions 602 for (i = 0, l = this._needsRemoving.length; i < l; i++) { 603 layer = this._needsRemoving[i]; 604 this._removeLayer(layer.layer, true); 605 layer.layer._latlng = layer.newlatlng; 474 606 } 475 607 this._needsRemoving = []; 476 608 477 609 //Remember the current zoom level and bounds 478 this._zoom = this._map.getZoom();610 this._zoom = Math.round(this._map._zoom); 479 611 this._currentShownBounds = this._getExpandedVisibleBounds(); 480 612 … … 491 623 l = this._needsClustering; 492 624 this._needsClustering = []; 493 this.addLayers(l );625 this.addLayers(l, true); 494 626 }, 495 627 … … 508 640 } 509 641 510 642 delete this._maxLat; 511 643 512 644 //Clean up all the layers we added to the map 513 645 this._hideCoverage(); 514 this._featureGroup. onRemove(map);515 this._nonPointGroup. onRemove(map);646 this._featureGroup.remove(); 647 this._nonPointGroup.remove(); 516 648 517 649 this._featureGroup.clearLayers(); … … 538 670 }, 539 671 672 /** 673 * Removes a marker from all _gridUnclustered zoom levels, starting at the supplied zoom. 674 * @param marker to be removed from _gridUnclustered. 675 * @param z integer bottom start zoom level (included) 676 * @private 677 */ 678 _removeFromGridUnclustered: function (marker, z) { 679 var map = this._map, 680 gridUnclustered = this._gridUnclustered, 681 minZoom = Math.floor(this._map.getMinZoom()); 682 683 for (; z >= minZoom; z--) { 684 if (!gridUnclustered[z].removeObject(marker, map.project(marker.getLatLng(), z))) { 685 break; 686 } 687 } 688 }, 689 690 _childMarkerDragStart: function (e) { 691 e.target.__dragStart = e.target._latlng; 692 }, 693 694 _childMarkerMoved: function (e) { 695 if (!this._ignoreMove && !e.target.__dragStart) { 696 var isPopupOpen = e.target._popup && e.target._popup.isOpen(); 697 698 this._moveChild(e.target, e.oldLatLng, e.latlng); 699 700 if (isPopupOpen) { 701 e.target.openPopup(); 702 } 703 } 704 }, 705 706 _moveChild: function (layer, from, to) { 707 layer._latlng = from; 708 this.removeLayer(layer); 709 710 layer._latlng = to; 711 this.addLayer(layer); 712 }, 713 714 _childMarkerDragEnd: function (e) { 715 if (e.target.__dragStart) { 716 this._moveChild(e.target, e.target.__dragStart, e.target._latlng); 717 } 718 delete e.target.__dragStart; 719 }, 720 721 540 722 //Internal function for removing a marker from everything. 541 723 //dontUpdateMap: set to true if you will handle updating the map manually (for bulk functions) … … 544 726 gridUnclustered = this._gridUnclustered, 545 727 fg = this._featureGroup, 546 map = this._map; 728 map = this._map, 729 minZoom = Math.floor(this._map.getMinZoom()); 547 730 548 731 //Remove the marker from distance clusters it might be in 549 732 if (removeFromDistanceGrid) { 550 for (var z = this._maxZoom; z >= 0; z--) { 551 if (!gridUnclustered[z].removeObject(marker, map.project(marker.getLatLng(), z))) { 552 break; 553 } 554 } 733 this._removeFromGridUnclustered(marker, this._maxZoom); 555 734 } 556 735 … … 565 744 while (cluster) { 566 745 cluster._childCount--; 567 568 if (cluster._zoom < 0) { 746 cluster._boundsNeedUpdate = true; 747 748 if (cluster._zoom < minZoom) { 569 749 //Top level, do nothing 570 750 break; … … 590 770 } 591 771 } else { 592 cluster._recalculateBounds(); 593 if (!dontUpdateMap || !cluster._icon) { 594 cluster._updateIcon(); 595 } 772 cluster._iconNeedsUpdate = true; 596 773 } 597 774 … … 612 789 }, 613 790 614 _propagateEvent: function (e) { 615 if (e.layer instanceof L.MarkerCluster) { 791 //Override L.Evented.fire 792 fire: function (type, data, propagate) { 793 if (data && data.layer instanceof L.MarkerCluster) { 616 794 //Prevent multiple clustermouseover/off events if the icon is made up of stacked divs (Doesn't work in ie <= 8, no relatedTarget) 617 if ( e.originalEvent && this._isOrIsParent(e.layer._icon, e.originalEvent.relatedTarget)) {795 if (data.originalEvent && this._isOrIsParent(data.layer._icon, data.originalEvent.relatedTarget)) { 618 796 return; 619 797 } 620 e.type = 'cluster' + e.type; 621 } 622 623 this.fire(e.type, e); 798 type = 'cluster' + type; 799 } 800 801 L.FeatureGroup.prototype.fire.call(this, type, data, propagate); 802 }, 803 804 //Override L.Evented.listens 805 listens: function (type, propagate) { 806 return L.FeatureGroup.prototype.listens.call(this, type, propagate) || L.FeatureGroup.prototype.listens.call(this, 'cluster' + type, propagate); 624 807 }, 625 808 … … 660 843 661 844 _zoomOrSpiderfy: function (e) { 662 var map = this._map; 663 if (map.getMaxZoom() === map.getZoom()) { 664 if (this.options.spiderfyOnMaxZoom) { 665 e.layer.spiderfy(); 666 } 845 var cluster = e.layer, 846 bottomCluster = cluster; 847 848 while (bottomCluster._childClusters.length === 1) { 849 bottomCluster = bottomCluster._childClusters[0]; 850 } 851 852 if (bottomCluster._zoom === this._maxZoom && 853 bottomCluster._childCount === cluster._childCount && 854 this.options.spiderfyOnMaxZoom) { 855 856 // All child markers are contained in a single cluster from this._maxZoom to this cluster. 857 cluster.spiderfy(); 667 858 } else if (this.options.zoomToBoundsOnClick) { 668 e.layer.zoomToBounds();859 cluster.zoomToBounds(); 669 860 } 670 861 671 862 // Focus the map again for keyboard users. 672 863 if (e.originalEvent && e.originalEvent.keyCode === 13) { 673 map._container.focus();864 this._map._container.focus(); 674 865 } 675 866 }, … … 718 909 this._mergeSplitClusters(); 719 910 720 this._zoom = this._map._zoom;911 this._zoom = Math.round(this._map._zoom); 721 912 this._currentShownBounds = this._getExpandedVisibleBounds(); 722 913 }, … … 729 920 var newBounds = this._getExpandedVisibleBounds(); 730 921 731 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom, newBounds);732 this._topClusterLevel._recursivelyAddChildrenToMap(null, this._map._zoom, newBounds);922 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), this._zoom, newBounds); 923 this._topClusterLevel._recursivelyAddChildrenToMap(null, Math.round(this._map._zoom), newBounds); 733 924 734 925 this._currentShownBounds = newBounds; … … 737 928 738 929 _generateInitialClusters: function () { 739 var maxZoom = this._map.getMaxZoom(), 930 var maxZoom = Math.ceil(this._map.getMaxZoom()), 931 minZoom = Math.floor(this._map.getMinZoom()), 740 932 radius = this.options.maxClusterRadius, 741 933 radiusFn = radius; … … 748 940 } 749 941 750 if (this.options.disableClusteringAtZoom ) {942 if (this.options.disableClusteringAtZoom !== null) { 751 943 maxZoom = this.options.disableClusteringAtZoom - 1; 752 944 } … … 756 948 757 949 //Set up DistanceGrids for each zoom 758 for (var zoom = maxZoom; zoom >= 0; zoom--) {950 for (var zoom = maxZoom; zoom >= minZoom; zoom--) { 759 951 this._gridClusters[zoom] = new L.DistanceGrid(radiusFn(zoom)); 760 952 this._gridUnclustered[zoom] = new L.DistanceGrid(radiusFn(zoom)); 761 953 } 762 954 763 this._topClusterLevel = new L.MarkerCluster(this, -1); 955 // Instantiate the appropriate L.MarkerCluster class (animated or not). 956 this._topClusterLevel = new this._markerCluster(this, minZoom - 1); 764 957 }, 765 958 … … 768 961 var gridClusters = this._gridClusters, 769 962 gridUnclustered = this._gridUnclustered, 963 minZoom = Math.floor(this._map.getMinZoom()), 770 964 markerPoint, z; 771 965 772 966 if (this.options.singleMarkerMode) { 773 layer.options.icon = this.options.iconCreateFunction({ 774 getChildCount: function () { 775 return 1; 776 }, 777 getAllChildMarkers: function () { 778 return [layer]; 779 } 780 }); 781 } 967 this._overrideMarkerIcon(layer); 968 } 969 970 layer.on(this._childMarkerEventHandlers, this); 782 971 783 972 //Find the lowest zoom level to slot this one in 784 for (; zoom >= 0; zoom--) {973 for (; zoom >= minZoom; zoom--) { 785 974 markerPoint = this._map.project(layer.getLatLng(), zoom); // calculate pixel position 786 975 … … 803 992 //Create new cluster with these 2 in it 804 993 805 var newCluster = new L.MarkerCluster(this, zoom, closest, layer);994 var newCluster = new this._markerCluster(this, zoom, closest, layer); 806 995 gridClusters[zoom].addObject(newCluster, this._map.project(newCluster._cLatLng, zoom)); 807 996 closest.__parent = newCluster; … … 811 1000 var lastParent = newCluster; 812 1001 for (z = zoom - 1; z > parent._zoom; z--) { 813 lastParent = new L.MarkerCluster(this, z, lastParent);1002 lastParent = new this._markerCluster(this, z, lastParent); 814 1003 gridClusters[z].addObject(lastParent, this._map.project(closest.getLatLng(), z)); 815 1004 } … … 817 1006 818 1007 //Remove closest from this zoom level and any above that it is in, replace with newCluster 819 for (z = zoom; z >= 0; z--) { 820 if (!gridUnclustered[z].removeObject(closest, this._map.project(closest.getLatLng(), z))) { 821 break; 822 } 823 } 1008 this._removeFromGridUnclustered(closest, zoom); 824 1009 825 1010 return; … … 834 1019 layer.__parent = this._topClusterLevel; 835 1020 return; 1021 }, 1022 1023 /** 1024 * Refreshes the icon of all "dirty" visible clusters. 1025 * Non-visible "dirty" clusters will be updated when they are added to the map. 1026 * @private 1027 */ 1028 _refreshClustersIcons: function () { 1029 this._featureGroup.eachLayer(function (c) { 1030 if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) { 1031 c._updateIcon(); 1032 } 1033 }); 836 1034 }, 837 1035 … … 854 1052 //Merge and split any existing clusters that are too big or small 855 1053 _mergeSplitClusters: function () { 856 857 //Incase we are starting to split before the animation finished 1054 var mapZoom = Math.round(this._map._zoom); 1055 1056 //In case we are starting to split before the animation finished 858 1057 this._processQueue(); 859 1058 860 if (this._zoom < this._map._zoom && this._currentShownBounds.intersects(this._getExpandedVisibleBounds())) { //Zoom in, split1059 if (this._zoom < mapZoom && this._currentShownBounds.intersects(this._getExpandedVisibleBounds())) { //Zoom in, split 861 1060 this._animationStart(); 862 1061 //Remove clusters now off screen 863 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom, this._getExpandedVisibleBounds());864 865 this._animationZoomIn(this._zoom, this._map._zoom);866 867 } else if (this._zoom > this._map._zoom) { //Zoom out, merge1062 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), this._zoom, this._getExpandedVisibleBounds()); 1063 1064 this._animationZoomIn(this._zoom, mapZoom); 1065 1066 } else if (this._zoom > mapZoom) { //Zoom out, merge 868 1067 this._animationStart(); 869 1068 870 this._animationZoomOut(this._zoom, this._map._zoom);1069 this._animationZoomOut(this._zoom, mapZoom); 871 1070 } else { 872 1071 this._moveEnd(); … … 877 1076 _getExpandedVisibleBounds: function () { 878 1077 if (!this.options.removeOutsideVisibleBounds) { 879 return this.getBounds(); 880 } 881 882 var map = this._map, 883 bounds = map.getBounds(), 884 sw = bounds._southWest, 885 ne = bounds._northEast, 886 latDiff = L.Browser.mobile ? 0 : Math.abs(sw.lat - ne.lat), 887 lngDiff = L.Browser.mobile ? 0 : Math.abs(sw.lng - ne.lng); 888 889 return new L.LatLngBounds( 890 new L.LatLng(sw.lat - latDiff, sw.lng - lngDiff, true), 891 new L.LatLng(ne.lat + latDiff, ne.lng + lngDiff, true)); 1078 return this._mapBoundsInfinite; 1079 } else if (L.Browser.mobile) { 1080 return this._checkBoundsMaxLat(this._map.getBounds()); 1081 } 1082 1083 return this._checkBoundsMaxLat(this._map.getBounds().pad(1)); // Padding expands the bounds by its own dimensions but scaled with the given factor. 1084 }, 1085 1086 /** 1087 * Expands the latitude to Infinity (or -Infinity) if the input bounds reach the map projection maximum defined latitude 1088 * (in the case of Web/Spherical Mercator, it is 85.0511287798 / see https://en.wikipedia.org/wiki/Web_Mercator#Formulas). 1089 * Otherwise, the removeOutsideVisibleBounds option will remove markers beyond that limit, whereas the same markers without 1090 * this option (or outside MCG) will have their position floored (ceiled) by the projection and rendered at that limit, 1091 * making the user think that MCG "eats" them and never displays them again. 1092 * @param bounds L.LatLngBounds 1093 * @returns {L.LatLngBounds} 1094 * @private 1095 */ 1096 _checkBoundsMaxLat: function (bounds) { 1097 var maxLat = this._maxLat; 1098 1099 if (maxLat !== undefined) { 1100 if (bounds.getNorth() >= maxLat) { 1101 bounds._northEast.lat = Infinity; 1102 } 1103 if (bounds.getSouth() <= -maxLat) { 1104 bounds._southWest.lat = -Infinity; 1105 } 1106 } 1107 1108 return bounds; 892 1109 }, 893 1110 … … 905 1122 newCluster._updateIcon(); 906 1123 } 1124 }, 1125 1126 /** 1127 * Extracts individual (i.e. non-group) layers from a Layer Group. 1128 * @param group to extract layers from. 1129 * @param output {Array} in which to store the extracted layers. 1130 * @returns {*|Array} 1131 * @private 1132 */ 1133 _extractNonGroupLayers: function (group, output) { 1134 var layers = group.getLayers(), 1135 i = 0, 1136 layer; 1137 1138 output = output || []; 1139 1140 for (; i < layers.length; i++) { 1141 layer = layers[i]; 1142 1143 if (layer instanceof L.LayerGroup) { 1144 this._extractNonGroupLayers(layer, output); 1145 continue; 1146 } 1147 1148 output.push(layer); 1149 } 1150 1151 return output; 1152 }, 1153 1154 /** 1155 * Implements the singleMarkerMode option. 1156 * @param layer Marker to re-style using the Clusters iconCreateFunction. 1157 * @returns {L.Icon} The newly created icon. 1158 * @private 1159 */ 1160 _overrideMarkerIcon: function (layer) { 1161 var icon = layer.options.icon = this.options.iconCreateFunction({ 1162 getChildCount: function () { 1163 return 1; 1164 }, 1165 getAllChildMarkers: function () { 1166 return [layer]; 1167 } 1168 }); 1169 1170 return icon; 907 1171 } 908 1172 }); 909 1173 910 L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? { 911 912 //Non Animated versions of everything 913 _animationStart: function () { 914 //Do nothing... 915 }, 916 _animationZoomIn: function (previousZoomLevel, newZoomLevel) { 917 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel); 918 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 919 920 //We didn't actually animate, but we use this event to mean "clustering animations have finished" 921 this.fire('animationend'); 922 }, 923 _animationZoomOut: function (previousZoomLevel, newZoomLevel) { 924 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel); 925 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 926 927 //We didn't actually animate, but we use this event to mean "clustering animations have finished" 928 this.fire('animationend'); 929 }, 930 _animationAddLayer: function (layer, newCluster) { 931 this._animationAddLayerNonAnimated(layer, newCluster); 932 } 933 } : { 934 935 //Animated versions here 936 _animationStart: function () { 937 this._map._mapPane.className += ' leaflet-cluster-anim'; 938 this._inZoomAnimation++; 939 }, 940 _animationEnd: function () { 941 if (this._map) { 942 this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', ''); 943 } 944 this._inZoomAnimation--; 945 this.fire('animationend'); 946 }, 947 _animationZoomIn: function (previousZoomLevel, newZoomLevel) { 1174 // Constant bounds used in case option "removeOutsideVisibleBounds" is set to false. 1175 L.MarkerClusterGroup.include({ 1176 _mapBoundsInfinite: new L.LatLngBounds(new L.LatLng(-Infinity, -Infinity), new L.LatLng(Infinity, Infinity)) 1177 }); 1178 1179 L.MarkerClusterGroup.include({ 1180 _noAnimation: { 1181 //Non Animated versions of everything 1182 _animationStart: function () { 1183 //Do nothing... 1184 }, 1185 _animationZoomIn: function (previousZoomLevel, newZoomLevel) { 1186 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel); 1187 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 1188 1189 //We didn't actually animate, but we use this event to mean "clustering animations have finished" 1190 this.fire('animationend'); 1191 }, 1192 _animationZoomOut: function (previousZoomLevel, newZoomLevel) { 1193 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel); 1194 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 1195 1196 //We didn't actually animate, but we use this event to mean "clustering animations have finished" 1197 this.fire('animationend'); 1198 }, 1199 _animationAddLayer: function (layer, newCluster) { 1200 this._animationAddLayerNonAnimated(layer, newCluster); 1201 } 1202 }, 1203 1204 _withAnimation: { 1205 //Animated versions here 1206 _animationStart: function () { 1207 this._map._mapPane.className += ' leaflet-cluster-anim'; 1208 this._inZoomAnimation++; 1209 }, 1210 1211 _animationZoomIn: function (previousZoomLevel, newZoomLevel) { 1212 var bounds = this._getExpandedVisibleBounds(), 1213 fg = this._featureGroup, 1214 minZoom = Math.floor(this._map.getMinZoom()), 1215 i; 1216 1217 this._ignoreMove = true; 1218 1219 //Add all children of current clusters to map and remove those clusters from map 1220 this._topClusterLevel._recursively(bounds, previousZoomLevel, minZoom, function (c) { 1221 var startPos = c._latlng, 1222 markers = c._markers, 1223 m; 1224 1225 if (!bounds.contains(startPos)) { 1226 startPos = null; 1227 } 1228 1229 if (c._isSingleParent() && previousZoomLevel + 1 === newZoomLevel) { //Immediately add the new child and remove us 1230 fg.removeLayer(c); 1231 c._recursivelyAddChildrenToMap(null, newZoomLevel, bounds); 1232 } else { 1233 //Fade out old cluster 1234 c.clusterHide(); 1235 c._recursivelyAddChildrenToMap(startPos, newZoomLevel, bounds); 1236 } 1237 1238 //Remove all markers that aren't visible any more 1239 //TODO: Do we actually need to do this on the higher levels too? 1240 for (i = markers.length - 1; i >= 0; i--) { 1241 m = markers[i]; 1242 if (!bounds.contains(m._latlng)) { 1243 fg.removeLayer(m); 1244 } 1245 } 1246 1247 }); 1248 1249 this._forceLayout(); 1250 1251 //Update opacities 1252 this._topClusterLevel._recursivelyBecomeVisible(bounds, newZoomLevel); 1253 //TODO Maybe? Update markers in _recursivelyBecomeVisible 1254 fg.eachLayer(function (n) { 1255 if (!(n instanceof L.MarkerCluster) && n._icon) { 1256 n.clusterShow(); 1257 } 1258 }); 1259 1260 //update the positions of the just added clusters/markers 1261 this._topClusterLevel._recursively(bounds, previousZoomLevel, newZoomLevel, function (c) { 1262 c._recursivelyRestoreChildPositions(newZoomLevel); 1263 }); 1264 1265 this._ignoreMove = false; 1266 1267 //Remove the old clusters and close the zoom animation 1268 this._enqueue(function () { 1269 //update the positions of the just added clusters/markers 1270 this._topClusterLevel._recursively(bounds, previousZoomLevel, minZoom, function (c) { 1271 fg.removeLayer(c); 1272 c.clusterShow(); 1273 }); 1274 1275 this._animationEnd(); 1276 }); 1277 }, 1278 1279 _animationZoomOut: function (previousZoomLevel, newZoomLevel) { 1280 this._animationZoomOutSingle(this._topClusterLevel, previousZoomLevel - 1, newZoomLevel); 1281 1282 //Need to add markers for those that weren't on the map before but are now 1283 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 1284 //Remove markers that were on the map before but won't be now 1285 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, Math.floor(this._map.getMinZoom()), previousZoomLevel, this._getExpandedVisibleBounds()); 1286 }, 1287 1288 _animationAddLayer: function (layer, newCluster) { 1289 var me = this, 1290 fg = this._featureGroup; 1291 1292 fg.addLayer(layer); 1293 if (newCluster !== layer) { 1294 if (newCluster._childCount > 2) { //Was already a cluster 1295 1296 newCluster._updateIcon(); 1297 this._forceLayout(); 1298 this._animationStart(); 1299 1300 layer._setPos(this._map.latLngToLayerPoint(newCluster.getLatLng())); 1301 layer.clusterHide(); 1302 1303 this._enqueue(function () { 1304 fg.removeLayer(layer); 1305 layer.clusterShow(); 1306 1307 me._animationEnd(); 1308 }); 1309 1310 } else { //Just became a cluster 1311 this._forceLayout(); 1312 1313 me._animationStart(); 1314 me._animationZoomOutSingle(newCluster, this._map.getMaxZoom(), this._zoom); 1315 } 1316 } 1317 } 1318 }, 1319 1320 // Private methods for animated versions. 1321 _animationZoomOutSingle: function (cluster, previousZoomLevel, newZoomLevel) { 948 1322 var bounds = this._getExpandedVisibleBounds(), 949 fg = this._featureGroup, 950 i; 951 952 //Add all children of current clusters to map and remove those clusters from map 953 this._topClusterLevel._recursively(bounds, previousZoomLevel, 0, function (c) { 954 var startPos = c._latlng, 955 markers = c._markers, 956 m; 957 958 if (!bounds.contains(startPos)) { 959 startPos = null; 960 } 961 962 if (c._isSingleParent() && previousZoomLevel + 1 === newZoomLevel) { //Immediately add the new child and remove us 963 fg.removeLayer(c); 964 c._recursivelyAddChildrenToMap(null, newZoomLevel, bounds); 965 } else { 966 //Fade out old cluster 967 c.setOpacity(0); 968 c._recursivelyAddChildrenToMap(startPos, newZoomLevel, bounds); 969 } 970 971 //Remove all markers that aren't visible any more 972 //TODO: Do we actually need to do this on the higher levels too? 973 for (i = markers.length - 1; i >= 0; i--) { 974 m = markers[i]; 975 if (!bounds.contains(m._latlng)) { 976 fg.removeLayer(m); 977 } 978 } 979 980 }); 981 982 this._forceLayout(); 983 984 //Update opacities 985 this._topClusterLevel._recursivelyBecomeVisible(bounds, newZoomLevel); 986 //TODO Maybe? Update markers in _recursivelyBecomeVisible 987 fg.eachLayer(function (n) { 988 if (!(n instanceof L.MarkerCluster) && n._icon) { 989 n.setOpacity(1); 990 } 991 }); 992 993 //update the positions of the just added clusters/markers 994 this._topClusterLevel._recursively(bounds, previousZoomLevel, newZoomLevel, function (c) { 995 c._recursivelyRestoreChildPositions(newZoomLevel); 996 }); 997 998 //Remove the old clusters and close the zoom animation 999 this._enqueue(function () { 1000 //update the positions of the just added clusters/markers 1001 this._topClusterLevel._recursively(bounds, previousZoomLevel, 0, function (c) { 1002 fg.removeLayer(c); 1003 c.setOpacity(1); 1004 }); 1005 1006 this._animationEnd(); 1007 }); 1008 }, 1009 1010 _animationZoomOut: function (previousZoomLevel, newZoomLevel) { 1011 this._animationZoomOutSingle(this._topClusterLevel, previousZoomLevel - 1, newZoomLevel); 1012 1013 //Need to add markers for those that weren't on the map before but are now 1014 this._topClusterLevel._recursivelyAddChildrenToMap(null, newZoomLevel, this._getExpandedVisibleBounds()); 1015 //Remove markers that were on the map before but won't be now 1016 this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, previousZoomLevel, this._getExpandedVisibleBounds()); 1017 }, 1018 _animationZoomOutSingle: function (cluster, previousZoomLevel, newZoomLevel) { 1019 var bounds = this._getExpandedVisibleBounds(); 1323 minZoom = Math.floor(this._map.getMinZoom()); 1020 1324 1021 1325 //Animate all of the markers in the clusters to move to their cluster center point 1022 cluster._recursivelyAnimateChildrenInAndAddSelfToMap(bounds, previousZoomLevel + 1, newZoomLevel);1326 cluster._recursivelyAnimateChildrenInAndAddSelfToMap(bounds, minZoom, previousZoomLevel + 1, newZoomLevel); 1023 1327 1024 1328 var me = this; … … 1036 1340 var m = cluster._markers[0]; 1037 1341 //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 1342 this._ignoreMove = true; 1038 1343 m.setLatLng(m.getLatLng()); 1039 if (m.setOpacity) { 1040 m.setOpacity(1); 1344 this._ignoreMove = false; 1345 if (m.clusterShow) { 1346 m.clusterShow(); 1041 1347 } 1042 1348 } else { 1043 cluster._recursively(bounds, newZoomLevel, 0, function (c) {1044 c._recursivelyRemoveChildrenFromMap(bounds, previousZoomLevel + 1);1349 cluster._recursively(bounds, newZoomLevel, minZoom, function (c) { 1350 c._recursivelyRemoveChildrenFromMap(bounds, minZoom, previousZoomLevel + 1); 1045 1351 }); 1046 1352 } … … 1048 1354 }); 1049 1355 }, 1050 _animationAddLayer: function (layer, newCluster) { 1051 var me = this, 1052 fg = this._featureGroup; 1053 1054 fg.addLayer(layer); 1055 if (newCluster !== layer) { 1056 if (newCluster._childCount > 2) { //Was already a cluster 1057 1058 newCluster._updateIcon(); 1059 this._forceLayout(); 1060 this._animationStart(); 1061 1062 layer._setPos(this._map.latLngToLayerPoint(newCluster.getLatLng())); 1063 layer.setOpacity(0); 1064 1065 this._enqueue(function () { 1066 fg.removeLayer(layer); 1067 layer.setOpacity(1); 1068 1069 me._animationEnd(); 1070 }); 1071 1072 } else { //Just became a cluster 1073 this._forceLayout(); 1074 1075 me._animationStart(); 1076 me._animationZoomOutSingle(newCluster, this._map.getMaxZoom(), this._map.getZoom()); 1077 } 1078 } 1356 1357 _animationEnd: function () { 1358 if (this._map) { 1359 this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', ''); 1360 } 1361 this._inZoomAnimation--; 1362 this.fire('animationend'); 1079 1363 }, 1080 1364 … … 1097 1381 initialize: function (group, zoom, a, b) { 1098 1382 1099 L.Marker.prototype.initialize.call(this, a ? (a._cLatLng || a.getLatLng()) : new L.LatLng(0, 0), { icon: this });1100 1383 L.Marker.prototype.initialize.call(this, a ? (a._cLatLng || a.getLatLng()) : new L.LatLng(0, 0), 1384 { icon: this, pane: group.options.clusterPane }); 1101 1385 1102 1386 this._group = group; … … 1107 1391 this._childCount = 0; 1108 1392 this._iconNeedsUpdate = true; 1393 this._boundsNeedUpdate = true; 1109 1394 1110 1395 this._bounds = new L.LatLngBounds(); … … 1139 1424 1140 1425 //Zoom to the minimum of showing all of the child markers, or the extents of this cluster 1141 zoomToBounds: function ( ) {1426 zoomToBounds: function (fitBoundsOptions) { 1142 1427 var childClusters = this._childClusters.slice(), 1143 1428 map = this._group._map, … … 1162 1447 this._group._map.setView(this._latlng, mapZoom + 1); 1163 1448 } else { 1164 this._group._map.fitBounds(this._bounds );1449 this._group._map.fitBounds(this._bounds, fitBoundsOptions); 1165 1450 } 1166 1451 }, … … 1195 1480 1196 1481 this._iconNeedsUpdate = true; 1197 this._expandBounds(new1); 1482 1483 this._boundsNeedUpdate = true; 1484 this._setClusterCenter(new1); 1198 1485 1199 1486 if (new1 instanceof L.MarkerCluster) { … … 1215 1502 }, 1216 1503 1217 //Expand our bounds and tell our parent to 1218 _expandBounds: function (marker) { 1219 var addedCount, 1220 addedLatLng = marker._wLatLng || marker._latlng; 1221 1222 if (marker instanceof L.MarkerCluster) { 1223 this._bounds.extend(marker._bounds); 1224 addedCount = marker._childCount; 1225 } else { 1226 this._bounds.extend(addedLatLng); 1227 addedCount = 1; 1228 } 1229 1504 /** 1505 * Makes sure the cluster center is set. If not, uses the child center if it is a cluster, or the marker position. 1506 * @param child L.MarkerCluster|L.Marker that will be used as cluster center if not defined yet. 1507 * @private 1508 */ 1509 _setClusterCenter: function (child) { 1230 1510 if (!this._cLatLng) { 1231 1511 // when clustering, take position of the first point as the cluster center 1232 this._cLatLng = marker._cLatLng || addedLatLng; 1233 } 1234 1235 // when showing clusters, take weighted average of all points as cluster center 1236 var totalCount = this._childCount + addedCount; 1237 1238 //Calculate weighted latlng for display 1239 if (!this._wLatLng) { 1240 this._latlng = this._wLatLng = new L.LatLng(addedLatLng.lat, addedLatLng.lng); 1241 } else { 1242 this._wLatLng.lat = (addedLatLng.lat * addedCount + this._wLatLng.lat * this._childCount) / totalCount; 1243 this._wLatLng.lng = (addedLatLng.lng * addedCount + this._wLatLng.lng * this._childCount) / totalCount; 1244 } 1512 this._cLatLng = child._cLatLng || child._latlng; 1513 } 1514 }, 1515 1516 /** 1517 * Assigns impossible bounding values so that the next extend entirely determines the new bounds. 1518 * This method avoids having to trash the previous L.LatLngBounds object and to create a new one, which is much slower for this class. 1519 * As long as the bounds are not extended, most other methods would probably fail, as they would with bounds initialized but not extended. 1520 * @private 1521 */ 1522 _resetBounds: function () { 1523 var bounds = this._bounds; 1524 1525 if (bounds._southWest) { 1526 bounds._southWest.lat = Infinity; 1527 bounds._southWest.lng = Infinity; 1528 } 1529 if (bounds._northEast) { 1530 bounds._northEast.lat = -Infinity; 1531 bounds._northEast.lng = -Infinity; 1532 } 1533 }, 1534 1535 _recalculateBounds: function () { 1536 var markers = this._markers, 1537 childClusters = this._childClusters, 1538 latSum = 0, 1539 lngSum = 0, 1540 totalCount = this._childCount, 1541 i, child, childLatLng, childCount; 1542 1543 // Case where all markers are removed from the map and we are left with just an empty _topClusterLevel. 1544 if (totalCount === 0) { 1545 return; 1546 } 1547 1548 // Reset rather than creating a new object, for performance. 1549 this._resetBounds(); 1550 1551 // Child markers. 1552 for (i = 0; i < markers.length; i++) { 1553 childLatLng = markers[i]._latlng; 1554 1555 this._bounds.extend(childLatLng); 1556 1557 latSum += childLatLng.lat; 1558 lngSum += childLatLng.lng; 1559 } 1560 1561 // Child clusters. 1562 for (i = 0; i < childClusters.length; i++) { 1563 child = childClusters[i]; 1564 1565 // Re-compute child bounds and weighted position first if necessary. 1566 if (child._boundsNeedUpdate) { 1567 child._recalculateBounds(); 1568 } 1569 1570 this._bounds.extend(child._bounds); 1571 1572 childLatLng = child._wLatLng; 1573 childCount = child._childCount; 1574 1575 latSum += childLatLng.lat * childCount; 1576 lngSum += childLatLng.lng * childCount; 1577 } 1578 1579 this._latlng = this._wLatLng = new L.LatLng(latSum / totalCount, lngSum / totalCount); 1580 1581 // Reset dirty flag. 1582 this._boundsNeedUpdate = false; 1245 1583 }, 1246 1584 … … 1255 1593 1256 1594 _recursivelyAnimateChildrenIn: function (bounds, center, maxZoom) { 1257 this._recursively(bounds, 0, maxZoom - 1,1595 this._recursively(bounds, this._group._map.getMinZoom(), maxZoom - 1, 1258 1596 function (c) { 1259 1597 var markers = c._markers, … … 1265 1603 if (m._icon) { 1266 1604 m._setPos(center); 1267 m. setOpacity(0);1605 m.clusterHide(); 1268 1606 } 1269 1607 } … … 1276 1614 if (cm._icon) { 1277 1615 cm._setPos(center); 1278 cm. setOpacity(0);1616 cm.clusterHide(); 1279 1617 } 1280 1618 } … … 1283 1621 }, 1284 1622 1285 _recursivelyAnimateChildrenInAndAddSelfToMap: function (bounds, previousZoomLevel, newZoomLevel) {1286 this._recursively(bounds, newZoomLevel, 0,1623 _recursivelyAnimateChildrenInAndAddSelfToMap: function (bounds, mapMinZoom, previousZoomLevel, newZoomLevel) { 1624 this._recursively(bounds, newZoomLevel, mapMinZoom, 1287 1625 function (c) { 1288 1626 c._recursivelyAnimateChildrenIn(bounds, c._group._map.latLngToLayerPoint(c.getLatLng()).round(), previousZoomLevel); … … 1291 1629 //As a hack we only do a animation free zoom on a single level zoom, if someone does multiple levels then we always animate 1292 1630 if (c._isSingleParent() && previousZoomLevel - 1 === newZoomLevel) { 1293 c. setOpacity(1);1294 c._recursivelyRemoveChildrenFromMap(bounds, previousZoomLevel); //Immediately remove our children as we are replacing them. TODO previousBounds not bounds1631 c.clusterShow(); 1632 c._recursivelyRemoveChildrenFromMap(bounds, mapMinZoom, previousZoomLevel); //Immediately remove our children as we are replacing them. TODO previousBounds not bounds 1295 1633 } else { 1296 c. setOpacity(0);1634 c.clusterHide(); 1297 1635 } 1298 1636 … … 1303 1641 1304 1642 _recursivelyBecomeVisible: function (bounds, zoomLevel) { 1305 this._recursively(bounds, 0, zoomLevel, null, function (c) {1306 c. setOpacity(1);1643 this._recursively(bounds, this._group._map.getMinZoom(), zoomLevel, null, function (c) { 1644 c.clusterShow(); 1307 1645 }); 1308 1646 }, 1309 1647 1310 1648 _recursivelyAddChildrenToMap: function (startPos, zoomLevel, bounds) { 1311 this._recursively(bounds, -1, zoomLevel,1649 this._recursively(bounds, this._group._map.getMinZoom() - 1, zoomLevel, 1312 1650 function (c) { 1313 1651 if (zoomLevel === c._zoom) { … … 1327 1665 1328 1666 nm.setLatLng(startPos); 1329 if (nm. setOpacity) {1330 nm. setOpacity(0);1667 if (nm.clusterHide) { 1668 nm.clusterHide(); 1331 1669 } 1332 1670 } … … 1371 1709 1372 1710 //exceptBounds: If set, don't remove any markers/clusters in it 1373 _recursivelyRemoveChildrenFromMap: function (previousBounds, zoomLevel, exceptBounds) {1711 _recursivelyRemoveChildrenFromMap: function (previousBounds, mapMinZoom, zoomLevel, exceptBounds) { 1374 1712 var m, i; 1375 this._recursively(previousBounds, -1, zoomLevel - 1,1713 this._recursively(previousBounds, mapMinZoom - 1, zoomLevel - 1, 1376 1714 function (c) { 1377 1715 //Remove markers at every level … … 1380 1718 if (!exceptBounds || !exceptBounds.contains(m._latlng)) { 1381 1719 c._group._featureGroup.removeLayer(m); 1382 if (m. setOpacity) {1383 m. setOpacity(1);1720 if (m.clusterShow) { 1721 m.clusterShow(); 1384 1722 } 1385 1723 } … … 1392 1730 if (!exceptBounds || !exceptBounds.contains(m._latlng)) { 1393 1731 c._group._featureGroup.removeLayer(m); 1394 if (m. setOpacity) {1395 m. setOpacity(1);1732 if (m.clusterShow) { 1733 m.clusterShow(); 1396 1734 } 1397 1735 } … … 1410 1748 var childClusters = this._childClusters, 1411 1749 zoom = this._zoom, 1412 i, c; 1413 1414 if (zoomLevelToStart > zoom) { //Still going down to required depth, just recurse to child clusters 1750 i, c; 1751 1752 if (zoomLevelToStart <= zoom) { 1753 if (runAtEveryLevel) { 1754 runAtEveryLevel(this); 1755 } 1756 if (runAtBottomLevel && zoom === zoomLevelToStop) { 1757 runAtBottomLevel(this); 1758 } 1759 } 1760 1761 if (zoom < zoomLevelToStart || zoom < zoomLevelToStop) { 1415 1762 for (i = childClusters.length - 1; i >= 0; i--) { 1416 1763 c = childClusters[i]; … … 1419 1766 } 1420 1767 } 1421 } else { //In required depth 1422 1423 if (runAtEveryLevel) { 1424 runAtEveryLevel(this); 1425 } 1426 if (runAtBottomLevel && this._zoom === zoomLevelToStop) { 1427 runAtBottomLevel(this); 1428 } 1429 1430 //TODO: This loop is almost the same as above 1431 if (zoomLevelToStop > zoom) { 1432 for (i = childClusters.length - 1; i >= 0; i--) { 1433 c = childClusters[i]; 1434 if (boundsToApplyTo.intersects(c._bounds)) { 1435 c._recursively(boundsToApplyTo, zoomLevelToStart, zoomLevelToStop, runAtEveryLevel, runAtBottomLevel); 1436 } 1437 } 1438 } 1439 } 1440 }, 1441 1442 _recalculateBounds: function () { 1443 var markers = this._markers, 1444 childClusters = this._childClusters, 1445 i; 1446 1447 this._bounds = new L.LatLngBounds(); 1448 delete this._wLatLng; 1449 1450 for (i = markers.length - 1; i >= 0; i--) { 1451 this._expandBounds(markers[i]); 1452 } 1453 for (i = childClusters.length - 1; i >= 0; i--) { 1454 this._expandBounds(childClusters[i]); 1455 } 1456 }, 1457 1768 } 1769 }, 1458 1770 1459 1771 //Returns true if we are the parent of only one cluster and that cluster is the same as us … … 1463 1775 } 1464 1776 }); 1777 1778 1779 1780 /* 1781 * Extends L.Marker to include two extra methods: clusterHide and clusterShow. 1782 * 1783 * They work as setOpacity(0) and setOpacity(1) respectively, but 1784 * they will remember the marker's opacity when hiding and showing it again. 1785 * 1786 */ 1787 1788 1789 L.Marker.include({ 1790 1791 clusterHide: function () { 1792 this.options.opacityWhenUnclustered = this.options.opacity || 1; 1793 return this.setOpacity(0); 1794 }, 1795 1796 clusterShow: function () { 1797 var ret = this.setOpacity(this.options.opacity || this.options.opacityWhenUnclustered); 1798 delete this.options.opacityWhenUnclustered; 1799 return ret; 1800 } 1801 1802 }); 1803 1804 1465 1805 1466 1806 … … 1559 1899 obj = cell[k]; 1560 1900 dist = this._sqDist(objectPoint[L.Util.stamp(obj)], point); 1561 if (dist < closestDistSq) { 1901 if (dist < closestDistSq || 1902 dist <= closestDistSq && closest === null) { 1562 1903 closestDistSq = dist; 1563 1904 closest = obj; … … 1572 1913 1573 1914 _getCoord: function (x) { 1574 return Math.floor(x / this._cellSize); 1915 var coord = Math.floor(x / this._cellSize); 1916 return isFinite(coord) ? coord : x; 1575 1917 }, 1576 1918 … … 1693 2035 // find first baseline 1694 2036 var maxLat = false, minLat = false, 2037 maxLng = false, minLng = false, 2038 maxLatPt = null, minLatPt = null, 2039 maxLngPt = null, minLngPt = null, 1695 2040 maxPt = null, minPt = null, 1696 2041 i; … … 1699 2044 var pt = latLngs[i]; 1700 2045 if (maxLat === false || pt.lat > maxLat) { 1701 max Pt = pt;2046 maxLatPt = pt; 1702 2047 maxLat = pt.lat; 1703 2048 } 1704 2049 if (minLat === false || pt.lat < minLat) { 1705 min Pt = pt;2050 minLatPt = pt; 1706 2051 minLat = pt.lat; 1707 2052 } 1708 } 2053 if (maxLng === false || pt.lng > maxLng) { 2054 maxLngPt = pt; 2055 maxLng = pt.lng; 2056 } 2057 if (minLng === false || pt.lng < minLng) { 2058 minLngPt = pt; 2059 minLng = pt.lng; 2060 } 2061 } 2062 2063 if (minLat !== maxLat) { 2064 minPt = minLatPt; 2065 maxPt = maxLatPt; 2066 } else { 2067 minPt = minLngPt; 2068 maxPt = maxLngPt; 2069 } 2070 1709 2071 var ch = [].concat(this.buildConvexHull([minPt, maxPt], latLngs), 1710 2072 this.buildConvexHull([maxPt, minPt], latLngs)); … … 1765 2127 positions = this._generatePointsSpiral(childMarkers.length, center); 1766 2128 } else { 1767 center.y += 10; // Otherwise circles look wrong2129 center.y += 10; // Otherwise circles look wrong => hack for standard blue icon, renders differently for other icons. 1768 2130 positions = this._generatePointsCircle(childMarkers.length, center); 1769 2131 } … … 1800 2162 1801 2163 _generatePointsSpiral: function (count, centerPt) { 1802 var legLength = this._group.options.spiderfyDistanceMultiplier * this._spiralLengthStart, 1803 separation = this._group.options.spiderfyDistanceMultiplier * this._spiralFootSeparation, 1804 lengthFactor = this._group.options.spiderfyDistanceMultiplier * this._spiralLengthFactor, 2164 var spiderfyDistanceMultiplier = this._group.options.spiderfyDistanceMultiplier, 2165 legLength = spiderfyDistanceMultiplier * this._spiralLengthStart, 2166 separation = spiderfyDistanceMultiplier * this._spiralFootSeparation, 2167 lengthFactor = spiderfyDistanceMultiplier * this._spiralLengthFactor * this._2PI, 1805 2168 angle = 0, 1806 2169 res = [], … … 1809 2172 res.length = count; 1810 2173 2174 // Higher index, closer position to cluster center. 1811 2175 for (i = count - 1; i >= 0; i--) { 1812 2176 angle += separation / legLength + i * 0.0005; 1813 2177 res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round(); 1814 legLength += this._2PI *lengthFactor / angle;2178 legLength += lengthFactor / angle; 1815 2179 } 1816 2180 return res; … … 1824 2188 m, i; 1825 2189 2190 group._ignoreMove = true; 2191 1826 2192 this.setOpacity(1); 1827 2193 for (i = childMarkers.length - 1; i >= 0; i--) { … … 1844 2210 } 1845 2211 2212 group.fire('unspiderfied', { 2213 cluster: this, 2214 markers: childMarkers 2215 }); 2216 group._ignoreMove = false; 1846 2217 group._spiderfied = null; 1847 2218 } 1848 2219 }); 1849 2220 1850 L.MarkerCluster.include(!L.DomUtil.TRANSITION ? { 1851 //Non Animated versions of everything 2221 //Non Animated versions of everything 2222 L.MarkerClusterNonAnimated = L.MarkerCluster.extend({ 1852 2223 _animationSpiderfy: function (childMarkers, positions) { 1853 2224 var group = this._group, 1854 2225 map = group._map, 1855 2226 fg = group._featureGroup, 2227 legOptions = this._group.options.spiderLegPolylineOptions, 1856 2228 i, m, leg, newPos; 1857 2229 1858 for (i = childMarkers.length - 1; i >= 0; i--) { 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++) { 1859 2235 newPos = map.layerPointToLatLng(positions[i]); 1860 2236 m = childMarkers[i]; 1861 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 L.Polyline([this._latlng, newPos], legOptions); 2240 map.addLayer(leg); 2241 m._spiderLeg = leg; 2242 2243 // Now add the marker. 1862 2244 m._preSpiderfyLatlng = m._latlng; 1863 2245 m.setLatLng(newPos); … … 1867 2249 1868 2250 fg.addLayer(m); 1869 1870 1871 leg = new L.Polyline([this._latlng, newPos], { weight: 1.5, color: '#222' });1872 map.addLayer(leg);1873 m._spiderLeg = leg;1874 2251 } 1875 2252 this.setOpacity(0.3); 1876 group.fire('spiderfied'); 2253 2254 group._ignoreMove = false; 2255 group.fire('spiderfied', { 2256 cluster: this, 2257 markers: childMarkers 2258 }); 1877 2259 }, 1878 2260 … … 1880 2262 this._noanimationUnspiderfy(); 1881 2263 } 1882 } : { 1883 //Animated versions here 1884 SVG_ANIMATION: (function () { 1885 return document.createElementNS('http://www.w3.org/2000/svg', 'animate').toString().indexOf('SVGAnimate') > -1; 1886 }()), 2264 }); 2265 2266 //Animated versions here 2267 L.MarkerCluster.include({ 1887 2268 1888 2269 _animationSpiderfy: function (childMarkers, positions) { … … 1891 2272 map = group._map, 1892 2273 fg = group._featureGroup, 1893 thisLayerPos = map.latLngToLayerPoint(this._latlng), 1894 i, m, leg, newPos; 1895 1896 //Add markers to map hidden at our center point 1897 for (i = childMarkers.length - 1; i >= 0; i--) { 2274 thisLayerLatLng = this._latlng, 2275 thisLayerPos = map.latLngToLayerPoint(thisLayerLatLng), 2276 svg = L.Path.SVG, 2277 legOptions = L.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 = L.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++) { 1898 2302 m = childMarkers[i]; 1899 2303 1900 //If it is a marker, add it now and we'll animate it out 1901 if (m.setOpacity) { 1902 m.setZIndexOffset(1000000); //Make these appear on top of EVERYTHING 1903 m.setOpacity(0); 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 L.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 } 1904 2327 1905 fg.addLayer(m); 1906 2328 // Vectors just get immediately added 2329 fg.addLayer(m); 2330 2331 if (m._setPos) { 1907 2332 m._setPos(thisLayerPos); 1908 } else {1909 //Vectors just get immediately added1910 fg.addLayer(m);1911 2333 } 1912 2334 } … … 1915 2337 group._animationStart(); 1916 2338 1917 var initialLegOpacity = L.Path.SVG ? 0 : 0.3, 1918 xmlns = L.Path.SVG_NS; 1919 1920 2339 // Reveal markers and spider legs. 1921 2340 for (i = childMarkers.length - 1; i >= 0; i--) { 1922 2341 newPos = map.layerPointToLatLng(positions[i]); … … 1927 2346 m.setLatLng(newPos); 1928 2347 1929 if (m.setOpacity) { 1930 m.setOpacity(1); 1931 } 1932 1933 1934 //Add Legs. 1935 leg = new L.Polyline([me._latlng, newPos], { weight: 1.5, color: '#222', opacity: initialLegOpacity }); 1936 map.addLayer(leg); 1937 m._spiderLeg = leg; 1938 1939 //Following animations don't work for canvas 1940 if (!L.Path.SVG || !this.SVG_ANIMATION) { 1941 continue; 1942 } 1943 1944 //How this works: 1945 //http://stackoverflow.com/questions/5924238/how-do-you-animate-an-svg-path-in-ios 1946 //http://dev.opera.com/articles/view/advanced-svg-animation-techniques/ 1947 1948 //Animate length 1949 var length = leg._path.getTotalLength(); 1950 leg._path.setAttribute("stroke-dasharray", length + "," + length); 1951 1952 var anim = document.createElementNS(xmlns, "animate"); 1953 anim.setAttribute("attributeName", "stroke-dashoffset"); 1954 anim.setAttribute("begin", "indefinite"); 1955 anim.setAttribute("from", length); 1956 anim.setAttribute("to", 0); 1957 anim.setAttribute("dur", 0.25); 1958 leg._path.appendChild(anim); 1959 anim.beginElement(); 1960 1961 //Animate opacity 1962 anim = document.createElementNS(xmlns, "animate"); 1963 anim.setAttribute("attributeName", "stroke-opacity"); 1964 anim.setAttribute("attributeName", "stroke-opacity"); 1965 anim.setAttribute("begin", "indefinite"); 1966 anim.setAttribute("from", 0); 1967 anim.setAttribute("to", 0.5); 1968 anim.setAttribute("dur", 0.25); 1969 leg._path.appendChild(anim); 1970 anim.beginElement(); 1971 } 1972 me.setOpacity(0.3); 1973 1974 //Set the opacity of the spiderLegs back to their correct value 1975 // The animations above override this until they complete. 1976 // If the initial opacity of the spiderlegs isn't 0 then they appear before the animation starts. 1977 if (L.Path.SVG) { 1978 this._group._forceLayout(); 1979 1980 for (i = childMarkers.length - 1; i >= 0; i--) { 1981 m = childMarkers[i]._spiderLeg; 1982 1983 m.options.opacity = 0.5; 1984 m._path.setAttribute('stroke-opacity', 0.5); 1985 } 1986 } 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; 1987 2364 1988 2365 setTimeout(function () { 1989 2366 group._animationEnd(); 1990 group.fire('spiderfied'); 2367 group.fire('spiderfied', { 2368 cluster: me, 2369 markers: childMarkers 2370 }); 1991 2371 }, 200); 1992 2372 }, 1993 2373 1994 2374 _animationUnspiderfy: function (zoomDetails) { 1995 var group = this._group, 2375 var me = this, 2376 group = this._group, 1996 2377 map = group._map, 1997 2378 fg = group._featureGroup, 1998 2379 thisLayerPos = zoomDetails ? map._latLngToNewLayerPoint(this._latlng, zoomDetails.zoom, zoomDetails.center) : map.latLngToLayerPoint(this._latlng), 1999 2380 childMarkers = this.getAllChildMarkers(), 2000 svg = L.Path.SVG && this.SVG_ANIMATION, 2001 m, i, a; 2002 2381 svg = L.Path.SVG, 2382 m, i, leg, legPath, legLength, nonAnimatable; 2383 2384 group._ignoreMove = true; 2003 2385 group._animationStart(); 2004 2386 … … 2008 2390 m = childMarkers[i]; 2009 2391 2010 //Marker was added to us after we were spid ified2392 //Marker was added to us after we were spiderfied 2011 2393 if (!m._preSpiderfyLatlng) { 2012 2394 continue; 2013 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(); 2014 2399 2015 2400 //Fix up the location to the real one 2016 2401 m.setLatLng(m._preSpiderfyLatlng); 2017 2402 delete m._preSpiderfyLatlng; 2403 2018 2404 //Hack override the location to be our center 2019 if (m.setOpacity) { 2405 nonAnimatable = true; 2406 if (m._setPos) { 2020 2407 m._setPos(thisLayerPos); 2021 m.setOpacity(0); 2022 } else { 2408 nonAnimatable = false; 2409 } 2410 if (m.clusterHide) { 2411 m.clusterHide(); 2412 nonAnimatable = false; 2413 } 2414 if (nonAnimatable) { 2023 2415 fg.removeLayer(m); 2024 2416 } 2025 2417 2026 // Animate the spider legs back in2418 // Animate the spider leg back in (animation is actually delegated to CSS transition). 2027 2419 if (svg) { 2028 a = m._spiderLeg._path.childNodes[0]; 2029 a.setAttribute('to', a.getAttribute('from')); 2030 a.setAttribute('from', 0); 2031 a.beginElement(); 2032 2033 a = m._spiderLeg._path.childNodes[1]; 2034 a.setAttribute('from', 0.5); 2035 a.setAttribute('to', 0); 2036 a.setAttribute('stroke-opacity', 0); 2037 a.beginElement(); 2038 2039 m._spiderLeg._path.setAttribute('stroke-opacity', 0); 2040 } 2041 } 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; 2042 2429 2043 2430 setTimeout(function () { … … 2059 2446 } 2060 2447 2061 2062 if (m.setOpacity) { 2063 m.setOpacity(1); 2448 if (m.clusterShow) { 2449 m.clusterShow(); 2450 } 2451 if (m.setZIndexOffset) { 2064 2452 m.setZIndexOffset(0); 2065 2453 } … … 2073 2461 } 2074 2462 group._animationEnd(); 2463 group.fire('unspiderfied', { 2464 cluster: me, 2465 markers: childMarkers 2466 }); 2075 2467 }, 200); 2076 2468 } … … 2082 2474 _spiderfied: null, 2083 2475 2476 unspiderfy: function () { 2477 this._unspiderfy.apply(this, arguments); 2478 }, 2479 2084 2480 _spiderfierOnAdd: function () { 2085 2481 this._map.on('click', this._unspiderfyWrapper, this); … … 2091 2487 this._map.on('zoomend', this._noanimationUnspiderfy, this); 2092 2488 2093 if ( L.Path.SVG &&!L.Browser.touch) {2094 this._map. _initPathRoot();2489 if (!L.Browser.touch) { 2490 this._map.getRenderer(this); 2095 2491 //Needs to happen in the pageload, not after, or animations don't work in webkit 2096 2492 // http://stackoverflow.com/questions/8455200/svg-animate-with-dynamically-added-elements … … 2103 2499 this._map.off('zoomstart', this._unspiderfyZoomStart, this); 2104 2500 this._map.off('zoomanim', this._unspiderfyZoomAnim, this); 2105 2106 this._unspiderfy(); //Ensure that markers are back where they should be 2107 }, 2108 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 }, 2109 2507 2110 2508 //On zoom start we add a zoomanim handler so that we are guaranteed to be last (after markers are animated) … … 2117 2515 this._map.on('zoomanim', this._unspiderfyZoomAnim, this); 2118 2516 }, 2517 2119 2518 _unspiderfyZoomAnim: function (zoomDetails) { 2120 2519 //Wait until the first zoomanim after the user has finished touch-zooming before running the animation … … 2127 2526 }, 2128 2527 2129 2130 2528 _unspiderfyWrapper: function () { 2131 2529 /// <summary>_unspiderfy but passes no arguments</summary> … … 2150 2548 this._featureGroup.removeLayer(layer); 2151 2549 2152 layer.setOpacity(1); 2153 //Position will be fixed up immediately in _animationUnspiderfy 2154 layer.setZIndexOffset(0); 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 } 2155 2557 2156 2558 this._map.removeLayer(layer._spiderLeg); … … 2161 2563 2162 2564 2565 /** 2566 * Adds 1 public method to MCG and 1 to L.Marker to facilitate changing 2567 * markers' icon options and refreshing their icon and their parent clusters 2568 * accordingly (case where their iconCreateFunction uses data of childMarkers 2569 * to make up the cluster icon). 2570 */ 2571 2572 2573 L.MarkerClusterGroup.include({ 2574 /** 2575 * Updates the icon of all clusters which are parents of the given marker(s). 2576 * In singleMarkerMode, also updates the given marker(s) icon. 2577 * @param layers L.MarkerClusterGroup|L.LayerGroup|Array(L.Marker)|Map(L.Marker)| 2578 * L.MarkerCluster|L.Marker (optional) list of markers (or single marker) whose parent 2579 * clusters need to be updated. If not provided, retrieves all child markers of this. 2580 * @returns {L.MarkerClusterGroup} 2581 */ 2582 refreshClusters: function (layers) { 2583 if (!layers) { 2584 layers = this._topClusterLevel.getAllChildMarkers(); 2585 } else if (layers instanceof L.MarkerClusterGroup) { 2586 layers = layers._topClusterLevel.getAllChildMarkers(); 2587 } else if (layers instanceof L.LayerGroup) { 2588 layers = layers._layers; 2589 } else if (layers instanceof L.MarkerCluster) { 2590 layers = layers.getAllChildMarkers(); 2591 } else if (layers instanceof L.Marker) { 2592 layers = [layers]; 2593 } // else: must be an Array(L.Marker)|Map(L.Marker) 2594 this._flagParentsIconsNeedUpdate(layers); 2595 this._refreshClustersIcons(); 2596 2597 // In case of singleMarkerMode, also re-draw the markers. 2598 if (this.options.singleMarkerMode) { 2599 this._refreshSingleMarkerModeMarkers(layers); 2600 } 2601 2602 return this; 2603 }, 2604 2605 /** 2606 * Simply flags all parent clusters of the given markers as having a "dirty" icon. 2607 * @param layers Array(L.Marker)|Map(L.Marker) list of markers. 2608 * @private 2609 */ 2610 _flagParentsIconsNeedUpdate: function (layers) { 2611 var id, parent; 2612 2613 // Assumes layers is an Array or an Object whose prototype is non-enumerable. 2614 for (id in layers) { 2615 // Flag parent clusters' icon as "dirty", all the way up. 2616 // Dumb process that flags multiple times upper parents, but still 2617 // much more efficient than trying to be smart and make short lists, 2618 // at least in the case of a hierarchy following a power law: 2619 // http://jsperf.com/flag-nodes-in-power-hierarchy/2 2620 parent = layers[id].__parent; 2621 while (parent) { 2622 parent._iconNeedsUpdate = true; 2623 parent = parent.__parent; 2624 } 2625 } 2626 }, 2627 2628 /** 2629 * Re-draws the icon of the supplied markers. 2630 * To be used in singleMarkerMode only. 2631 * @param layers Array(L.Marker)|Map(L.Marker) list of markers. 2632 * @private 2633 */ 2634 _refreshSingleMarkerModeMarkers: function (layers) { 2635 var id, layer; 2636 2637 for (id in layers) { 2638 layer = layers[id]; 2639 2640 // Make sure we do not override markers that do not belong to THIS group. 2641 if (this.hasLayer(layer)) { 2642 // Need to re-create the icon first, then re-draw the marker. 2643 layer.setIcon(this._overrideMarkerIcon(layer)); 2644 } 2645 } 2646 } 2647 }); 2648 2649 L.Marker.include({ 2650 /** 2651 * Updates the given options in the marker's icon and refreshes the marker. 2652 * @param options map object of icon options. 2653 * @param directlyRefreshClusters boolean (optional) true to trigger 2654 * MCG.refreshClustersOf() right away with this single marker. 2655 * @returns {L.Marker} 2656 */ 2657 refreshIconOptions: function (options, directlyRefreshClusters) { 2658 var icon = this.options.icon; 2659 2660 L.setOptions(icon, options); 2661 2662 this.setIcon(icon); 2663 2664 // Shortcut to refresh the associated MCG clusters right away. 2665 // To be used when refreshing a single marker. 2666 // Otherwise, better use MCG.refreshClusters() once at the end with 2667 // the list of modified markers. 2668 if (directlyRefreshClusters && this.__parent) { 2669 this.__parent._group.refreshClusters(this); 2670 } 2671 2672 return this; 2673 } 2674 }); 2675 2676 2163 2677 }(window, document)); -
binary-improvements/webserver/leaflet/markercluster/leaflet.markercluster.js
r173 r315 2 2 Leaflet.markercluster, Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps. 3 3 https://github.com/Leaflet/Leaflet.markercluster 4 (c) 2012-201 3, Dave Leaver, smartrak4 (c) 2012-2017, Dave Leaver 5 5 */ 6 !function(t,e){L.MarkerClusterGroup=L.FeatureGroup.extend({options:{maxClusterRadius:80,iconCreateFunction:null,spiderfyOnMaxZoom:!0,showCoverageOnHover:!0,zoomToBoundsOnClick:!0,singleMarkerMode:!1,disableClusteringAtZoom:null,removeOutsideVisibleBounds:!0,animateAddingMarkers:!1,spiderfyDistanceMultiplier:1,chunkedLoading:!1,chunkInterval:200,chunkDelay:50,chunkProgress:null,polygonOptions:{}},initialize:function(t){L.Util.setOptions(this,t),this.options.iconCreateFunction||(this.options.iconCreateFunction=this._defaultIconCreateFunction),this._featureGroup=L.featureGroup(),this._featureGroup.on(L.FeatureGroup.EVENTS,this._propagateEvent,this),this._nonPointGroup=L.featureGroup(),this._nonPointGroup.on(L.FeatureGroup.EVENTS,this._propagateEvent,this),this._inZoomAnimation=0,this._needsClustering=[],this._needsRemoving=[],this._currentShownBounds=null,this._queue=[]},addLayer:function(t){if(t instanceof L.LayerGroup){var e=[];for(var i in t._layers)e.push(t._layers[i]);return this.addLayers(e)}if(!t.getLatLng)return this._nonPointGroup.addLayer(t),this;if(!this._map)return this._needsClustering.push(t),this;if(this.hasLayer(t))return this;this._unspiderfy&&this._unspiderfy(),this._addLayer(t,this._maxZoom);var n=t,s=this._map.getZoom();if(t.__parent)for(;n.__parent._zoom>=s;)n=n.__parent;return this._currentShownBounds.contains(n.getLatLng())&&(this.options.animateAddingMarkers?this._animationAddLayer(t,n):this._animationAddLayerNonAnimated(t,n)),this},removeLayer:function(t){if(t instanceof L.LayerGroup){var e=[];for(var i in t._layers)e.push(t._layers[i]);return this.removeLayers(e)}return t.getLatLng?this._map?t.__parent?(this._unspiderfy&&(this._unspiderfy(),this._unspiderfyLayer(t)),this._removeLayer(t,!0),this._featureGroup.hasLayer(t)&&(this._featureGroup.removeLayer(t),t.setOpacity&&t.setOpacity(1)),this):this:(!this._arraySplice(this._needsClustering,t)&&this.hasLayer(t)&&this._needsRemoving.push(t),this):(this._nonPointGroup.removeLayer(t),this)},addLayers:function(t){var e,i,n,s,r=this._featureGroup,o=this._nonPointGroup,a=this.options.chunkedLoading,h=this.options.chunkInterval,_=this.options.chunkProgress;if(this._map){var u=0,l=(new Date).getTime(),d=L.bind(function(){for(var e=(new Date).getTime();u<t.length;u++){if(a&&0===u%200){var i=(new Date).getTime()-e;if(i>h)break}if(s=t[u],s.getLatLng){if(!this.hasLayer(s)&&(this._addLayer(s,this._maxZoom),s.__parent&&2===s.__parent.getChildCount())){var n=s.__parent.getAllChildMarkers(),p=n[0]===s?n[1]:n[0];r.removeLayer(p)}}else o.addLayer(s)}_&&_(u,t.length,(new Date).getTime()-l),u===t.length?(this._featureGroup.eachLayer(function(t){t instanceof L.MarkerCluster&&t._iconNeedsUpdate&&t._updateIcon()}),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds)):setTimeout(d,this.options.chunkDelay)},this);d()}else{for(e=[],i=0,n=t.length;n>i;i++)s=t[i],s.getLatLng?this.hasLayer(s)||e.push(s):o.addLayer(s);this._needsClustering=this._needsClustering.concat(e)}return this},removeLayers:function(t){var e,i,n,s=this._featureGroup,r=this._nonPointGroup;if(!this._map){for(e=0,i=t.length;i>e;e++)n=t[e],this._arraySplice(this._needsClustering,n),r.removeLayer(n);return this}for(e=0,i=t.length;i>e;e++)n=t[e],n.__parent?(this._removeLayer(n,!0,!0),s.hasLayer(n)&&(s.removeLayer(n),n.setOpacity&&n.setOpacity(1))):r.removeLayer(n);return this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds),s.eachLayer(function(t){t instanceof L.MarkerCluster&&t._updateIcon()}),this},clearLayers:function(){return this._map||(this._needsClustering=[],delete this._gridClusters,delete this._gridUnclustered),this._noanimationUnspiderfy&&this._noanimationUnspiderfy(),this._featureGroup.clearLayers(),this._nonPointGroup.clearLayers(),this.eachLayer(function(t){delete t.__parent}),this._map&&this._generateInitialClusters(),this},getBounds:function(){var t=new L.LatLngBounds;this._topClusterLevel&&t.extend(this._topClusterLevel._bounds);for(var e=this._needsClustering.length-1;e>=0;e--)t.extend(this._needsClustering[e].getLatLng());return t.extend(this._nonPointGroup.getBounds()),t},eachLayer:function(t,e){var i,n=this._needsClustering.slice();for(this._topClusterLevel&&this._topClusterLevel.getAllChildMarkers(n),i=n.length-1;i>=0;i--)t.call(e,n[i]);this._nonPointGroup.eachLayer(t,e)},getLayers:function(){var t=[];return this.eachLayer(function(e){t.push(e)}),t},getLayer:function(t){var e=null;return this.eachLayer(function(i){L.stamp(i)===t&&(e=i)}),e},hasLayer:function(t){if(!t)return!1;var e,i=this._needsClustering;for(e=i.length-1;e>=0;e--)if(i[e]===t)return!0;for(i=this._needsRemoving,e=i.length-1;e>=0;e--)if(i[e]===t)return!1;return!(!t.__parent||t.__parent._group!==this)||this._nonPointGroup.hasLayer(t)},zoomToShowLayer:function(t,e){var i=function(){if((t._icon||t.__parent._icon)&&!this._inZoomAnimation)if(this._map.off("moveend",i,this),this.off("animationend",i,this),t._icon)e();else if(t.__parent._icon){var n=function(){this.off("spiderfied",n,this),e()};this.on("spiderfied",n,this),t.__parent.spiderfy()}};if(t._icon&&this._map.getBounds().contains(t.getLatLng()))e();else if(t.__parent._zoom<this._map.getZoom())this._map.on("moveend",i,this),this._map.panTo(t.getLatLng());else{var n=function(){this._map.off("movestart",n,this),n=null};this._map.on("movestart",n,this),this._map.on("moveend",i,this),this.on("animationend",i,this),t.__parent.zoomToBounds(),n&&i.call(this)}},onAdd:function(t){this._map=t;var e,i,n;if(!isFinite(this._map.getMaxZoom()))throw"Map has no maxZoom specified";for(this._featureGroup.onAdd(t),this._nonPointGroup.onAdd(t),this._gridClusters||this._generateInitialClusters(),e=0,i=this._needsRemoving.length;i>e;e++)n=this._needsRemoving[e],this._removeLayer(n,!0);this._needsRemoving=[],this._zoom=this._map.getZoom(),this._currentShownBounds=this._getExpandedVisibleBounds(),this._map.on("zoomend",this._zoomEnd,this),this._map.on("moveend",this._moveEnd,this),this._spiderfierOnAdd&&this._spiderfierOnAdd(),this._bindEvents(),i=this._needsClustering,this._needsClustering=[],this.addLayers(i)},onRemove:function(t){t.off("zoomend",this._zoomEnd,this),t.off("moveend",this._moveEnd,this),this._unbindEvents(),this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim",""),this._spiderfierOnRemove&&this._spiderfierOnRemove(),this._hideCoverage(),this._featureGroup.onRemove(t),this._nonPointGroup.onRemove(t),this._featureGroup.clearLayers(),this._map=null},getVisibleParent:function(t){for(var e=t;e&&!e._icon;)e=e.__parent;return e||null},_arraySplice:function(t,e){for(var i=t.length-1;i>=0;i--)if(t[i]===e)return t.splice(i,1),!0},_removeLayer:function(t,e,i){var n=this._gridClusters,s=this._gridUnclustered,r=this._featureGroup,o=this._map;if(e)for(var a=this._maxZoom;a>=0&&s[a].removeObject(t,o.project(t.getLatLng(),a));a--);var h,_=t.__parent,u=_._markers;for(this._arraySplice(u,t);_&&(_._childCount--,!(_._zoom<0));)e&&_._childCount<=1?(h=_._markers[0]===t?_._markers[1]:_._markers[0],n[_._zoom].removeObject(_,o.project(_._cLatLng,_._zoom)),s[_._zoom].addObject(h,o.project(h.getLatLng(),_._zoom)),this._arraySplice(_.__parent._childClusters,_),_.__parent._markers.push(h),h.__parent=_.__parent,_._icon&&(r.removeLayer(_),i||r.addLayer(h))):(_._recalculateBounds(),i&&_._icon||_._updateIcon()),_=_.__parent;delete t.__parent},_isOrIsParent:function(t,e){for(;e;){if(t===e)return!0;e=e.parentNode}return!1},_propagateEvent:function(t){if(t.layer instanceof L.MarkerCluster){if(t.originalEvent&&this._isOrIsParent(t.layer._icon,t.originalEvent.relatedTarget))return;t.type="cluster"+t.type}this.fire(t.type,t)},_defaultIconCreateFunction:function(t){var e=t.getChildCount(),i=" marker-cluster-";return i+=10>e?"small":100>e?"medium":"large",new L.DivIcon({html:"<div><span>"+e+"</span></div>",className:"marker-cluster"+i,iconSize:new L.Point(40,40)})},_bindEvents:function(){var t=this._map,e=this.options.spiderfyOnMaxZoom,i=this.options.showCoverageOnHover,n=this.options.zoomToBoundsOnClick;(e||n)&&this.on("clusterclick",this._zoomOrSpiderfy,this),i&&(this.on("clustermouseover",this._showCoverage,this),this.on("clustermouseout",this._hideCoverage,this),t.on("zoomend",this._hideCoverage,this))},_zoomOrSpiderfy:function(t){var e=this._map;e.getMaxZoom()===e.getZoom()?this.options.spiderfyOnMaxZoom&&t.layer.spiderfy():this.options.zoomToBoundsOnClick&&t.layer.zoomToBounds(),t.originalEvent&&13===t.originalEvent.keyCode&&e._container.focus()},_showCoverage:function(t){var e=this._map;this._inZoomAnimation||(this._shownPolygon&&e.removeLayer(this._shownPolygon),t.layer.getChildCount()>2&&t.layer!==this._spiderfied&&(this._shownPolygon=new L.Polygon(t.layer.getConvexHull(),this.options.polygonOptions),e.addLayer(this._shownPolygon)))},_hideCoverage:function(){this._shownPolygon&&(this._map.removeLayer(this._shownPolygon),this._shownPolygon=null)},_unbindEvents:function(){var t=this.options.spiderfyOnMaxZoom,e=this.options.showCoverageOnHover,i=this.options.zoomToBoundsOnClick,n=this._map;(t||i)&&this.off("clusterclick",this._zoomOrSpiderfy,this),e&&(this.off("clustermouseover",this._showCoverage,this),this.off("clustermouseout",this._hideCoverage,this),n.off("zoomend",this._hideCoverage,this))},_zoomEnd:function(){this._map&&(this._mergeSplitClusters(),this._zoom=this._map._zoom,this._currentShownBounds=this._getExpandedVisibleBounds())},_moveEnd:function(){if(!this._inZoomAnimation){var t=this._getExpandedVisibleBounds();this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,this._zoom,t),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._map._zoom,t),this._currentShownBounds=t}},_generateInitialClusters:function(){var t=this._map.getMaxZoom(),e=this.options.maxClusterRadius,i=e;"function"!=typeof e&&(i=function(){return e}),this.options.disableClusteringAtZoom&&(t=this.options.disableClusteringAtZoom-1),this._maxZoom=t,this._gridClusters={},this._gridUnclustered={};for(var n=t;n>=0;n--)this._gridClusters[n]=new L.DistanceGrid(i(n)),this._gridUnclustered[n]=new L.DistanceGrid(i(n));this._topClusterLevel=new L.MarkerCluster(this,-1)},_addLayer:function(t,e){var i,n,s=this._gridClusters,r=this._gridUnclustered;for(this.options.singleMarkerMode&&(t.options.icon=this.options.iconCreateFunction({getChildCount:function(){return 1},getAllChildMarkers:function(){return[t]}}));e>=0;e--){i=this._map.project(t.getLatLng(),e);var o=s[e].getNearObject(i);if(o)return o._addChild(t),t.__parent=o,void 0;if(o=r[e].getNearObject(i)){var a=o.__parent;a&&this._removeLayer(o,!1);var h=new L.MarkerCluster(this,e,o,t);s[e].addObject(h,this._map.project(h._cLatLng,e)),o.__parent=h,t.__parent=h;var _=h;for(n=e-1;n>a._zoom;n--)_=new L.MarkerCluster(this,n,_),s[n].addObject(_,this._map.project(o.getLatLng(),n));for(a._addChild(_),n=e;n>=0&&r[n].removeObject(o,this._map.project(o.getLatLng(),n));n--);return}r[e].addObject(t,i)}this._topClusterLevel._addChild(t),t.__parent=this._topClusterLevel},_enqueue:function(t){this._queue.push(t),this._queueTimeout||(this._queueTimeout=setTimeout(L.bind(this._processQueue,this),300))},_processQueue:function(){for(var t=0;t<this._queue.length;t++)this._queue[t].call(this);this._queue.length=0,clearTimeout(this._queueTimeout),this._queueTimeout=null},_mergeSplitClusters:function(){this._processQueue(),this._zoom<this._map._zoom&&this._currentShownBounds.intersects(this._getExpandedVisibleBounds())?(this._animationStart(),this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,this._zoom,this._getExpandedVisibleBounds()),this._animationZoomIn(this._zoom,this._map._zoom)):this._zoom>this._map._zoom?(this._animationStart(),this._animationZoomOut(this._zoom,this._map._zoom)):this._moveEnd()},_getExpandedVisibleBounds:function(){if(!this.options.removeOutsideVisibleBounds)return this.getBounds();var t=this._map,e=t.getBounds(),i=e._southWest,n=e._northEast,s=L.Browser.mobile?0:Math.abs(i.lat-n.lat),r=L.Browser.mobile?0:Math.abs(i.lng-n.lng);return new L.LatLngBounds(new L.LatLng(i.lat-s,i.lng-r,!0),new L.LatLng(n.lat+s,n.lng+r,!0))},_animationAddLayerNonAnimated:function(t,e){if(e===t)this._featureGroup.addLayer(t);else if(2===e._childCount){e._addToMap();var i=e.getAllChildMarkers();this._featureGroup.removeLayer(i[0]),this._featureGroup.removeLayer(i[1])}else e._updateIcon()}}),L.MarkerClusterGroup.include(L.DomUtil.TRANSITION?{_animationStart:function(){this._map._mapPane.className+=" leaflet-cluster-anim",this._inZoomAnimation++},_animationEnd:function(){this._map&&(this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim","")),this._inZoomAnimation--,this.fire("animationend")},_animationZoomIn:function(t,e){var i,n=this._getExpandedVisibleBounds(),s=this._featureGroup;this._topClusterLevel._recursively(n,t,0,function(r){var o,a=r._latlng,h=r._markers;for(n.contains(a)||(a=null),r._isSingleParent()&&t+1===e?(s.removeLayer(r),r._recursivelyAddChildrenToMap(null,e,n)):(r.setOpacity(0),r._recursivelyAddChildrenToMap(a,e,n)),i=h.length-1;i>=0;i--)o=h[i],n.contains(o._latlng)||s.removeLayer(o)}),this._forceLayout(),this._topClusterLevel._recursivelyBecomeVisible(n,e),s.eachLayer(function(t){t instanceof L.MarkerCluster||!t._icon||t.setOpacity(1)}),this._topClusterLevel._recursively(n,t,e,function(t){t._recursivelyRestoreChildPositions(e)}),this._enqueue(function(){this._topClusterLevel._recursively(n,t,0,function(t){s.removeLayer(t),t.setOpacity(1)}),this._animationEnd()})},_animationZoomOut:function(t,e){this._animationZoomOutSingle(this._topClusterLevel,t-1,e),this._topClusterLevel._recursivelyAddChildrenToMap(null,e,this._getExpandedVisibleBounds()),this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,t,this._getExpandedVisibleBounds())},_animationZoomOutSingle:function(t,e,i){var n=this._getExpandedVisibleBounds();t._recursivelyAnimateChildrenInAndAddSelfToMap(n,e+1,i);var s=this;this._forceLayout(),t._recursivelyBecomeVisible(n,i),this._enqueue(function(){if(1===t._childCount){var r=t._markers[0];r.setLatLng(r.getLatLng()),r.setOpacity&&r.setOpacity(1)}else t._recursively(n,i,0,function(t){t._recursivelyRemoveChildrenFromMap(n,e+1)});s._animationEnd()})},_animationAddLayer:function(t,e){var i=this,n=this._featureGroup;n.addLayer(t),e!==t&&(e._childCount>2?(e._updateIcon(),this._forceLayout(),this._animationStart(),t._setPos(this._map.latLngToLayerPoint(e.getLatLng())),t.setOpacity(0),this._enqueue(function(){n.removeLayer(t),t.setOpacity(1),i._animationEnd()})):(this._forceLayout(),i._animationStart(),i._animationZoomOutSingle(e,this._map.getMaxZoom(),this._map.getZoom())))},_forceLayout:function(){L.Util.falseFn(e.body.offsetWidth)}}:{_animationStart:function(){},_animationZoomIn:function(t,e){this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,t),this._topClusterLevel._recursivelyAddChildrenToMap(null,e,this._getExpandedVisibleBounds()),this.fire("animationend")},_animationZoomOut:function(t,e){this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,t),this._topClusterLevel._recursivelyAddChildrenToMap(null,e,this._getExpandedVisibleBounds()),this.fire("animationend")},_animationAddLayer:function(t,e){this._animationAddLayerNonAnimated(t,e)}}),L.markerClusterGroup=function(t){return new L.MarkerClusterGroup(t)},L.MarkerCluster=L.Marker.extend({initialize:function(t,e,i,n){L.Marker.prototype.initialize.call(this,i?i._cLatLng||i.getLatLng():new L.LatLng(0,0),{icon:this}),this._group=t,this._zoom=e,this._markers=[],this._childClusters=[],this._childCount=0,this._iconNeedsUpdate=!0,this._bounds=new L.LatLngBounds,i&&this._addChild(i),n&&this._addChild(n)},getAllChildMarkers:function(t){t=t||[];for(var e=this._childClusters.length-1;e>=0;e--)this._childClusters[e].getAllChildMarkers(t);for(var i=this._markers.length-1;i>=0;i--)t.push(this._markers[i]);return t},getChildCount:function(){return this._childCount},zoomToBounds:function(){for(var t,e=this._childClusters.slice(),i=this._group._map,n=i.getBoundsZoom(this._bounds),s=this._zoom+1,r=i.getZoom();e.length>0&&n>s;){s++;var o=[];for(t=0;t<e.length;t++)o=o.concat(e[t]._childClusters);e=o}n>s?this._group._map.setView(this._latlng,s):r>=n?this._group._map.setView(this._latlng,r+1):this._group._map.fitBounds(this._bounds)},getBounds:function(){var t=new L.LatLngBounds;return t.extend(this._bounds),t},_updateIcon:function(){this._iconNeedsUpdate=!0,this._icon&&this.setIcon(this)},createIcon:function(){return this._iconNeedsUpdate&&(this._iconObj=this._group.options.iconCreateFunction(this),this._iconNeedsUpdate=!1),this._iconObj.createIcon()},createShadow:function(){return this._iconObj.createShadow()},_addChild:function(t,e){this._iconNeedsUpdate=!0,this._expandBounds(t),t instanceof L.MarkerCluster?(e||(this._childClusters.push(t),t.__parent=this),this._childCount+=t._childCount):(e||this._markers.push(t),this._childCount++),this.__parent&&this.__parent._addChild(t,!0)},_expandBounds:function(t){var e,i=t._wLatLng||t._latlng;t instanceof L.MarkerCluster?(this._bounds.extend(t._bounds),e=t._childCount):(this._bounds.extend(i),e=1),this._cLatLng||(this._cLatLng=t._cLatLng||i);var n=this._childCount+e;this._wLatLng?(this._wLatLng.lat=(i.lat*e+this._wLatLng.lat*this._childCount)/n,this._wLatLng.lng=(i.lng*e+this._wLatLng.lng*this._childCount)/n):this._latlng=this._wLatLng=new L.LatLng(i.lat,i.lng)},_addToMap:function(t){t&&(this._backupLatlng=this._latlng,this.setLatLng(t)),this._group._featureGroup.addLayer(this)},_recursivelyAnimateChildrenIn:function(t,e,i){this._recursively(t,0,i-1,function(t){var i,n,s=t._markers;for(i=s.length-1;i>=0;i--)n=s[i],n._icon&&(n._setPos(e),n.setOpacity(0))},function(t){var i,n,s=t._childClusters;for(i=s.length-1;i>=0;i--)n=s[i],n._icon&&(n._setPos(e),n.setOpacity(0))})},_recursivelyAnimateChildrenInAndAddSelfToMap:function(t,e,i){this._recursively(t,i,0,function(n){n._recursivelyAnimateChildrenIn(t,n._group._map.latLngToLayerPoint(n.getLatLng()).round(),e),n._isSingleParent()&&e-1===i?(n.setOpacity(1),n._recursivelyRemoveChildrenFromMap(t,e)):n.setOpacity(0),n._addToMap()})},_recursivelyBecomeVisible:function(t,e){this._recursively(t,0,e,null,function(t){t.setOpacity(1)})},_recursivelyAddChildrenToMap:function(t,e,i){this._recursively(i,-1,e,function(n){if(e!==n._zoom)for(var s=n._markers.length-1;s>=0;s--){var r=n._markers[s];i.contains(r._latlng)&&(t&&(r._backupLatlng=r.getLatLng(),r.setLatLng(t),r.setOpacity&&r.setOpacity(0)),n._group._featureGroup.addLayer(r))}},function(e){e._addToMap(t)})},_recursivelyRestoreChildPositions:function(t){for(var e=this._markers.length-1;e>=0;e--){var i=this._markers[e];i._backupLatlng&&(i.setLatLng(i._backupLatlng),delete i._backupLatlng)}if(t-1===this._zoom)for(var n=this._childClusters.length-1;n>=0;n--)this._childClusters[n]._restorePosition();else for(var s=this._childClusters.length-1;s>=0;s--)this._childClusters[s]._recursivelyRestoreChildPositions(t)},_restorePosition:function(){this._backupLatlng&&(this.setLatLng(this._backupLatlng),delete this._backupLatlng)},_recursivelyRemoveChildrenFromMap:function(t,e,i){var n,s;this._recursively(t,-1,e-1,function(t){for(s=t._markers.length-1;s>=0;s--)n=t._markers[s],i&&i.contains(n._latlng)||(t._group._featureGroup.removeLayer(n),n.setOpacity&&n.setOpacity(1))},function(t){for(s=t._childClusters.length-1;s>=0;s--)n=t._childClusters[s],i&&i.contains(n._latlng)||(t._group._featureGroup.removeLayer(n),n.setOpacity&&n.setOpacity(1))})},_recursively:function(t,e,i,n,s){var r,o,a=this._childClusters,h=this._zoom;if(e>h)for(r=a.length-1;r>=0;r--)o=a[r],t.intersects(o._bounds)&&o._recursively(t,e,i,n,s);else if(n&&n(this),s&&this._zoom===i&&s(this),i>h)for(r=a.length-1;r>=0;r--)o=a[r],t.intersects(o._bounds)&&o._recursively(t,e,i,n,s)},_recalculateBounds:function(){var t,e=this._markers,i=this._childClusters;for(this._bounds=new L.LatLngBounds,delete this._wLatLng,t=e.length-1;t>=0;t--)this._expandBounds(e[t]);for(t=i.length-1;t>=0;t--)this._expandBounds(i[t])},_isSingleParent:function(){return this._childClusters.length>0&&this._childClusters[0]._childCount===this._childCount}}),L.DistanceGrid=function(t){this._cellSize=t,this._sqCellSize=t*t,this._grid={},this._objectPoint={}},L.DistanceGrid.prototype={addObject:function(t,e){var i=this._getCoord(e.x),n=this._getCoord(e.y),s=this._grid,r=s[n]=s[n]||{},o=r[i]=r[i]||[],a=L.Util.stamp(t);this._objectPoint[a]=e,o.push(t)},updateObject:function(t,e){this.removeObject(t),this.addObject(t,e)},removeObject:function(t,e){var i,n,s=this._getCoord(e.x),r=this._getCoord(e.y),o=this._grid,a=o[r]=o[r]||{},h=a[s]=a[s]||[];for(delete this._objectPoint[L.Util.stamp(t)],i=0,n=h.length;n>i;i++)if(h[i]===t)return h.splice(i,1),1===n&&delete a[s],!0},eachObject:function(t,e){var i,n,s,r,o,a,h,_=this._grid;for(i in _){o=_[i];for(n in o)for(a=o[n],s=0,r=a.length;r>s;s++)h=t.call(e,a[s]),h&&(s--,r--)}},getNearObject:function(t){var e,i,n,s,r,o,a,h,_=this._getCoord(t.x),u=this._getCoord(t.y),l=this._objectPoint,d=this._sqCellSize,p=null;for(e=u-1;u+1>=e;e++)if(s=this._grid[e])for(i=_-1;_+1>=i;i++)if(r=s[i])for(n=0,o=r.length;o>n;n++)a=r[n],h=this._sqDist(l[L.Util.stamp(a)],t),d>h&&(d=h,p=a);return p},_getCoord:function(t){return Math.floor(t/this._cellSize)},_sqDist:function(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n}},function(){L.QuickHull={getDistant:function(t,e){var i=e[1].lat-e[0].lat,n=e[0].lng-e[1].lng;return n*(t.lat-e[0].lat)+i*(t.lng-e[0].lng)},findMostDistantPointFromBaseLine:function(t,e){var i,n,s,r=0,o=null,a=[];for(i=e.length-1;i>=0;i--)n=e[i],s=this.getDistant(n,t),s>0&&(a.push(n),s>r&&(r=s,o=n));return{maxPoint:o,newPoints:a}},buildConvexHull:function(t,e){var i=[],n=this.findMostDistantPointFromBaseLine(t,e);return n.maxPoint?(i=i.concat(this.buildConvexHull([t[0],n.maxPoint],n.newPoints)),i=i.concat(this.buildConvexHull([n.maxPoint,t[1]],n.newPoints))):[t[0]]},getConvexHull:function(t){var e,i=!1,n=!1,s=null,r=null;for(e=t.length-1;e>=0;e--){var o=t[e];(i===!1||o.lat>i)&&(s=o,i=o.lat),(n===!1||o.lat<n)&&(r=o,n=o.lat)}var a=[].concat(this.buildConvexHull([r,s],t),this.buildConvexHull([s,r],t));return a}}}(),L.MarkerCluster.include({getConvexHull:function(){var t,e,i=this.getAllChildMarkers(),n=[];for(e=i.length-1;e>=0;e--)t=i[e].getLatLng(),n.push(t);return L.QuickHull.getConvexHull(n)}}),L.MarkerCluster.include({_2PI:2*Math.PI,_circleFootSeparation:25,_circleStartAngle:Math.PI/6,_spiralFootSeparation:28,_spiralLengthStart:11,_spiralLengthFactor:5,_circleSpiralSwitchover:9,spiderfy:function(){if(this._group._spiderfied!==this&&!this._group._inZoomAnimation){var t,e=this.getAllChildMarkers(),i=this._group,n=i._map,s=n.latLngToLayerPoint(this._latlng);this._group._unspiderfy(),this._group._spiderfied=this,e.length>=this._circleSpiralSwitchover?t=this._generatePointsSpiral(e.length,s):(s.y+=10,t=this._generatePointsCircle(e.length,s)),this._animationSpiderfy(e,t)}},unspiderfy:function(t){this._group._inZoomAnimation||(this._animationUnspiderfy(t),this._group._spiderfied=null)},_generatePointsCircle:function(t,e){var i,n,s=this._group.options.spiderfyDistanceMultiplier*this._circleFootSeparation*(2+t),r=s/this._2PI,o=this._2PI/t,a=[];for(a.length=t,i=t-1;i>=0;i--)n=this._circleStartAngle+i*o,a[i]=new L.Point(e.x+r*Math.cos(n),e.y+r*Math.sin(n))._round();return a},_generatePointsSpiral:function(t,e){var i,n=this._group.options.spiderfyDistanceMultiplier*this._spiralLengthStart,s=this._group.options.spiderfyDistanceMultiplier*this._spiralFootSeparation,r=this._group.options.spiderfyDistanceMultiplier*this._spiralLengthFactor,o=0,a=[];for(a.length=t,i=t-1;i>=0;i--)o+=s/n+5e-4*i,a[i]=new L.Point(e.x+n*Math.cos(o),e.y+n*Math.sin(o))._round(),n+=this._2PI*r/o;return a},_noanimationUnspiderfy:function(){var t,e,i=this._group,n=i._map,s=i._featureGroup,r=this.getAllChildMarkers();for(this.setOpacity(1),e=r.length-1;e>=0;e--)t=r[e],s.removeLayer(t),t._preSpiderfyLatlng&&(t.setLatLng(t._preSpiderfyLatlng),delete t._preSpiderfyLatlng),t.setZIndexOffset&&t.setZIndexOffset(0),t._spiderLeg&&(n.removeLayer(t._spiderLeg),delete t._spiderLeg);i._spiderfied=null}}),L.MarkerCluster.include(L.DomUtil.TRANSITION?{SVG_ANIMATION:function(){return e.createElementNS("http://www.w3.org/2000/svg","animate").toString().indexOf("SVGAnimate")>-1}(),_animationSpiderfy:function(t,i){var n,s,r,o,a=this,h=this._group,_=h._map,u=h._featureGroup,l=_.latLngToLayerPoint(this._latlng);for(n=t.length-1;n>=0;n--)s=t[n],s.setOpacity?(s.setZIndexOffset(1e6),s.setOpacity(0),u.addLayer(s),s._setPos(l)):u.addLayer(s);h._forceLayout(),h._animationStart();var d=L.Path.SVG?0:.3,p=L.Path.SVG_NS;for(n=t.length-1;n>=0;n--)if(o=_.layerPointToLatLng(i[n]),s=t[n],s._preSpiderfyLatlng=s._latlng,s.setLatLng(o),s.setOpacity&&s.setOpacity(1),r=new L.Polyline([a._latlng,o],{weight:1.5,color:"#222",opacity:d}),_.addLayer(r),s._spiderLeg=r,L.Path.SVG&&this.SVG_ANIMATION){var c=r._path.getTotalLength();r._path.setAttribute("stroke-dasharray",c+","+c);var f=e.createElementNS(p,"animate");f.setAttribute("attributeName","stroke-dashoffset"),f.setAttribute("begin","indefinite"),f.setAttribute("from",c),f.setAttribute("to",0),f.setAttribute("dur",.25),r._path.appendChild(f),f.beginElement(),f=e.createElementNS(p,"animate"),f.setAttribute("attributeName","stroke-opacity"),f.setAttribute("attributeName","stroke-opacity"),f.setAttribute("begin","indefinite"),f.setAttribute("from",0),f.setAttribute("to",.5),f.setAttribute("dur",.25),r._path.appendChild(f),f.beginElement()}if(a.setOpacity(.3),L.Path.SVG)for(this._group._forceLayout(),n=t.length-1;n>=0;n--)s=t[n]._spiderLeg,s.options.opacity=.5,s._path.setAttribute("stroke-opacity",.5);setTimeout(function(){h._animationEnd(),h.fire("spiderfied")},200)},_animationUnspiderfy:function(t){var e,i,n,s=this._group,r=s._map,o=s._featureGroup,a=t?r._latLngToNewLayerPoint(this._latlng,t.zoom,t.center):r.latLngToLayerPoint(this._latlng),h=this.getAllChildMarkers(),_=L.Path.SVG&&this.SVG_ANIMATION;for(s._animationStart(),this.setOpacity(1),i=h.length-1;i>=0;i--)e=h[i],e._preSpiderfyLatlng&&(e.setLatLng(e._preSpiderfyLatlng),delete e._preSpiderfyLatlng,e.setOpacity?(e._setPos(a),e.setOpacity(0)):o.removeLayer(e),_&&(n=e._spiderLeg._path.childNodes[0],n.setAttribute("to",n.getAttribute("from")),n.setAttribute("from",0),n.beginElement(),n=e._spiderLeg._path.childNodes[1],n.setAttribute("from",.5),n.setAttribute("to",0),n.setAttribute("stroke-opacity",0),n.beginElement(),e._spiderLeg._path.setAttribute("stroke-opacity",0)));setTimeout(function(){var t=0;for(i=h.length-1;i>=0;i--)e=h[i],e._spiderLeg&&t++;for(i=h.length-1;i>=0;i--)e=h[i],e._spiderLeg&&(e.setOpacity&&(e.setOpacity(1),e.setZIndexOffset(0)),t>1&&o.removeLayer(e),r.removeLayer(e._spiderLeg),delete e._spiderLeg);s._animationEnd()},200)}}:{_animationSpiderfy:function(t,e){var i,n,s,r,o=this._group,a=o._map,h=o._featureGroup;for(i=t.length-1;i>=0;i--)r=a.layerPointToLatLng(e[i]),n=t[i],n._preSpiderfyLatlng=n._latlng,n.setLatLng(r),n.setZIndexOffset&&n.setZIndexOffset(1e6),h.addLayer(n),s=new L.Polyline([this._latlng,r],{weight:1.5,color:"#222"}),a.addLayer(s),n._spiderLeg=s;this.setOpacity(.3),o.fire("spiderfied")},_animationUnspiderfy:function(){this._noanimationUnspiderfy()}}),L.MarkerClusterGroup.include({_spiderfied:null,_spiderfierOnAdd:function(){this._map.on("click",this._unspiderfyWrapper,this),this._map.options.zoomAnimation&&this._map.on("zoomstart",this._unspiderfyZoomStart,this),this._map.on("zoomend",this._noanimationUnspiderfy,this),L.Path.SVG&&!L.Browser.touch&&this._map._initPathRoot()},_spiderfierOnRemove:function(){this._map.off("click",this._unspiderfyWrapper,this),this._map.off("zoomstart",this._unspiderfyZoomStart,this),this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._unspiderfy()},_unspiderfyZoomStart:function(){this._map&&this._map.on("zoomanim",this._unspiderfyZoomAnim,this)},_unspiderfyZoomAnim:function(t){L.DomUtil.hasClass(this._map._mapPane,"leaflet-touching")||(this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._unspiderfy(t))},_unspiderfyWrapper:function(){this._unspiderfy()},_unspiderfy:function(t){this._spiderfied&&this._spiderfied.unspiderfy(t)},_noanimationUnspiderfy:function(){this._spiderfied&&this._spiderfied._noanimationUnspiderfy()},_unspiderfyLayer:function(t){t._spiderLeg&&(this._featureGroup.removeLayer(t),t.setOpacity(1),t.setZIndexOffset(0),this._map.removeLayer(t._spiderLeg),delete t._spiderLeg)}})}(window,document); 6 !function(e,t,i){L.MarkerClusterGroup=L.FeatureGroup.extend({options:{maxClusterRadius:80,iconCreateFunction:null,clusterPane:L.Marker.prototype.options.pane,spiderfyOnMaxZoom:!0,showCoverageOnHover:!0,zoomToBoundsOnClick:!0,singleMarkerMode:!1,disableClusteringAtZoom:null,removeOutsideVisibleBounds:!0,animate:!0,animateAddingMarkers:!1,spiderfyDistanceMultiplier:1,spiderLegPolylineOptions:{weight:1.5,color:"#222",opacity:.5},chunkedLoading:!1,chunkInterval:200,chunkDelay:50,chunkProgress:null,polygonOptions:{}},initialize:function(e){L.Util.setOptions(this,e),this.options.iconCreateFunction||(this.options.iconCreateFunction=this._defaultIconCreateFunction),this._featureGroup=L.featureGroup(),this._featureGroup.addEventParent(this),this._nonPointGroup=L.featureGroup(),this._nonPointGroup.addEventParent(this),this._inZoomAnimation=0,this._needsClustering=[],this._needsRemoving=[],this._currentShownBounds=null,this._queue=[],this._childMarkerEventHandlers={dragstart:this._childMarkerDragStart,move:this._childMarkerMoved,dragend:this._childMarkerDragEnd};var t=L.DomUtil.TRANSITION&&this.options.animate;L.extend(this,t?this._withAnimation:this._noAnimation),this._markerCluster=t?L.MarkerCluster:L.MarkerClusterNonAnimated},addLayer:function(e){if(e instanceof L.LayerGroup)return this.addLayers([e]);if(!e.getLatLng)return this._nonPointGroup.addLayer(e),this.fire("layeradd",{layer:e}),this;if(!this._map)return this._needsClustering.push(e),this.fire("layeradd",{layer:e}),this;if(this.hasLayer(e))return this;this._unspiderfy&&this._unspiderfy(),this._addLayer(e,this._maxZoom),this.fire("layeradd",{layer:e}),this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons();var t=e,i=this._zoom;if(e.__parent)for(;t.__parent._zoom>=i;)t=t.__parent;return this._currentShownBounds.contains(t.getLatLng())&&(this.options.animateAddingMarkers?this._animationAddLayer(e,t):this._animationAddLayerNonAnimated(e,t)),this},removeLayer:function(e){return e instanceof L.LayerGroup?this.removeLayers([e]):e.getLatLng?this._map?e.__parent?(this._unspiderfy&&(this._unspiderfy(),this._unspiderfyLayer(e)),this._removeLayer(e,!0),this.fire("layerremove",{layer:e}),this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),e.off(this._childMarkerEventHandlers,this),this._featureGroup.hasLayer(e)&&(this._featureGroup.removeLayer(e),e.clusterShow&&e.clusterShow()),this):this:(!this._arraySplice(this._needsClustering,e)&&this.hasLayer(e)&&this._needsRemoving.push({layer:e,latlng:e._latlng}),this.fire("layerremove",{layer:e}),this):(this._nonPointGroup.removeLayer(e),this.fire("layerremove",{layer:e}),this)},addLayers:function(e,t){if(!L.Util.isArray(e))return this.addLayer(e);var i,n=this._featureGroup,r=this._nonPointGroup,s=this.options.chunkedLoading,o=this.options.chunkInterval,a=this.options.chunkProgress,h=e.length,l=0,u=!0;if(this._map){var _=(new Date).getTime(),d=L.bind(function(){for(var c=(new Date).getTime();h>l;l++){if(s&&0===l%200){var p=(new Date).getTime()-c;if(p>o)break}if(i=e[l],i instanceof L.LayerGroup)u&&(e=e.slice(),u=!1),this._extractNonGroupLayers(i,e),h=e.length;else if(i.getLatLng){if(!this.hasLayer(i)&&(this._addLayer(i,this._maxZoom),t||this.fire("layeradd",{layer:i}),i.__parent&&2===i.__parent.getChildCount())){var f=i.__parent.getAllChildMarkers(),m=f[0]===i?f[1]:f[0];n.removeLayer(m)}}else r.addLayer(i),t||this.fire("layeradd",{layer:i})}a&&a(l,h,(new Date).getTime()-_),l===h?(this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds)):setTimeout(d,this.options.chunkDelay)},this);d()}else for(var c=this._needsClustering;h>l;l++)i=e[l],i instanceof L.LayerGroup?(u&&(e=e.slice(),u=!1),this._extractNonGroupLayers(i,e),h=e.length):i.getLatLng?this.hasLayer(i)||c.push(i):r.addLayer(i);return this},removeLayers:function(e){var t,i,n=e.length,r=this._featureGroup,s=this._nonPointGroup,o=!0;if(!this._map){for(t=0;n>t;t++)i=e[t],i instanceof L.LayerGroup?(o&&(e=e.slice(),o=!1),this._extractNonGroupLayers(i,e),n=e.length):(this._arraySplice(this._needsClustering,i),s.removeLayer(i),this.hasLayer(i)&&this._needsRemoving.push({layer:i,latlng:i._latlng}),this.fire("layerremove",{layer:i}));return this}if(this._unspiderfy){this._unspiderfy();var a=e.slice(),h=n;for(t=0;h>t;t++)i=a[t],i instanceof L.LayerGroup?(this._extractNonGroupLayers(i,a),h=a.length):this._unspiderfyLayer(i)}for(t=0;n>t;t++)i=e[t],i instanceof L.LayerGroup?(o&&(e=e.slice(),o=!1),this._extractNonGroupLayers(i,e),n=e.length):i.__parent?(this._removeLayer(i,!0,!0),this.fire("layerremove",{layer:i}),r.hasLayer(i)&&(r.removeLayer(i),i.clusterShow&&i.clusterShow())):(s.removeLayer(i),this.fire("layerremove",{layer:i}));return this._topClusterLevel._recalculateBounds(),this._refreshClustersIcons(),this._topClusterLevel._recursivelyAddChildrenToMap(null,this._zoom,this._currentShownBounds),this},clearLayers:function(){return this._map||(this._needsClustering=[],delete this._gridClusters,delete this._gridUnclustered),this._noanimationUnspiderfy&&this._noanimationUnspiderfy(),this._featureGroup.clearLayers(),this._nonPointGroup.clearLayers(),this.eachLayer(function(e){e.off(this._childMarkerEventHandlers,this),delete e.__parent},this),this._map&&this._generateInitialClusters(),this},getBounds:function(){var e=new L.LatLngBounds;this._topClusterLevel&&e.extend(this._topClusterLevel._bounds);for(var t=this._needsClustering.length-1;t>=0;t--)e.extend(this._needsClustering[t].getLatLng());return e.extend(this._nonPointGroup.getBounds()),e},eachLayer:function(e,t){var i,n,r,s=this._needsClustering.slice(),o=this._needsRemoving;for(this._topClusterLevel&&this._topClusterLevel.getAllChildMarkers(s),n=s.length-1;n>=0;n--){for(i=!0,r=o.length-1;r>=0;r--)if(o[r].layer===s[n]){i=!1;break}i&&e.call(t,s[n])}this._nonPointGroup.eachLayer(e,t)},getLayers:function(){var e=[];return this.eachLayer(function(t){e.push(t)}),e},getLayer:function(e){var t=null;return e=parseInt(e,10),this.eachLayer(function(i){L.stamp(i)===e&&(t=i)}),t},hasLayer:function(e){if(!e)return!1;var t,i=this._needsClustering;for(t=i.length-1;t>=0;t--)if(i[t]===e)return!0;for(i=this._needsRemoving,t=i.length-1;t>=0;t--)if(i[t].layer===e)return!1;return!(!e.__parent||e.__parent._group!==this)||this._nonPointGroup.hasLayer(e)},zoomToShowLayer:function(e,t){"function"!=typeof t&&(t=function(){});var i=function(){!e._icon&&!e.__parent._icon||this._inZoomAnimation||(this._map.off("moveend",i,this),this.off("animationend",i,this),e._icon?t():e.__parent._icon&&(this.once("spiderfied",t,this),e.__parent.spiderfy()))};e._icon&&this._map.getBounds().contains(e.getLatLng())?t():e.__parent._zoom<Math.round(this._map._zoom)?(this._map.on("moveend",i,this),this._map.panTo(e.getLatLng())):(this._map.on("moveend",i,this),this.on("animationend",i,this),e.__parent.zoomToBounds())},onAdd:function(e){this._map=e;var t,i,n;if(!isFinite(this._map.getMaxZoom()))throw"Map has no maxZoom specified";for(this._featureGroup.addTo(e),this._nonPointGroup.addTo(e),this._gridClusters||this._generateInitialClusters(),this._maxLat=e.options.crs.projection.MAX_LATITUDE,t=0,i=this._needsRemoving.length;i>t;t++)n=this._needsRemoving[t],n.newlatlng=n.layer._latlng,n.layer._latlng=n.latlng;for(t=0,i=this._needsRemoving.length;i>t;t++)n=this._needsRemoving[t],this._removeLayer(n.layer,!0),n.layer._latlng=n.newlatlng;this._needsRemoving=[],this._zoom=Math.round(this._map._zoom),this._currentShownBounds=this._getExpandedVisibleBounds(),this._map.on("zoomend",this._zoomEnd,this),this._map.on("moveend",this._moveEnd,this),this._spiderfierOnAdd&&this._spiderfierOnAdd(),this._bindEvents(),i=this._needsClustering,this._needsClustering=[],this.addLayers(i,!0)},onRemove:function(e){e.off("zoomend",this._zoomEnd,this),e.off("moveend",this._moveEnd,this),this._unbindEvents(),this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim",""),this._spiderfierOnRemove&&this._spiderfierOnRemove(),delete this._maxLat,this._hideCoverage(),this._featureGroup.remove(),this._nonPointGroup.remove(),this._featureGroup.clearLayers(),this._map=null},getVisibleParent:function(e){for(var t=e;t&&!t._icon;)t=t.__parent;return t||null},_arraySplice:function(e,t){for(var i=e.length-1;i>=0;i--)if(e[i]===t)return e.splice(i,1),!0},_removeFromGridUnclustered:function(e,t){for(var i=this._map,n=this._gridUnclustered,r=Math.floor(this._map.getMinZoom());t>=r&&n[t].removeObject(e,i.project(e.getLatLng(),t));t--);},_childMarkerDragStart:function(e){e.target.__dragStart=e.target._latlng},_childMarkerMoved:function(e){if(!this._ignoreMove&&!e.target.__dragStart){var t=e.target._popup&&e.target._popup.isOpen();this._moveChild(e.target,e.oldLatLng,e.latlng),t&&e.target.openPopup()}},_moveChild:function(e,t,i){e._latlng=t,this.removeLayer(e),e._latlng=i,this.addLayer(e)},_childMarkerDragEnd:function(e){e.target.__dragStart&&this._moveChild(e.target,e.target.__dragStart,e.target._latlng),delete e.target.__dragStart},_removeLayer:function(e,t,i){var n=this._gridClusters,r=this._gridUnclustered,s=this._featureGroup,o=this._map,a=Math.floor(this._map.getMinZoom());t&&this._removeFromGridUnclustered(e,this._maxZoom);var h,l=e.__parent,u=l._markers;for(this._arraySplice(u,e);l&&(l._childCount--,l._boundsNeedUpdate=!0,!(l._zoom<a));)t&&l._childCount<=1?(h=l._markers[0]===e?l._markers[1]:l._markers[0],n[l._zoom].removeObject(l,o.project(l._cLatLng,l._zoom)),r[l._zoom].addObject(h,o.project(h.getLatLng(),l._zoom)),this._arraySplice(l.__parent._childClusters,l),l.__parent._markers.push(h),h.__parent=l.__parent,l._icon&&(s.removeLayer(l),i||s.addLayer(h))):l._iconNeedsUpdate=!0,l=l.__parent;delete e.__parent},_isOrIsParent:function(e,t){for(;t;){if(e===t)return!0;t=t.parentNode}return!1},fire:function(e,t,i){if(t&&t.layer instanceof L.MarkerCluster){if(t.originalEvent&&this._isOrIsParent(t.layer._icon,t.originalEvent.relatedTarget))return;e="cluster"+e}L.FeatureGroup.prototype.fire.call(this,e,t,i)},listens:function(e,t){return L.FeatureGroup.prototype.listens.call(this,e,t)||L.FeatureGroup.prototype.listens.call(this,"cluster"+e,t)},_defaultIconCreateFunction:function(e){var t=e.getChildCount(),i=" marker-cluster-";return i+=10>t?"small":100>t?"medium":"large",new L.DivIcon({html:"<div><span>"+t+"</span></div>",className:"marker-cluster"+i,iconSize:new L.Point(40,40)})},_bindEvents:function(){var e=this._map,t=this.options.spiderfyOnMaxZoom,i=this.options.showCoverageOnHover,n=this.options.zoomToBoundsOnClick;(t||n)&&this.on("clusterclick",this._zoomOrSpiderfy,this),i&&(this.on("clustermouseover",this._showCoverage,this),this.on("clustermouseout",this._hideCoverage,this),e.on("zoomend",this._hideCoverage,this))},_zoomOrSpiderfy:function(e){for(var t=e.layer,i=t;1===i._childClusters.length;)i=i._childClusters[0];i._zoom===this._maxZoom&&i._childCount===t._childCount&&this.options.spiderfyOnMaxZoom?t.spiderfy():this.options.zoomToBoundsOnClick&&t.zoomToBounds(),e.originalEvent&&13===e.originalEvent.keyCode&&this._map._container.focus()},_showCoverage:function(e){var t=this._map;this._inZoomAnimation||(this._shownPolygon&&t.removeLayer(this._shownPolygon),e.layer.getChildCount()>2&&e.layer!==this._spiderfied&&(this._shownPolygon=new L.Polygon(e.layer.getConvexHull(),this.options.polygonOptions),t.addLayer(this._shownPolygon)))},_hideCoverage:function(){this._shownPolygon&&(this._map.removeLayer(this._shownPolygon),this._shownPolygon=null)},_unbindEvents:function(){var e=this.options.spiderfyOnMaxZoom,t=this.options.showCoverageOnHover,i=this.options.zoomToBoundsOnClick,n=this._map;(e||i)&&this.off("clusterclick",this._zoomOrSpiderfy,this),t&&(this.off("clustermouseover",this._showCoverage,this),this.off("clustermouseout",this._hideCoverage,this),n.off("zoomend",this._hideCoverage,this))},_zoomEnd:function(){this._map&&(this._mergeSplitClusters(),this._zoom=Math.round(this._map._zoom),this._currentShownBounds=this._getExpandedVisibleBounds())},_moveEnd:function(){if(!this._inZoomAnimation){var e=this._getExpandedVisibleBounds();this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,Math.floor(this._map.getMinZoom()),this._zoom,e),this._topClusterLevel._recursivelyAddChildrenToMap(null,Math.round(this._map._zoom),e),this._currentShownBounds=e}},_generateInitialClusters:function(){var e=Math.ceil(this._map.getMaxZoom()),t=Math.floor(this._map.getMinZoom()),i=this.options.maxClusterRadius,n=i;"function"!=typeof i&&(n=function(){return i}),null!==this.options.disableClusteringAtZoom&&(e=this.options.disableClusteringAtZoom-1),this._maxZoom=e,this._gridClusters={},this._gridUnclustered={};for(var r=e;r>=t;r--)this._gridClusters[r]=new L.DistanceGrid(n(r)),this._gridUnclustered[r]=new L.DistanceGrid(n(r));this._topClusterLevel=new this._markerCluster(this,t-1)},_addLayer:function(e,t){var i,n,r=this._gridClusters,s=this._gridUnclustered,o=Math.floor(this._map.getMinZoom());for(this.options.singleMarkerMode&&this._overrideMarkerIcon(e),e.on(this._childMarkerEventHandlers,this);t>=o;t--){i=this._map.project(e.getLatLng(),t);var a=r[t].getNearObject(i);if(a)return a._addChild(e),e.__parent=a,void 0;if(a=s[t].getNearObject(i)){var h=a.__parent;h&&this._removeLayer(a,!1);var l=new this._markerCluster(this,t,a,e);r[t].addObject(l,this._map.project(l._cLatLng,t)),a.__parent=l,e.__parent=l;var u=l;for(n=t-1;n>h._zoom;n--)u=new this._markerCluster(this,n,u),r[n].addObject(u,this._map.project(a.getLatLng(),n));return h._addChild(u),this._removeFromGridUnclustered(a,t),void 0}s[t].addObject(e,i)}this._topClusterLevel._addChild(e),e.__parent=this._topClusterLevel},_refreshClustersIcons:function(){this._featureGroup.eachLayer(function(e){e instanceof L.MarkerCluster&&e._iconNeedsUpdate&&e._updateIcon()})},_enqueue:function(e){this._queue.push(e),this._queueTimeout||(this._queueTimeout=setTimeout(L.bind(this._processQueue,this),300))},_processQueue:function(){for(var e=0;e<this._queue.length;e++)this._queue[e].call(this);this._queue.length=0,clearTimeout(this._queueTimeout),this._queueTimeout=null},_mergeSplitClusters:function(){var e=Math.round(this._map._zoom);this._processQueue(),this._zoom<e&&this._currentShownBounds.intersects(this._getExpandedVisibleBounds())?(this._animationStart(),this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,Math.floor(this._map.getMinZoom()),this._zoom,this._getExpandedVisibleBounds()),this._animationZoomIn(this._zoom,e)):this._zoom>e?(this._animationStart(),this._animationZoomOut(this._zoom,e)):this._moveEnd()},_getExpandedVisibleBounds:function(){return this.options.removeOutsideVisibleBounds?L.Browser.mobile?this._checkBoundsMaxLat(this._map.getBounds()):this._checkBoundsMaxLat(this._map.getBounds().pad(1)):this._mapBoundsInfinite},_checkBoundsMaxLat:function(e){var t=this._maxLat;return t!==i&&(e.getNorth()>=t&&(e._northEast.lat=1/0),e.getSouth()<=-t&&(e._southWest.lat=-1/0)),e},_animationAddLayerNonAnimated:function(e,t){if(t===e)this._featureGroup.addLayer(e);else if(2===t._childCount){t._addToMap();var i=t.getAllChildMarkers();this._featureGroup.removeLayer(i[0]),this._featureGroup.removeLayer(i[1])}else t._updateIcon()},_extractNonGroupLayers:function(e,t){var i,n=e.getLayers(),r=0;for(t=t||[];r<n.length;r++)i=n[r],i instanceof L.LayerGroup?this._extractNonGroupLayers(i,t):t.push(i);return t},_overrideMarkerIcon:function(e){var t=e.options.icon=this.options.iconCreateFunction({getChildCount:function(){return 1},getAllChildMarkers:function(){return[e]}});return t}}),L.MarkerClusterGroup.include({_mapBoundsInfinite:new L.LatLngBounds(new L.LatLng(-1/0,-1/0),new L.LatLng(1/0,1/0))}),L.MarkerClusterGroup.include({_noAnimation:{_animationStart:function(){},_animationZoomIn:function(e,t){this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,Math.floor(this._map.getMinZoom()),e),this._topClusterLevel._recursivelyAddChildrenToMap(null,t,this._getExpandedVisibleBounds()),this.fire("animationend")},_animationZoomOut:function(e,t){this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,Math.floor(this._map.getMinZoom()),e),this._topClusterLevel._recursivelyAddChildrenToMap(null,t,this._getExpandedVisibleBounds()),this.fire("animationend")},_animationAddLayer:function(e,t){this._animationAddLayerNonAnimated(e,t)}},_withAnimation:{_animationStart:function(){this._map._mapPane.className+=" leaflet-cluster-anim",this._inZoomAnimation++},_animationZoomIn:function(e,t){var i,n=this._getExpandedVisibleBounds(),r=this._featureGroup,s=Math.floor(this._map.getMinZoom());this._ignoreMove=!0,this._topClusterLevel._recursively(n,e,s,function(s){var o,a=s._latlng,h=s._markers;for(n.contains(a)||(a=null),s._isSingleParent()&&e+1===t?(r.removeLayer(s),s._recursivelyAddChildrenToMap(null,t,n)):(s.clusterHide(),s._recursivelyAddChildrenToMap(a,t,n)),i=h.length-1;i>=0;i--)o=h[i],n.contains(o._latlng)||r.removeLayer(o)}),this._forceLayout(),this._topClusterLevel._recursivelyBecomeVisible(n,t),r.eachLayer(function(e){e instanceof L.MarkerCluster||!e._icon||e.clusterShow()}),this._topClusterLevel._recursively(n,e,t,function(e){e._recursivelyRestoreChildPositions(t)}),this._ignoreMove=!1,this._enqueue(function(){this._topClusterLevel._recursively(n,e,s,function(e){r.removeLayer(e),e.clusterShow()}),this._animationEnd()})},_animationZoomOut:function(e,t){this._animationZoomOutSingle(this._topClusterLevel,e-1,t),this._topClusterLevel._recursivelyAddChildrenToMap(null,t,this._getExpandedVisibleBounds()),this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds,Math.floor(this._map.getMinZoom()),e,this._getExpandedVisibleBounds())},_animationAddLayer:function(e,t){var i=this,n=this._featureGroup;n.addLayer(e),t!==e&&(t._childCount>2?(t._updateIcon(),this._forceLayout(),this._animationStart(),e._setPos(this._map.latLngToLayerPoint(t.getLatLng())),e.clusterHide(),this._enqueue(function(){n.removeLayer(e),e.clusterShow(),i._animationEnd()})):(this._forceLayout(),i._animationStart(),i._animationZoomOutSingle(t,this._map.getMaxZoom(),this._zoom)))}},_animationZoomOutSingle:function(e,t,i){var n=this._getExpandedVisibleBounds(),r=Math.floor(this._map.getMinZoom());e._recursivelyAnimateChildrenInAndAddSelfToMap(n,r,t+1,i);var s=this;this._forceLayout(),e._recursivelyBecomeVisible(n,i),this._enqueue(function(){if(1===e._childCount){var o=e._markers[0];this._ignoreMove=!0,o.setLatLng(o.getLatLng()),this._ignoreMove=!1,o.clusterShow&&o.clusterShow()}else e._recursively(n,i,r,function(e){e._recursivelyRemoveChildrenFromMap(n,r,t+1)});s._animationEnd()})},_animationEnd:function(){this._map&&(this._map._mapPane.className=this._map._mapPane.className.replace(" leaflet-cluster-anim","")),this._inZoomAnimation--,this.fire("animationend")},_forceLayout:function(){L.Util.falseFn(t.body.offsetWidth)}}),L.markerClusterGroup=function(e){return new L.MarkerClusterGroup(e)},L.MarkerCluster=L.Marker.extend({initialize:function(e,t,i,n){L.Marker.prototype.initialize.call(this,i?i._cLatLng||i.getLatLng():new L.LatLng(0,0),{icon:this,pane:e.options.clusterPane}),this._group=e,this._zoom=t,this._markers=[],this._childClusters=[],this._childCount=0,this._iconNeedsUpdate=!0,this._boundsNeedUpdate=!0,this._bounds=new L.LatLngBounds,i&&this._addChild(i),n&&this._addChild(n)},getAllChildMarkers:function(e){e=e||[];for(var t=this._childClusters.length-1;t>=0;t--)this._childClusters[t].getAllChildMarkers(e);for(var i=this._markers.length-1;i>=0;i--)e.push(this._markers[i]);return e},getChildCount:function(){return this._childCount},zoomToBounds:function(e){for(var t,i=this._childClusters.slice(),n=this._group._map,r=n.getBoundsZoom(this._bounds),s=this._zoom+1,o=n.getZoom();i.length>0&&r>s;){s++;var a=[];for(t=0;t<i.length;t++)a=a.concat(i[t]._childClusters);i=a}r>s?this._group._map.setView(this._latlng,s):o>=r?this._group._map.setView(this._latlng,o+1):this._group._map.fitBounds(this._bounds,e)},getBounds:function(){var e=new L.LatLngBounds;return e.extend(this._bounds),e},_updateIcon:function(){this._iconNeedsUpdate=!0,this._icon&&this.setIcon(this)},createIcon:function(){return this._iconNeedsUpdate&&(this._iconObj=this._group.options.iconCreateFunction(this),this._iconNeedsUpdate=!1),this._iconObj.createIcon()},createShadow:function(){return this._iconObj.createShadow()},_addChild:function(e,t){this._iconNeedsUpdate=!0,this._boundsNeedUpdate=!0,this._setClusterCenter(e),e instanceof L.MarkerCluster?(t||(this._childClusters.push(e),e.__parent=this),this._childCount+=e._childCount):(t||this._markers.push(e),this._childCount++),this.__parent&&this.__parent._addChild(e,!0)},_setClusterCenter:function(e){this._cLatLng||(this._cLatLng=e._cLatLng||e._latlng)},_resetBounds:function(){var e=this._bounds;e._southWest&&(e._southWest.lat=1/0,e._southWest.lng=1/0),e._northEast&&(e._northEast.lat=-1/0,e._northEast.lng=-1/0)},_recalculateBounds:function(){var e,t,i,n,r=this._markers,s=this._childClusters,o=0,a=0,h=this._childCount;if(0!==h){for(this._resetBounds(),e=0;e<r.length;e++)i=r[e]._latlng,this._bounds.extend(i),o+=i.lat,a+=i.lng;for(e=0;e<s.length;e++)t=s[e],t._boundsNeedUpdate&&t._recalculateBounds(),this._bounds.extend(t._bounds),i=t._wLatLng,n=t._childCount,o+=i.lat*n,a+=i.lng*n;this._latlng=this._wLatLng=new L.LatLng(o/h,a/h),this._boundsNeedUpdate=!1}},_addToMap:function(e){e&&(this._backupLatlng=this._latlng,this.setLatLng(e)),this._group._featureGroup.addLayer(this)},_recursivelyAnimateChildrenIn:function(e,t,i){this._recursively(e,this._group._map.getMinZoom(),i-1,function(e){var i,n,r=e._markers;for(i=r.length-1;i>=0;i--)n=r[i],n._icon&&(n._setPos(t),n.clusterHide())},function(e){var i,n,r=e._childClusters;for(i=r.length-1;i>=0;i--)n=r[i],n._icon&&(n._setPos(t),n.clusterHide())})},_recursivelyAnimateChildrenInAndAddSelfToMap:function(e,t,i,n){this._recursively(e,n,t,function(r){r._recursivelyAnimateChildrenIn(e,r._group._map.latLngToLayerPoint(r.getLatLng()).round(),i),r._isSingleParent()&&i-1===n?(r.clusterShow(),r._recursivelyRemoveChildrenFromMap(e,t,i)):r.clusterHide(),r._addToMap()})},_recursivelyBecomeVisible:function(e,t){this._recursively(e,this._group._map.getMinZoom(),t,null,function(e){e.clusterShow()})},_recursivelyAddChildrenToMap:function(e,t,i){this._recursively(i,this._group._map.getMinZoom()-1,t,function(n){if(t!==n._zoom)for(var r=n._markers.length-1;r>=0;r--){var s=n._markers[r];i.contains(s._latlng)&&(e&&(s._backupLatlng=s.getLatLng(),s.setLatLng(e),s.clusterHide&&s.clusterHide()),n._group._featureGroup.addLayer(s))}},function(t){t._addToMap(e)})},_recursivelyRestoreChildPositions:function(e){for(var t=this._markers.length-1;t>=0;t--){var i=this._markers[t];i._backupLatlng&&(i.setLatLng(i._backupLatlng),delete i._backupLatlng)}if(e-1===this._zoom)for(var n=this._childClusters.length-1;n>=0;n--)this._childClusters[n]._restorePosition();else for(var r=this._childClusters.length-1;r>=0;r--)this._childClusters[r]._recursivelyRestoreChildPositions(e)},_restorePosition:function(){this._backupLatlng&&(this.setLatLng(this._backupLatlng),delete this._backupLatlng)},_recursivelyRemoveChildrenFromMap:function(e,t,i,n){var r,s;this._recursively(e,t-1,i-1,function(e){for(s=e._markers.length-1;s>=0;s--)r=e._markers[s],n&&n.contains(r._latlng)||(e._group._featureGroup.removeLayer(r),r.clusterShow&&r.clusterShow())},function(e){for(s=e._childClusters.length-1;s>=0;s--)r=e._childClusters[s],n&&n.contains(r._latlng)||(e._group._featureGroup.removeLayer(r),r.clusterShow&&r.clusterShow())})},_recursively:function(e,t,i,n,r){var s,o,a=this._childClusters,h=this._zoom;if(h>=t&&(n&&n(this),r&&h===i&&r(this)),t>h||i>h)for(s=a.length-1;s>=0;s--)o=a[s],e.intersects(o._bounds)&&o._recursively(e,t,i,n,r)},_isSingleParent:function(){return this._childClusters.length>0&&this._childClusters[0]._childCount===this._childCount}}),L.Marker.include({clusterHide:function(){return this.options.opacityWhenUnclustered=this.options.opacity||1,this.setOpacity(0)},clusterShow:function(){var e=this.setOpacity(this.options.opacity||this.options.opacityWhenUnclustered);return delete this.options.opacityWhenUnclustered,e}}),L.DistanceGrid=function(e){this._cellSize=e,this._sqCellSize=e*e,this._grid={},this._objectPoint={}},L.DistanceGrid.prototype={addObject:function(e,t){var i=this._getCoord(t.x),n=this._getCoord(t.y),r=this._grid,s=r[n]=r[n]||{},o=s[i]=s[i]||[],a=L.Util.stamp(e);this._objectPoint[a]=t,o.push(e)},updateObject:function(e,t){this.removeObject(e),this.addObject(e,t)},removeObject:function(e,t){var i,n,r=this._getCoord(t.x),s=this._getCoord(t.y),o=this._grid,a=o[s]=o[s]||{},h=a[r]=a[r]||[];for(delete this._objectPoint[L.Util.stamp(e)],i=0,n=h.length;n>i;i++)if(h[i]===e)return h.splice(i,1),1===n&&delete a[r],!0},eachObject:function(e,t){var i,n,r,s,o,a,h,l=this._grid;for(i in l){o=l[i];for(n in o)for(a=o[n],r=0,s=a.length;s>r;r++)h=e.call(t,a[r]),h&&(r--,s--)}},getNearObject:function(e){var t,i,n,r,s,o,a,h,l=this._getCoord(e.x),u=this._getCoord(e.y),_=this._objectPoint,d=this._sqCellSize,c=null;for(t=u-1;u+1>=t;t++)if(r=this._grid[t])for(i=l-1;l+1>=i;i++)if(s=r[i])for(n=0,o=s.length;o>n;n++)a=s[n],h=this._sqDist(_[L.Util.stamp(a)],e),(d>h||d>=h&&null===c)&&(d=h,c=a);return c},_getCoord:function(e){var t=Math.floor(e/this._cellSize);return isFinite(t)?t:e},_sqDist:function(e,t){var i=t.x-e.x,n=t.y-e.y;return i*i+n*n}},function(){L.QuickHull={getDistant:function(e,t){var i=t[1].lat-t[0].lat,n=t[0].lng-t[1].lng;return n*(e.lat-t[0].lat)+i*(e.lng-t[0].lng)},findMostDistantPointFromBaseLine:function(e,t){var i,n,r,s=0,o=null,a=[];for(i=t.length-1;i>=0;i--)n=t[i],r=this.getDistant(n,e),r>0&&(a.push(n),r>s&&(s=r,o=n));return{maxPoint:o,newPoints:a}},buildConvexHull:function(e,t){var i=[],n=this.findMostDistantPointFromBaseLine(e,t);return n.maxPoint?(i=i.concat(this.buildConvexHull([e[0],n.maxPoint],n.newPoints)),i=i.concat(this.buildConvexHull([n.maxPoint,e[1]],n.newPoints))):[e[0]]},getConvexHull:function(e){var t,i=!1,n=!1,r=!1,s=!1,o=null,a=null,h=null,l=null,u=null,_=null;for(t=e.length-1;t>=0;t--){var d=e[t];(i===!1||d.lat>i)&&(o=d,i=d.lat),(n===!1||d.lat<n)&&(a=d,n=d.lat),(r===!1||d.lng>r)&&(h=d,r=d.lng),(s===!1||d.lng<s)&&(l=d,s=d.lng)}n!==i?(_=a,u=o):(_=l,u=h);var c=[].concat(this.buildConvexHull([_,u],e),this.buildConvexHull([u,_],e));return c}}}(),L.MarkerCluster.include({getConvexHull:function(){var e,t,i=this.getAllChildMarkers(),n=[];for(t=i.length-1;t>=0;t--)e=i[t].getLatLng(),n.push(e);return L.QuickHull.getConvexHull(n)}}),L.MarkerCluster.include({_2PI:2*Math.PI,_circleFootSeparation:25,_circleStartAngle:Math.PI/6,_spiralFootSeparation:28,_spiralLengthStart:11,_spiralLengthFactor:5,_circleSpiralSwitchover:9,spiderfy:function(){if(this._group._spiderfied!==this&&!this._group._inZoomAnimation){var e,t=this.getAllChildMarkers(),i=this._group,n=i._map,r=n.latLngToLayerPoint(this._latlng);this._group._unspiderfy(),this._group._spiderfied=this,t.length>=this._circleSpiralSwitchover?e=this._generatePointsSpiral(t.length,r):(r.y+=10,e=this._generatePointsCircle(t.length,r)),this._animationSpiderfy(t,e)}},unspiderfy:function(e){this._group._inZoomAnimation||(this._animationUnspiderfy(e),this._group._spiderfied=null)},_generatePointsCircle:function(e,t){var i,n,r=this._group.options.spiderfyDistanceMultiplier*this._circleFootSeparation*(2+e),s=r/this._2PI,o=this._2PI/e,a=[];for(a.length=e,i=e-1;i>=0;i--)n=this._circleStartAngle+i*o,a[i]=new L.Point(t.x+s*Math.cos(n),t.y+s*Math.sin(n))._round();return a},_generatePointsSpiral:function(e,t){var i,n=this._group.options.spiderfyDistanceMultiplier,r=n*this._spiralLengthStart,s=n*this._spiralFootSeparation,o=n*this._spiralLengthFactor*this._2PI,a=0,h=[];for(h.length=e,i=e-1;i>=0;i--)a+=s/r+5e-4*i,h[i]=new L.Point(t.x+r*Math.cos(a),t.y+r*Math.sin(a))._round(),r+=o/a;return h},_noanimationUnspiderfy:function(){var e,t,i=this._group,n=i._map,r=i._featureGroup,s=this.getAllChildMarkers();for(i._ignoreMove=!0,this.setOpacity(1),t=s.length-1;t>=0;t--)e=s[t],r.removeLayer(e),e._preSpiderfyLatlng&&(e.setLatLng(e._preSpiderfyLatlng),delete e._preSpiderfyLatlng),e.setZIndexOffset&&e.setZIndexOffset(0),e._spiderLeg&&(n.removeLayer(e._spiderLeg),delete e._spiderLeg);i.fire("unspiderfied",{cluster:this,markers:s}),i._ignoreMove=!1,i._spiderfied=null}}),L.MarkerClusterNonAnimated=L.MarkerCluster.extend({_animationSpiderfy:function(e,t){var i,n,r,s,o=this._group,a=o._map,h=o._featureGroup,l=this._group.options.spiderLegPolylineOptions;for(o._ignoreMove=!0,i=0;i<e.length;i++)s=a.layerPointToLatLng(t[i]),n=e[i],r=new L.Polyline([this._latlng,s],l),a.addLayer(r),n._spiderLeg=r,n._preSpiderfyLatlng=n._latlng,n.setLatLng(s),n.setZIndexOffset&&n.setZIndexOffset(1e6),h.addLayer(n);this.setOpacity(.3),o._ignoreMove=!1,o.fire("spiderfied",{cluster:this,markers:e})},_animationUnspiderfy:function(){this._noanimationUnspiderfy()}}),L.MarkerCluster.include({_animationSpiderfy:function(e,t){var n,r,s,o,a,h,l=this,u=this._group,_=u._map,d=u._featureGroup,c=this._latlng,p=_.latLngToLayerPoint(c),f=L.Path.SVG,m=L.extend({},this._group.options.spiderLegPolylineOptions),g=m.opacity;for(g===i&&(g=L.MarkerClusterGroup.prototype.options.spiderLegPolylineOptions.opacity),f?(m.opacity=0,m.className=(m.className||"")+" leaflet-cluster-spider-leg"):m.opacity=g,u._ignoreMove=!0,n=0;n<e.length;n++)r=e[n],h=_.layerPointToLatLng(t[n]),s=new L.Polyline([c,h],m),_.addLayer(s),r._spiderLeg=s,f&&(o=s._path,a=o.getTotalLength()+.1,o.style.strokeDasharray=a,o.style.strokeDashoffset=a),r.setZIndexOffset&&r.setZIndexOffset(1e6),r.clusterHide&&r.clusterHide(),d.addLayer(r),r._setPos&&r._setPos(p);for(u._forceLayout(),u._animationStart(),n=e.length-1;n>=0;n--)h=_.layerPointToLatLng(t[n]),r=e[n],r._preSpiderfyLatlng=r._latlng,r.setLatLng(h),r.clusterShow&&r.clusterShow(),f&&(s=r._spiderLeg,o=s._path,o.style.strokeDashoffset=0,s.setStyle({opacity:g}));this.setOpacity(.3),u._ignoreMove=!1,setTimeout(function(){u._animationEnd(),u.fire("spiderfied",{cluster:l,markers:e})},200)},_animationUnspiderfy:function(e){var t,i,n,r,s,o,a=this,h=this._group,l=h._map,u=h._featureGroup,_=e?l._latLngToNewLayerPoint(this._latlng,e.zoom,e.center):l.latLngToLayerPoint(this._latlng),d=this.getAllChildMarkers(),c=L.Path.SVG;for(h._ignoreMove=!0,h._animationStart(),this.setOpacity(1),i=d.length-1;i>=0;i--)t=d[i],t._preSpiderfyLatlng&&(t.closePopup(),t.setLatLng(t._preSpiderfyLatlng),delete t._preSpiderfyLatlng,o=!0,t._setPos&&(t._setPos(_),o=!1),t.clusterHide&&(t.clusterHide(),o=!1),o&&u.removeLayer(t),c&&(n=t._spiderLeg,r=n._path,s=r.getTotalLength()+.1,r.style.strokeDashoffset=s,n.setStyle({opacity:0})));h._ignoreMove=!1,setTimeout(function(){var e=0;for(i=d.length-1;i>=0;i--)t=d[i],t._spiderLeg&&e++;for(i=d.length-1;i>=0;i--)t=d[i],t._spiderLeg&&(t.clusterShow&&t.clusterShow(),t.setZIndexOffset&&t.setZIndexOffset(0),e>1&&u.removeLayer(t),l.removeLayer(t._spiderLeg),delete t._spiderLeg);h._animationEnd(),h.fire("unspiderfied",{cluster:a,markers:d})},200)}}),L.MarkerClusterGroup.include({_spiderfied:null,unspiderfy:function(){this._unspiderfy.apply(this,arguments)},_spiderfierOnAdd:function(){this._map.on("click",this._unspiderfyWrapper,this),this._map.options.zoomAnimation&&this._map.on("zoomstart",this._unspiderfyZoomStart,this),this._map.on("zoomend",this._noanimationUnspiderfy,this),L.Browser.touch||this._map.getRenderer(this)},_spiderfierOnRemove:function(){this._map.off("click",this._unspiderfyWrapper,this),this._map.off("zoomstart",this._unspiderfyZoomStart,this),this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._map.off("zoomend",this._noanimationUnspiderfy,this),this._noanimationUnspiderfy()},_unspiderfyZoomStart:function(){this._map&&this._map.on("zoomanim",this._unspiderfyZoomAnim,this)},_unspiderfyZoomAnim:function(e){L.DomUtil.hasClass(this._map._mapPane,"leaflet-touching")||(this._map.off("zoomanim",this._unspiderfyZoomAnim,this),this._unspiderfy(e))},_unspiderfyWrapper:function(){this._unspiderfy() 7 },_unspiderfy:function(e){this._spiderfied&&this._spiderfied.unspiderfy(e)},_noanimationUnspiderfy:function(){this._spiderfied&&this._spiderfied._noanimationUnspiderfy()},_unspiderfyLayer:function(e){e._spiderLeg&&(this._featureGroup.removeLayer(e),e.clusterShow&&e.clusterShow(),e.setZIndexOffset&&e.setZIndexOffset(0),this._map.removeLayer(e._spiderLeg),delete e._spiderLeg)}}),L.MarkerClusterGroup.include({refreshClusters:function(e){return e?e instanceof L.MarkerClusterGroup?e=e._topClusterLevel.getAllChildMarkers():e instanceof L.LayerGroup?e=e._layers:e instanceof L.MarkerCluster?e=e.getAllChildMarkers():e instanceof L.Marker&&(e=[e]):e=this._topClusterLevel.getAllChildMarkers(),this._flagParentsIconsNeedUpdate(e),this._refreshClustersIcons(),this.options.singleMarkerMode&&this._refreshSingleMarkerModeMarkers(e),this},_flagParentsIconsNeedUpdate:function(e){var t,i;for(t in e)for(i=e[t].__parent;i;)i._iconNeedsUpdate=!0,i=i.__parent},_refreshSingleMarkerModeMarkers:function(e){var t,i;for(t in e)i=e[t],this.hasLayer(i)&&i.setIcon(this._overrideMarkerIcon(i))}}),L.Marker.include({refreshIconOptions:function(e,t){var i=this.options.icon;return L.setOptions(i,e),this.setIcon(i),t&&this.__parent&&this.__parent._group.refreshClusters(this),this}})}(window,document);
Note:
See TracChangeset
for help on using the changeset viewer.