[Pkg-javascript-commits] [leaflet-markercluster] 197/479: 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.

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:29 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 374e74f78acff3ca142c8fdf92d1d03564a6dc10
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Sep 3 10:34:59 2012 +1200

    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.
---
 README.md                 |  1 +
 src/MarkerClusterGroup.js | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index baffeac..b35ed82 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 0ee8deb..0778077 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) {

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