[Pkg-javascript-commits] [leaflet-markercluster] 106/128: Support layerremove event. fixes #647

Jonas Smedegaard dr at jones.dk
Sun Apr 16 06:26:08 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet-markercluster.

commit 16cf328a5a5f8b3a6381cdaea6e5160de8629ff8
Author: danzel <dave at smartrak.co.nz>
Date:   Fri Jan 27 10:36:34 2017 +1300

    Support layerremove event. fixes #647
---
 spec/suites/eventsSpec.js | 110 ++++++++++++++++++++++++++++++++++++++++++++++
 src/MarkerClusterGroup.js |   6 +++
 2 files changed, 116 insertions(+)

diff --git a/spec/suites/eventsSpec.js b/spec/suites/eventsSpec.js
index 6d1c3dc..0b5b430 100644
--- a/spec/suites/eventsSpec.js
+++ b/spec/suites/eventsSpec.js
@@ -192,6 +192,7 @@
 			expect(callback.called).to.be(true);
 		});
 
+		//layeradd
 		it('fires layeradd when markers are added while not on the map', function() {
 			var callback = sinon.spy();
 
@@ -267,6 +268,115 @@
 
 			expect(callback.callCount).to.be(1);
 		});
+
+		//layerremove
+		it('fires layerremove when a marker is removed while not on the map', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup();
+			group.on('layerremove', callback);
+
+			var marker = new L.Marker([1.5, 1.5]);
+			group.addLayer(marker);
+			group.removeLayer(marker);
+
+			expect(callback.callCount).to.be(1);
+		});
+
+		it('fires layerremove when a vector is removed while not on the map', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup();
+			group.on('layerremove', callback);
+
+			var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+			group.addLayer(polygon);
+			group.removeLayer(polygon);
+
+			expect(callback.callCount).to.be(1);
+		});
+		
+		it('fires layerremove when a marker is removed while on the map', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup();
+			group.on('layerremove', callback);
+			map.addLayer(group);
+
+			var marker = new L.Marker([1.5, 1.5]);
+			group.addLayer(marker);
+			group.removeLayer(marker);
+
+			expect(callback.callCount).to.be(1);
+		});
+
+		it('fires layerremove when a vector is removed while on the map', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup();
+			group.on('layerremove', callback);
+			map.addLayer(group);
+
+			var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+			group.addLayer(polygon);
+			group.removeLayer(polygon);
+
+			expect(callback.callCount).to.be(1);
+		});
+		
+		it('fires layerremove when a marker is removed using removeLayers while on the map with chunked loading', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup({ chunkedLoading: true });
+			group.on('layerremove', callback);
+			map.addLayer(group);
+
+			var marker = new L.Marker([1.5, 1.5]);
+			group.addLayers([marker]);
+			group.removeLayers([marker]);
+
+			expect(callback.callCount).to.be(1);
+		});
+
+		it('fires layerremove when a vector is removed using removeLayers while on the map with chunked loading', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup({ chunkedLoading: true });
+			group.on('layerremove', callback);
+			map.addLayer(group);
+
+			var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+			group.addLayers([polygon]);
+			group.removeLayers([polygon]);
+
+			expect(callback.callCount).to.be(1);
+		});
+		
+		it('fires layerremove when a marker is removed using removeLayers while not on the map with chunked loading', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup({ chunkedLoading: true });
+			group.on('layerremove', callback);
+
+			var marker = new L.Marker([1.5, 1.5]);
+			group.addLayers([marker]);
+			group.removeLayers([marker]);
+
+			expect(callback.callCount).to.be(1);
+		});
+
+		it('fires layerremove when a vector is removed using removeLayers while not on the map with chunked loading', function() {
+			var callback = sinon.spy();
+
+			group = new L.MarkerClusterGroup({ chunkedLoading: true });
+			group.on('layerremove', callback);
+
+			var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+			group.addLayers([polygon]);
+			group.removeLayers([polygon]);
+
+			expect(callback.callCount).to.be(1);
+		});
 	});
 
 	/*
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 2d315f9..ee94f71 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -143,6 +143,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		//Non point layers
 		if (!layer.getLatLng) {
 			this._nonPointGroup.removeLayer(layer);
+			this.fire('layerremove', { layer: layer });
 			return this;
 		}
 
@@ -150,6 +151,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) {
 				this._needsRemoving.push(layer);
 			}
+			this.fire('layerremove', { layer: layer });
 			return this;
 		}
 
@@ -164,6 +166,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 		//Remove the marker from clusters
 		this._removeLayer(layer, true);
+		this.fire('layerremove', { layer: layer });
 
 		// Refresh bounds and weighted positions.
 		this._topClusterLevel._recalculateBounds();
@@ -338,6 +341,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 				if (this.hasLayer(m)) {
 					this._needsRemoving.push(m);
 				}
+				this.fire('layerremove', { layer: m });
 			}
 			return this;
 		}
@@ -378,10 +382,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 			if (!m.__parent) {
 				npg.removeLayer(m);
+				this.fire('layerremove', { layer: m });
 				continue;
 			}
 
 			this._removeLayer(m, true, true);
+			this.fire('layerremove', { layer: m });
 
 			if (fg.hasLayer(m)) {
 				fg.removeLayer(m);

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