[Pkg-javascript-commits] [leaflet-markercluster] 258/479: Add addLayers, takes an array of markers and adds them in bulk for awesome performance. TODO: Docs+Example. Refs #59

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:37 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 9dab59f1754a8fd82164ba958d4bd7fd1792bf3d
Author: danzel <danzel at localhost.geek.nz>
Date:   Wed Oct 10 17:18:03 2012 +1300

    Add addLayers, takes an array of markers and adds them in bulk for awesome performance. TODO: Docs+Example. Refs #59
---
 src/MarkerClusterGroup.js | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 1dba89c..92a3872 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -43,12 +43,13 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	addLayer: function (layer) {
 
 		if (layer instanceof L.LayerGroup) {
+			var array = [];
 			for (var i in layer._layers) {
 				if (layer._layers.hasOwnProperty(i)) {
-					this.addLayer(layer._layers[i]);
+					array.push(layer._layers[i]);
 				}
 			}
-			return this;
+			return this.addLayers(array);
 		}
 
 		if (this.options.singleMarkerMode) {
@@ -124,6 +125,30 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		return this;
 	},
 
+	addLayers: function (layersArray) {
+		if (!this._map) {
+			this._needsClustering = this._needsClustering.concat(layersArray);
+			return this;
+		}
+
+		for (var i = 0, l = layersArray.length; i < l; i++) {
+			var m = layersArray[i];
+			this._addLayer(m, this._maxZoom);
+
+			//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
+			if (m.__parent) {
+				if (m.__parent.getChildCount() === 2) {
+					var markers = m.__parent.getAllChildMarkers(),
+						otherMarker = markers[0] === m ? markers[1] : markers[0];
+					L.FeatureGroup.prototype.removeLayer.call(this, otherMarker);
+				}
+			}
+		}
+		this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds);
+
+		return this;
+	},
+
 	clearLayers: function () {
 		//Need our own special implementation as the LayerGroup one doesn't work for us
 

-- 
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