Add eachChildLayer, an eachLayer implementation. We cannot override eachLayer as we have different behaviour. Doing so makes us add all makers to the map always which is dumb :(

Fixes #102
This commit is contained in:
danzel
2012-12-06 09:47:31 +13:00
parent f9539fed32
commit 13e71f5a85
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -107,6 +107,7 @@ If you are removing a lot of markers it will almost definitely be better to call
### Other Methods
````
eachChildLayer(method, context): Provides an eachLayer implementation. (eachLayer operates on each visible layer, this method runs on all layers added to the MarkerClusterGroup)
hasLayer(layer): Returns true if the given layer (marker) is in the MarkerClusterGroup
zoomToShowLayer(layer, callback): Zooms to show the given marker (spidifying if required), calls the callback when the marker is visible on the map
addLayers(layerArray): Adds the markers in the given array from the MarkerClusterGroup in an efficent bulk method.
+14
View File
@@ -230,6 +230,20 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
return bounds;
},
//Don't override LayerGroup.eachLayer, but provide the same functionality for external users
eachChildLayer: function (method, context) {
var markers = this._needsClustering.slice(),
i;
if (this._topClusterLevel) {
this._topClusterLevel.getAllChildMarkers(markers);
}
for (i = markers.length - 1; i >= 0; i--) {
method.call(context, markers[i]);
}
},
//Returns true if the given layer is in this MarkerClusterGroup
hasLayer: function (layer) {
if (this._needsClustering.length > 0) {