[Pkg-javascript-commits] [leaflet-markercluster] 263/479: Remove skipDuplicateAddTesting (as hasLayer is now efficient!). Make hasLayer work when we haven't been added to the map yet

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 8432f0e7c2f8fb7f33ccf54854f1ffffaefa10ba
Author: danzel <danzel at localhost.geek.nz>
Date:   Thu Oct 11 10:23:10 2012 +1300

    Remove skipDuplicateAddTesting (as hasLayer is now efficient!). Make hasLayer work when we haven't been added to the map yet
---
 README.md                 |  1 -
 src/MarkerClusterGroup.js | 23 ++++++++++-------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md
index a225bad..45ab38e 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,6 @@ Other options
 * **maxClusterRadius**: The maximum radius that a cluster will cover from the central marker (in pixels). Default 80. Decreasing will make more smaller clusters.
 * **polygonOptions**: Options to pass when creating the L.Polygon to show the bounds of a cluster
 * **singleMarkerMode**: If set to true, overrides the icon for all added markers to make them appear as a 1 size cluster
-* **skipDuplicateAddTesting**: By default we check if a marker already exists in the cluster when addLayer is called. To disable this behaviour set this to true. You must only do this if you know you will not try add markers that are already in the cluster. Provides a slight performance boost to addLayer when called after the MarkerClusterGroup is on the map.
 
 ## Events
 If you register for click, mouseover, etc events just related to Markers in the cluster.
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 02be113..cdc3d5d 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -16,8 +16,6 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 		disableClusteringAtZoom: null,
 
-		skipDuplicateAddTesting: false,
-
 		//Whether to animate adding markers after adding the MarkerClusterGroup to the map
 		// If you are adding individual markers set to true, if adding bulk markers leave false for massive performance gains.
 		animateAddingMarkers: false,
@@ -68,7 +66,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			return this;
 		}
 
-		if (!this.options.skipDuplicateAddTesting && this.hasLayer(layer)) {
+		if (this.hasLayer(layer)) {
 			return this;
 		}
 
@@ -215,17 +213,16 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 	//Returns true if the given layer is in this MarkerClusterGroup
 	hasLayer: function (layer) {
-		var res = false;
-
-		this._topClusterLevel._recursively(new L.LatLngBounds([layer.getLatLng()]), 0, this._map.getMaxZoom() + 1,
-			function (cluster) {
-				for (var i = cluster._markers.length - 1; i >= 0 && !res; i--) {
-					if (cluster._markers[i] === layer) {
-						res = true;
-					}
+		if (this._needsClustering.length > 0) {
+			var anArray = this._needsClustering;
+			for (var i = anArray.length - 1; i >= 0; i--) {
+				if (anArray[i] === layer) {
+					return true;
 				}
-			}, null);
-		return res;
+			}
+		}
+
+		return !!(layer.__parent && layer.__parent._group === this);
 	},
 
 	//Zoom down to show the given layer (spiderfying if necessary) then calls the callback

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