Remove skipDuplicateAddTesting (as hasLayer is now efficient!). Make hasLayer work when we haven't been added to the map yet

This commit is contained in:
danzel
2012-10-11 10:23:10 +13:00
parent a1a2a99519
commit 8432f0e7c2
2 changed files with 10 additions and 14 deletions
-1
View File
@@ -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.
+10 -13
View File
@@ -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