diff --git a/README.md b/README.md index baffeac1d9..b35ed825e1 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Check out the [custom example](http://danzel.github.com/Leaflet.markercluster/ex ### Other Options disableClusteringAtZoom: If set, at this zoom level and below markers will not be clustered. This defaults to disabled. [See Example](http://danzel.github.com/Leaflet.markercluster/example/marker-clustering-realworld-maxzoom.388.html) 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 0ee8deb0ad..0778077273 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -14,7 +14,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ zoomToBoundsOnClick: true, singleMarkerMode: false, - disableClusteringAtZoom: null + disableClusteringAtZoom: null, + + skipDuplicateAddTesting: false }, initialize: function (options) { @@ -33,8 +35,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ addLayer: function (layer) { - if (layer instanceof L.LayerGroup) - { + if (layer instanceof L.LayerGroup) { for (var i in layer._layers) { if (layer._layers.hasOwnProperty(i)) { this.addLayer(layer._layers[i]); @@ -59,6 +60,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ return this; } + if (!this.options.skipDuplicateAddTesting && this.hasLayer(layer)) { + return this; + } + //If we have already clustered we'll need to add this one to a cluster if (this._unspiderfy) {