[Pkg-javascript-commits] [leaflet-markercluster] 295/479: 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 :(

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet-markercluster.

commit 13e71f5a85573011b420145237891376f38039a2
Author: danzel <danzel at localhost.geek.nz>
Date:   Thu Dec 6 09:47:31 2012 +1300

    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
---
 README.md                 |  1 +
 src/MarkerClusterGroup.js | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/README.md b/README.md
index 7caa9e2..3843e38 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 d5c7f29..262e655 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) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet-markercluster.git



More information about the Pkg-javascript-commits mailing list