Test if a marker is already in the cluster before adding it. You can skip this (for performance) by setting the skipDuplicateAddTesting option. Testing is only done after the MarkerClusterGroup has been added to the map, so any duplicates added before then will not be caught.

This commit is contained in:
danzel
2012-09-03 10:34:59 +12:00
parent 2ccd15bd43
commit 374e74f78a
2 changed files with 9 additions and 3 deletions

View File

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

View File

@@ -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) {