From 8432f0e7c2f8fb7f33ccf54854f1ffffaefa10ba Mon Sep 17 00:00:00 2001 From: danzel Date: Thu, 11 Oct 2012 10:23:10 +1300 Subject: [PATCH] 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 a225badd76..45ab38e94e 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 02be113e02..cdc3d5dd14 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