[Pkg-javascript-commits] [leaflet-markercluster] 416/479: removeLayer supports LayerGroup. Fixes #236

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:01:03 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 4f40622dfec4cc1328aca003a0fe63afdc582b1d
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Aug 26 15:39:25 2013 +1200

    removeLayer supports LayerGroup. Fixes #236
---
 spec/suites/RemoveLayerSpec.js | 33 +++++++++++++++++++++++++++++++++
 src/MarkerClusterGroup.js      |  9 +++++++++
 2 files changed, 42 insertions(+)

diff --git a/spec/suites/RemoveLayerSpec.js b/spec/suites/RemoveLayerSpec.js
index 7c65600..52f014c 100644
--- a/spec/suites/RemoveLayerSpec.js
+++ b/spec/suites/RemoveLayerSpec.js
@@ -125,4 +125,37 @@
 		expect(marker._icon).to.be(null);
 		expect(marker2._icon.parentNode).to.be(map._panes.markerPane);
 	});
+
+	it('removes the layers that are in the given LayerGroup', function () {
+
+		var group = new L.MarkerClusterGroup();
+		var marker = new L.Marker([1.5, 1.5]);
+		var marker2 = new L.Marker([1.5, 1.5]);
+
+		map.addLayer(group);
+		group.addLayers([marker, marker2]);
+
+		var layer = L.layerGroup();
+		layer.addLayer(marker2);
+		group.removeLayer(layer);
+
+		expect(marker._icon).to.not.be(undefined);
+		expect(marker2._icon).to.be(undefined);
+	});
+
+	it('removes the layers that are in the given LayerGroup when not on the map', function () {
+
+		var group = new L.MarkerClusterGroup();
+		var marker = new L.Marker([1.5, 1.5]);
+		var marker2 = new L.Marker([1.5, 1.5]);
+
+		group.addLayers([marker, marker2]);
+
+		var layer = L.layerGroup();
+		layer.addLayer(marker2);
+		group.removeLayer(layer);
+
+		expect(group.hasLayer(marker)).to.be(true);
+		expect(group.hasLayer(marker2)).to.be(false);
+	});
 });
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 89b26e7..8a58a6e 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -105,6 +105,15 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 	removeLayer: function (layer) {
 
+		if (layer instanceof L.LayerGroup)
+		{
+			var array = [];
+			for (var i in layer._layers) {
+				array.push(layer._layers[i]);
+			}
+			return this.removeLayers(array);
+		}
+
 		//Non point layers
 		if (!layer.getLatLng) {
 			this._nonPointGroup.removeLayer(layer);

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