diff --git a/README.md b/README.md index 7caa9e253..3843e3809 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index d5c7f2972..262e6558d 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -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) {