{"version":3,"file":"leaflet.markercluster-src.js","sources":["../src/MarkerClusterGroup.js","../src/MarkerCluster.js","../src/MarkerOpacity.js","../src/DistanceGrid.js","../src/MarkerCluster.QuickHull.js","../src/MarkerCluster.Spiderfier.js","../src/MarkerClusterGroup.Refresh.js"],"sourcesContent":["/*\r\n * L.MarkerClusterGroup extends L.FeatureGroup by clustering the markers contained within\r\n */\r\n\r\nexport var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({\r\n\r\n\toptions: {\r\n\t\tmaxClusterRadius: 80, //A cluster will cover at most this many pixels from its center\r\n\t\ticonCreateFunction: null,\r\n\t\tclusterPane: L.Marker.prototype.options.pane,\r\n\r\n\t\tspiderfyOnMaxZoom: true,\r\n\t\tshowCoverageOnHover: true,\r\n\t\tzoomToBoundsOnClick: true,\r\n\t\tsingleMarkerMode: false,\r\n\r\n\t\tdisableClusteringAtZoom: null,\r\n\r\n\t\t// Setting this to false prevents the removal of any clusters outside of the viewpoint, which\r\n\t\t// is the default behaviour for performance reasons.\r\n\t\tremoveOutsideVisibleBounds: true,\r\n\r\n\t\t// Set to false to disable all animations (zoom and spiderfy).\r\n\t\t// If false, option animateAddingMarkers below has no effect.\r\n\t\t// If L.DomUtil.TRANSITION is falsy, this option has no effect.\r\n\t\tanimate: true,\r\n\r\n\t\t//Whether to animate adding markers after adding the MarkerClusterGroup to the map\r\n\t\t// If you are adding individual markers set to true, if adding bulk markers leave false for massive performance gains.\r\n\t\tanimateAddingMarkers: false,\r\n\r\n\t\t//Increase to increase the distance away that spiderfied markers appear from the center\r\n\t\tspiderfyDistanceMultiplier: 1,\r\n\r\n\t\t// Make it possible to specify a polyline options on a spider leg\r\n\t\tspiderLegPolylineOptions: { weight: 1.5, color: '#222', opacity: 0.5 },\r\n\r\n\t\t// 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\r\n\t\tchunkedLoading: false,\r\n\t\tchunkInterval: 200, // process markers for a maximum of ~ n milliseconds (then trigger the chunkProgress callback)\r\n\t\tchunkDelay: 50, // at the end of each interval, give n milliseconds back to system/browser\r\n\t\tchunkProgress: null, // progress callback: function(processed, total, elapsed) (e.g. for a progress indicator)\r\n\r\n\t\t//Options to pass to the L.Polygon constructor\r\n\t\tpolygonOptions: {}\r\n\t},\r\n\r\n\tinitialize: function (options) {\r\n\t\tL.Util.setOptions(this, options);\r\n\t\tif (!this.options.iconCreateFunction) {\r\n\t\t\tthis.options.iconCreateFunction = this._defaultIconCreateFunction;\r\n\t\t}\r\n\r\n\t\tthis._featureGroup = L.featureGroup();\r\n\t\tthis._featureGroup.addEventParent(this);\r\n\r\n\t\tthis._nonPointGroup = L.featureGroup();\r\n\t\tthis._nonPointGroup.addEventParent(this);\r\n\r\n\t\tthis._inZoomAnimation = 0;\r\n\t\tthis._needsClustering = [];\r\n\t\tthis._needsRemoving = []; //Markers removed while we aren't on the map need to be kept track of\r\n\t\t//The bounds of the currently shown area (from _getExpandedVisibleBounds) Updated on zoom/move\r\n\t\tthis._currentShownBounds = null;\r\n\r\n\t\tthis._queue = [];\r\n\r\n\t\tthis._childMarkerEventHandlers = {\r\n\t\t\t'dragstart': this._childMarkerDragStart,\r\n\t\t\t'move': this._childMarkerMoved,\r\n\t\t\t'dragend': this._childMarkerDragEnd,\r\n\t\t};\r\n\r\n\t\t// Hook the appropriate animation methods.\r\n\t\tvar animate = L.DomUtil.TRANSITION && this.options.animate;\r\n\t\tL.extend(this, animate ? this._withAnimation : this._noAnimation);\r\n\t\t// Remember which MarkerCluster class to instantiate (animated or not).\r\n\t\tthis._markerCluster = animate ? L.MarkerCluster : L.MarkerClusterNonAnimated;\r\n\t},\r\n\r\n\taddLayer: function (layer) {\r\n\r\n\t\tif (layer instanceof L.LayerGroup) {\r\n\t\t\treturn this.addLayers([layer]);\r\n\t\t}\r\n\r\n\t\t//Don't cluster non point data\r\n\t\tif (!layer.getLatLng) {\r\n\t\t\tthis._nonPointGroup.addLayer(layer);\r\n\t\t\tthis.fire('layeradd', { layer: layer });\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (!this._map) {\r\n\t\t\tthis._needsClustering.push(layer);\r\n\t\t\tthis.fire('layeradd', { layer: layer });\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (this.hasLayer(layer)) {\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\r\n\t\t//If we have already clustered we'll need to add this one to a cluster\r\n\r\n\t\tif (this._unspiderfy) {\r\n\t\t\tthis._unspiderfy();\r\n\t\t}\r\n\r\n\t\tthis._addLayer(layer, this._maxZoom);\r\n\t\tthis.fire('layeradd', { layer: layer });\r\n\r\n\t\t// Refresh bounds and weighted positions.\r\n\t\tthis._topClusterLevel._recalculateBounds();\r\n\r\n\t\tthis._refreshClustersIcons();\r\n\r\n\t\t//Work out what is visible\r\n\t\tvar visibleLayer = layer,\r\n\t\t currentZoom = this._zoom;\r\n\t\tif (layer.__parent) {\r\n\t\t\twhile (visibleLayer.__parent._zoom >= currentZoom) {\r\n\t\t\t\tvisibleLayer = visibleLayer.__parent;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (this._currentShownBounds.contains(visibleLayer.getLatLng())) {\r\n\t\t\tif (this.options.animateAddingMarkers) {\r\n\t\t\t\tthis._animationAddLayer(layer, visibleLayer);\r\n\t\t\t} else {\r\n\t\t\t\tthis._animationAddLayerNonAnimated(layer, visibleLayer);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn this;\r\n\t},\r\n\r\n\tremoveLayer: function (layer) {\r\n\r\n\t\tif (layer instanceof L.LayerGroup) {\r\n\t\t\treturn this.removeLayers([layer]);\r\n\t\t}\r\n\r\n\t\t//Non point layers\r\n\t\tif (!layer.getLatLng) {\r\n\t\t\tthis._nonPointGroup.removeLayer(layer);\r\n\t\t\tthis.fire('layerremove', { layer: layer });\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (!this._map) {\r\n\t\t\tif (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) {\r\n\t\t\t\tthis._needsRemoving.push({ layer: layer, latlng: layer._latlng });\r\n\t\t\t}\r\n\t\t\tthis.fire('layerremove', { layer: layer });\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (!layer.__parent) {\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (this._unspiderfy) {\r\n\t\t\tthis._unspiderfy();\r\n\t\t\tthis._unspiderfyLayer(layer);\r\n\t\t}\r\n\r\n\t\t//Remove the marker from clusters\r\n\t\tthis._removeLayer(layer, true);\r\n\t\tthis.fire('layerremove', { layer: layer });\r\n\r\n\t\t// Refresh bounds and weighted positions.\r\n\t\tthis._topClusterLevel._recalculateBounds();\r\n\r\n\t\tthis._refreshClustersIcons();\r\n\r\n\t\tlayer.off(this._childMarkerEventHandlers, this);\r\n\r\n\t\tif (this._featureGroup.hasLayer(layer)) {\r\n\t\t\tthis._featureGroup.removeLayer(layer);\r\n\t\t\tif (layer.clusterShow) {\r\n\t\t\t\tlayer.clusterShow();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn this;\r\n\t},\r\n\r\n\t//Takes an array of markers and adds them in bulk\r\n\taddLayers: function (layersArray, skipLayerAddEvent) {\r\n\t\tif (!L.Util.isArray(layersArray)) {\r\n\t\t\treturn this.addLayer(layersArray);\r\n\t\t}\r\n\r\n\t\tvar fg = this._featureGroup,\r\n\t\t npg = this._nonPointGroup,\r\n\t\t chunked = this.options.chunkedLoading,\r\n\t\t chunkInterval = this.options.chunkInterval,\r\n\t\t chunkProgress = this.options.chunkProgress,\r\n\t\t l = layersArray.length,\r\n\t\t offset = 0,\r\n\t\t originalArray = true,\r\n\t\t m;\r\n\r\n\t\tif (this._map) {\r\n\t\t\tvar started = (new Date()).getTime();\r\n\t\t\tvar process = L.bind(function () {\r\n\t\t\t\tvar start = (new Date()).getTime();\r\n\t\t\t\tfor (; offset < l; offset++) {\r\n\t\t\t\t\tif (chunked && offset % 200 === 0) {\r\n\t\t\t\t\t\t// every couple hundred markers, instrument the time elapsed since processing started:\r\n\t\t\t\t\t\tvar elapsed = (new Date()).getTime() - start;\r\n\t\t\t\t\t\tif (elapsed > chunkInterval) {\r\n\t\t\t\t\t\t\tbreak; // been working too hard, time to take a break :-)\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tm = layersArray[offset];\r\n\r\n\t\t\t\t\t// Group of layers, append children to layersArray and skip.\r\n\t\t\t\t\t// Side effects:\r\n\t\t\t\t\t// - Total increases, so chunkProgress ratio jumps backward.\r\n\t\t\t\t\t// - Groups are not included in this group, only their non-group child layers (hasLayer).\r\n\t\t\t\t\t// Changing array length while looping does not affect performance in current browsers:\r\n\t\t\t\t\t// http://jsperf.com/for-loop-changing-length/6\r\n\t\t\t\t\tif (m instanceof L.LayerGroup) {\r\n\t\t\t\t\t\tif (originalArray) {\r\n\t\t\t\t\t\t\tlayersArray = layersArray.slice();\r\n\t\t\t\t\t\t\toriginalArray = false;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tthis._extractNonGroupLayers(m, layersArray);\r\n\t\t\t\t\t\tl = layersArray.length;\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t//Not point data, can't be clustered\r\n\t\t\t\t\tif (!m.getLatLng) {\r\n\t\t\t\t\t\tnpg.addLayer(m);\r\n\t\t\t\t\t\tif (!skipLayerAddEvent) {\r\n\t\t\t\t\t\t\tthis.fire('layeradd', { layer: m });\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (this.hasLayer(m)) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tthis._addLayer(m, this._maxZoom);\r\n\t\t\t\t\tif (!skipLayerAddEvent) {\r\n\t\t\t\t\t\tthis.fire('layeradd', { layer: m });\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t//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\r\n\t\t\t\t\tif (m.__parent) {\r\n\t\t\t\t\t\tif (m.__parent.getChildCount() === 2) {\r\n\t\t\t\t\t\t\tvar markers = m.__parent.getAllChildMarkers(),\r\n\t\t\t\t\t\t\t otherMarker = markers[0] === m ? markers[1] : markers[0];\r\n\t\t\t\t\t\t\tfg.removeLayer(otherMarker);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (chunkProgress) {\r\n\t\t\t\t\t// report progress and time elapsed:\r\n\t\t\t\t\tchunkProgress(offset, l, (new Date()).getTime() - started);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// Completed processing all markers.\r\n\t\t\t\tif (offset === l) {\r\n\r\n\t\t\t\t\t// Refresh bounds and weighted positions.\r\n\t\t\t\t\tthis._topClusterLevel._recalculateBounds();\r\n\r\n\t\t\t\t\tthis._refreshClustersIcons();\r\n\r\n\t\t\t\t\tthis._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tsetTimeout(process, this.options.chunkDelay);\r\n\t\t\t\t}\r\n\t\t\t}, this);\r\n\r\n\t\t\tprocess();\r\n\t\t} else {\r\n\t\t\tvar needsClustering = this._needsClustering;\r\n\r\n\t\t\tfor (; offset < l; offset++) {\r\n\t\t\t\tm = layersArray[offset];\r\n\r\n\t\t\t\t// Group of layers, append children to layersArray and skip.\r\n\t\t\t\tif (m instanceof L.LayerGroup) {\r\n\t\t\t\t\tif (originalArray) {\r\n\t\t\t\t\t\tlayersArray = layersArray.slice();\r\n\t\t\t\t\t\toriginalArray = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tthis._extractNonGroupLayers(m, layersArray);\r\n\t\t\t\t\tl = layersArray.length;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\t//Not point data, can't be clustered\r\n\t\t\t\tif (!m.getLatLng) {\r\n\t\t\t\t\tnpg.addLayer(m);\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.hasLayer(m)) {\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tneedsClustering.push(m);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn this;\r\n\t},\r\n\r\n\t//Takes an array of markers and removes them in bulk\r\n\tremoveLayers: function (layersArray) {\r\n\t\tvar i, m,\r\n\t\t l = layersArray.length,\r\n\t\t fg = this._featureGroup,\r\n\t\t npg = this._nonPointGroup,\r\n\t\t originalArray = true;\r\n\r\n\t\tif (!this._map) {\r\n\t\t\tfor (i = 0; i < l; i++) {\r\n\t\t\t\tm = layersArray[i];\r\n\r\n\t\t\t\t// Group of layers, append children to layersArray and skip.\r\n\t\t\t\tif (m instanceof L.LayerGroup) {\r\n\t\t\t\t\tif (originalArray) {\r\n\t\t\t\t\t\tlayersArray = layersArray.slice();\r\n\t\t\t\t\t\toriginalArray = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tthis._extractNonGroupLayers(m, layersArray);\r\n\t\t\t\t\tl = layersArray.length;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tthis._arraySplice(this._needsClustering, m);\r\n\t\t\t\tnpg.removeLayer(m);\r\n\t\t\t\tif (this.hasLayer(m)) {\r\n\t\t\t\t\tthis._needsRemoving.push({ layer: m, latlng: m._latlng });\r\n\t\t\t\t}\r\n\t\t\t\tthis.fire('layerremove', { layer: m });\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tif (this._unspiderfy) {\r\n\t\t\tthis._unspiderfy();\r\n\r\n\t\t\t// Work on a copy of the array, so that next loop is not affected.\r\n\t\t\tvar layersArray2 = layersArray.slice(),\r\n\t\t\t l2 = l;\r\n\t\t\tfor (i = 0; i < l2; i++) {\r\n\t\t\t\tm = layersArray2[i];\r\n\r\n\t\t\t\t// Group of layers, append children to layersArray and skip.\r\n\t\t\t\tif (m instanceof L.LayerGroup) {\r\n\t\t\t\t\tthis._extractNonGroupLayers(m, layersArray2);\r\n\t\t\t\t\tl2 = layersArray2.length;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tthis._unspiderfyLayer(m);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor (i = 0; i < l; i++) {\r\n\t\t\tm = layersArray[i];\r\n\r\n\t\t\t// Group of layers, append children to layersArray and skip.\r\n\t\t\tif (m instanceof L.LayerGroup) {\r\n\t\t\t\tif (originalArray) {\r\n\t\t\t\t\tlayersArray = layersArray.slice();\r\n\t\t\t\t\toriginalArray = false;\r\n\t\t\t\t}\r\n\t\t\t\tthis._extractNonGroupLayers(m, layersArray);\r\n\t\t\t\tl = layersArray.length;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tif (!m.__parent) {\r\n\t\t\t\tnpg.removeLayer(m);\r\n\t\t\t\tthis.fire('layerremove', { layer: m });\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tthis._removeLayer(m, true, true);\r\n\t\t\tthis.fire('layerremove', { layer: m });\r\n\r\n\t\t\tif (fg.hasLayer(m)) {\r\n\t\t\t\tfg.removeLayer(m);\r\n\t\t\t\tif (m.clusterShow) {\r\n\t\t\t\t\tm.clusterShow();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Refresh bounds and weighted positions.\r\n\t\tthis._topClusterLevel._recalculateBounds();\r\n\r\n\t\tthis._refreshClustersIcons();\r\n\r\n\t\t//Fix up the clusters and markers on the map\r\n\t\tthis._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);\r\n\r\n\t\treturn this;\r\n\t},\r\n\r\n\t//Removes all layers from the MarkerClusterGroup\r\n\tclearLayers: function () {\r\n\t\t//Need our own special implementation as the LayerGroup one doesn't work for us\r\n\r\n\t\t//If we aren't on the map (yet), blow away the markers we know of\r\n\t\tif (!this._map) {\r\n\t\t\tthis._needsClustering = [];\r\n\t\t\tthis._needsRemoving = [];\r\n\t\t\tdelete this._gridClusters;\r\n\t\t\tdelete this._gridUnclustered;\r\n\t\t}\r\n\r\n\t\tif (this._noanimationUnspiderfy) {\r\n\t\t\tthis._noanimationUnspiderfy();\r\n\t\t}\r\n\r\n\t\t//Remove all the visible layers\r\n\t\tthis._featureGroup.clearLayers();\r\n\t\tthis._nonPointGroup.clearLayers();\r\n\r\n\t\tthis.eachLayer(function (marker) {\r\n\t\t\tmarker.off(this._childMarkerEventHandlers, this);\r\n\t\t\tdelete marker.__parent;\r\n\t\t}, this);\r\n\r\n\t\tif (this._map) {\r\n\t\t\t//Reset _topClusterLevel and the DistanceGrids\r\n\t\t\tthis._generateInitialClusters();\r\n\t\t}\r\n\r\n\t\treturn this;\r\n\t},\r\n\r\n\t//Override FeatureGroup.getBounds as it doesn't work\r\n\tgetBounds: function () {\r\n\t\tvar bounds = new L.LatLngBounds();\r\n\r\n\t\tif (this._topClusterLevel) {\r\n\t\t\tbounds.extend(this._topClusterLevel._bounds);\r\n\t\t}\r\n\r\n\t\tfor (var i = this._needsClustering.length - 1; i >= 0; i--) {\r\n\t\t\tbounds.extend(this._needsClustering[i].getLatLng());\r\n\t\t}\r\n\r\n\t\tbounds.extend(this._nonPointGroup.getBounds());\r\n\r\n\t\treturn bounds;\r\n\t},\r\n\r\n\t//Overrides LayerGroup.eachLayer\r\n\teachLayer: function (method, context) {\r\n\t\tvar markers = this._needsClustering.slice(),\r\n\t\t\tneedsRemoving = this._needsRemoving,\r\n\t\t\tthisNeedsRemoving, i, j;\r\n\r\n\t\tif (this._topClusterLevel) {\r\n\t\t\tthis._topClusterLevel.getAllChildMarkers(markers);\r\n\t\t}\r\n\r\n\t\tfor (i = markers.length - 1; i >= 0; i--) {\r\n\t\t\tthisNeedsRemoving = true;\r\n\r\n\t\t\tfor (j = needsRemoving.length - 1; j >= 0; j--) {\r\n\t\t\t\tif (needsRemoving[j].layer === markers[i]) {\r\n\t\t\t\t\tthisNeedsRemoving = false;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (thisNeedsRemoving) {\r\n\t\t\t\tmethod.call(context, markers[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tthis._nonPointGroup.eachLayer(method, context);\r\n\t},\r\n\r\n\t//Overrides LayerGroup.getLayers\r\n\tgetLayers: function () {\r\n\t\tvar layers = [];\r\n\t\tthis.eachLayer(function (l) {\r\n\t\t\tlayers.push(l);\r\n\t\t});\r\n\t\treturn layers;\r\n\t},\r\n\r\n\t//Overrides LayerGroup.getLayer, WARNING: Really bad performance\r\n\tgetLayer: function (id) {\r\n\t\tvar result = null;\r\n\r\n\t\tid = parseInt(id, 10);\r\n\r\n\t\tthis.eachLayer(function (l) {\r\n\t\t\tif (L.stamp(l) === id) {\r\n\t\t\t\tresult = l;\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\treturn result;\r\n\t},\r\n\r\n\t//Returns true if the given layer is in this MarkerClusterGroup\r\n\thasLayer: function (layer) {\r\n\t\tif (!layer) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tvar i, anArray = this._needsClustering;\r\n\r\n\t\tfor (i = anArray.length - 1; i >= 0; i--) {\r\n\t\t\tif (anArray[i] === layer) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tanArray = this._needsRemoving;\r\n\t\tfor (i = anArray.length - 1; i >= 0; i--) {\r\n\t\t\tif (anArray[i].layer === layer) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn !!(layer.__parent && layer.__parent._group === this) || this._nonPointGroup.hasLayer(layer);\r\n\t},\r\n\r\n\t//Zoom down to show the given layer (spiderfying if necessary) then calls the callback\r\n\tzoomToShowLayer: function (layer, callback) {\r\n\r\n\t\tif (typeof callback !== 'function') {\r\n\t\t\tcallback = function () {};\r\n\t\t}\r\n\r\n\t\tvar showMarker = function () {\r\n\t\t\tif ((layer._icon || layer.__parent._icon) && !this._inZoomAnimation) {\r\n\t\t\t\tthis._map.off('moveend', showMarker, this);\r\n\t\t\t\tthis.off('animationend', showMarker, this);\r\n\r\n\t\t\t\tif (layer._icon) {\r\n\t\t\t\t\tcallback();\r\n\t\t\t\t} else if (layer.__parent._icon) {\r\n\t\t\t\t\tthis.once('spiderfied', callback, this);\r\n\t\t\t\t\tlayer.__parent.spiderfy();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tif (layer._icon && this._map.getBounds().contains(layer.getLatLng())) {\r\n\t\t\t//Layer is visible ond on screen, immediate return\r\n\t\t\tcallback();\r\n\t\t} else if (layer.__parent._zoom < Math.round(this._map._zoom)) {\r\n\t\t\t//Layer should be visible at this zoom level. It must not be on screen so just pan over to it\r\n\t\t\tthis._map.on('moveend', showMarker, this);\r\n\t\t\tthis._map.panTo(layer.getLatLng());\r\n\t\t} else {\r\n\t\t\tthis._map.on('moveend', showMarker, this);\r\n\t\t\tthis.on('animationend', showMarker, this);\r\n\t\t\tlayer.__parent.zoomToBounds();\r\n\t\t}\r\n\t},\r\n\r\n\t//Overrides FeatureGroup.onAdd\r\n\tonAdd: function (map) {\r\n\t\tthis._map = map;\r\n\t\tvar i, l, layer;\r\n\r\n\t\tif (!isFinite(this._map.getMaxZoom())) {\r\n\t\t\tthrow \"Map has no maxZoom specified\";\r\n\t\t}\r\n\r\n\t\tthis._featureGroup.addTo(map);\r\n\t\tthis._nonPointGroup.addTo(map);\r\n\r\n\t\tif (!this._gridClusters) {\r\n\t\t\tthis._generateInitialClusters();\r\n\t\t}\r\n\r\n\t\tthis._maxLat = map.options.crs.projection.MAX_LATITUDE;\r\n\r\n\t\t//Restore all the positions as they are in the MCG before removing them\r\n\t\tfor (i = 0, l = this._needsRemoving.length; i < l; i++) {\r\n\t\t\tlayer = this._needsRemoving[i];\r\n\t\t\tlayer.newlatlng = layer.layer._latlng;\r\n\t\t\tlayer.layer._latlng = layer.latlng;\r\n\t\t}\r\n\t\t//Remove them, then restore their new positions\r\n\t\tfor (i = 0, l = this._needsRemoving.length; i < l; i++) {\r\n\t\t\tlayer = this._needsRemoving[i];\r\n\t\t\tthis._removeLayer(layer.layer, true);\r\n\t\t\tlayer.layer._latlng = layer.newlatlng;\r\n\t\t}\r\n\t\tthis._needsRemoving = [];\r\n\r\n\t\t//Remember the current zoom level and bounds\r\n\t\tthis._zoom = Math.round(this._map._zoom);\r\n\t\tthis._currentShownBounds = this._getExpandedVisibleBounds();\r\n\r\n\t\tthis._map.on('zoomend', this._zoomEnd, this);\r\n\t\tthis._map.on('moveend', this._moveEnd, this);\r\n\r\n\t\tif (this._spiderfierOnAdd) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely\r\n\t\t\tthis._spiderfierOnAdd();\r\n\t\t}\r\n\r\n\t\tthis._bindEvents();\r\n\r\n\t\t//Actually add our markers to the map:\r\n\t\tl = this._needsClustering;\r\n\t\tthis._needsClustering = [];\r\n\t\tthis.addLayers(l, true);\r\n\t},\r\n\r\n\t//Overrides FeatureGroup.onRemove\r\n\tonRemove: function (map) {\r\n\t\tmap.off('zoomend', this._zoomEnd, this);\r\n\t\tmap.off('moveend', this._moveEnd, this);\r\n\r\n\t\tthis._unbindEvents();\r\n\r\n\t\t//In case we are in a cluster animation\r\n\t\tthis._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', '');\r\n\r\n\t\tif (this._spiderfierOnRemove) { //TODO FIXME: Not sure how to have spiderfier add something on here nicely\r\n\t\t\tthis._spiderfierOnRemove();\r\n\t\t}\r\n\r\n\t\tdelete this._maxLat;\r\n\r\n\t\t//Clean up all the layers we added to the map\r\n\t\tthis._hideCoverage();\r\n\t\tthis._featureGroup.remove();\r\n\t\tthis._nonPointGroup.remove();\r\n\r\n\t\tthis._featureGroup.clearLayers();\r\n\r\n\t\tthis._map = null;\r\n\t},\r\n\r\n\tgetVisibleParent: function (marker) {\r\n\t\tvar vMarker = marker;\r\n\t\twhile (vMarker && !vMarker._icon) {\r\n\t\t\tvMarker = vMarker.__parent;\r\n\t\t}\r\n\t\treturn vMarker || null;\r\n\t},\r\n\r\n\t//Remove the given object from the given array\r\n\t_arraySplice: function (anArray, obj) {\r\n\t\tfor (var i = anArray.length - 1; i >= 0; i--) {\r\n\t\t\tif (anArray[i] === obj) {\r\n\t\t\t\tanArray.splice(i, 1);\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\r\n\t/**\r\n\t * Removes a marker from all _gridUnclustered zoom levels, starting at the supplied zoom.\r\n\t * @param marker to be removed from _gridUnclustered.\r\n\t * @param z integer bottom start zoom level (included)\r\n\t * @private\r\n\t */\r\n\t_removeFromGridUnclustered: function (marker, z) {\r\n\t\tvar map = this._map,\r\n\t\t gridUnclustered = this._gridUnclustered,\r\n\t\t\tminZoom = Math.floor(this._map.getMinZoom());\r\n\r\n\t\tfor (; z >= minZoom; z--) {\r\n\t\t\tif (!gridUnclustered[z].removeObject(marker, map.project(marker.getLatLng(), z))) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\r\n\t_childMarkerDragStart: function (e) {\r\n\t\te.target.__dragStart = e.target._latlng;\r\n\t},\r\n\r\n\t_childMarkerMoved: function (e) {\r\n\t\tif (!this._ignoreMove && !e.target.__dragStart) {\r\n\t\t\tvar isPopupOpen = e.target._popup && e.target._popup.isOpen();\r\n\r\n\t\t\tthis._moveChild(e.target, e.oldLatLng, e.latlng);\r\n\r\n\t\t\tif (isPopupOpen) {\r\n\t\t\t\te.target.openPopup();\r\n\t\t\t}\r\n\t\t}\r\n\t},\r\n\r\n\t_moveChild: function (layer, from, to) {\r\n\t\tlayer._latlng = from;\r\n\t\tthis.removeLayer(layer);\r\n\r\n\t\tlayer._latlng = to;\r\n\t\tthis.addLayer(layer);\r\n\t},\r\n\r\n\t_childMarkerDragEnd: function (e) {\r\n\t\tvar dragStart = e.target.__dragStart;\r\n\t\tdelete e.target.__dragStart;\r\n\t\tif (dragStart) {\r\n\t\t\tthis._moveChild(e.target, dragStart, e.target._latlng);\r\n\t\t}\t\t\r\n\t},\r\n\r\n\r\n\t//Internal function for removing a marker from everything.\r\n\t//dontUpdateMap: set to true if you will handle updating the map manually (for bulk functions)\r\n\t_removeLayer: function (marker, removeFromDistanceGrid, dontUpdateMap) {\r\n\t\tvar gridClusters = this._gridClusters,\r\n\t\t\tgridUnclustered = this._gridUnclustered,\r\n\t\t\tfg = this._featureGroup,\r\n\t\t\tmap = this._map,\r\n\t\t\tminZoom = Math.floor(this._map.getMinZoom());\r\n\r\n\t\t//Remove the marker from distance clusters it might be in\r\n\t\tif (removeFromDistanceGrid) {\r\n\t\t\tthis._removeFromGridUnclustered(marker, this._maxZoom);\r\n\t\t}\r\n\r\n\t\t//Work our way up the clusters removing them as we go if required\r\n\t\tvar cluster = marker.__parent,\r\n\t\t\tmarkers = cluster._markers,\r\n\t\t\totherMarker;\r\n\r\n\t\t//Remove the marker from the immediate parents marker list\r\n\t\tthis._arraySplice(markers, marker);\r\n\r\n\t\twhile (cluster) {\r\n\t\t\tcluster._childCount--;\r\n\t\t\tcluster._boundsNeedUpdate = true;\r\n\r\n\t\t\tif (cluster._zoom < minZoom) {\r\n\t\t\t\t//Top level, do nothing\r\n\t\t\t\tbreak;\r\n\t\t\t} else if (removeFromDistanceGrid && cluster._childCount <= 1) { //Cluster no longer required\r\n\t\t\t\t//We need to push the other marker up to the parent\r\n\t\t\t\totherMarker = cluster._markers[0] === marker ? cluster._markers[1] : cluster._markers[0];\r\n\r\n\t\t\t\t//Update distance grid\r\n\t\t\t\tgridClusters[cluster._zoom].removeObject(cluster, map.project(cluster._cLatLng, cluster._zoom));\r\n\t\t\t\tgridUnclustered[cluster._zoom].addObject(otherMarker, map.project(otherMarker.getLatLng(), cluster._zoom));\r\n\r\n\t\t\t\t//Move otherMarker up to parent\r\n\t\t\t\tthis._arraySplice(cluster.__parent._childClusters, cluster);\r\n\t\t\t\tcluster.__parent._markers.push(otherMarker);\r\n\t\t\t\totherMarker.__parent = cluster.__parent;\r\n\r\n\t\t\t\tif (cluster._icon) {\r\n\t\t\t\t\t//Cluster is currently on the map, need to put the marker on the map instead\r\n\t\t\t\t\tfg.removeLayer(cluster);\r\n\t\t\t\t\tif (!dontUpdateMap) {\r\n\t\t\t\t\t\tfg.addLayer(otherMarker);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tcluster._iconNeedsUpdate = true;\r\n\t\t\t}\r\n\r\n\t\t\tcluster = cluster.__parent;\r\n\t\t}\r\n\r\n\t\tdelete marker.__parent;\r\n\t},\r\n\r\n\t_isOrIsParent: function (el, oel) {\r\n\t\twhile (oel) {\r\n\t\t\tif (el === oel) {\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\toel = oel.parentNode;\r\n\t\t}\r\n\t\treturn false;\r\n\t},\r\n\r\n\t//Override L.Evented.fire\r\n\tfire: function (type, data, propagate) {\r\n\t\tif (data && data.layer instanceof L.MarkerCluster) {\r\n\t\t\t//Prevent multiple clustermouseover/off events if the icon is made up of stacked divs (Doesn't work in ie <= 8, no relatedTarget)\r\n\t\t\tif (data.originalEvent && this._isOrIsParent(data.layer._icon, data.originalEvent.relatedTarget)) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\ttype = 'cluster' + type;\r\n\t\t}\r\n\r\n\t\tL.FeatureGroup.prototype.fire.call(this, type, data, propagate);\r\n\t},\r\n\r\n\t//Override L.Evented.listens\r\n\tlistens: function (type, propagate) {\r\n\t\treturn L.FeatureGroup.prototype.listens.call(this, type, propagate) || L.FeatureGroup.prototype.listens.call(this, 'cluster' + type, propagate);\r\n\t},\r\n\r\n\t//Default functionality\r\n\t_defaultIconCreateFunction: function (cluster) {\r\n\t\tvar childCount = cluster.getChildCount();\r\n\r\n\t\tvar c = ' marker-cluster-';\r\n\t\tif (childCount < 10) {\r\n\t\t\tc += 'small';\r\n\t\t} else if (childCount < 100) {\r\n\t\t\tc += 'medium';\r\n\t\t} else {\r\n\t\t\tc += 'large';\r\n\t\t}\r\n\r\n\t\treturn new L.DivIcon({ html: '