[Pkg-javascript-commits] [leaflet-markercluster] 105/128: Support layeradd event. refs #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 2a88279e960f34019cd4b10cc478476a9789b7ae
Author: danzel <dave at smartrak.co.nz>
Date: Fri Jan 27 10:25:11 2017 +1300
Support layeradd event. refs #647
---
spec/suites/eventsSpec.js | 76 +++++++++++++++++++++++++++++++++++++++++++++++
src/MarkerClusterGroup.js | 13 ++++++--
2 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/spec/suites/eventsSpec.js b/spec/suites/eventsSpec.js
index e2a64dd..6d1c3dc 100644
--- a/spec/suites/eventsSpec.js
+++ b/spec/suites/eventsSpec.js
@@ -191,6 +191,82 @@
expect(callback.called).to.be(true);
});
+
+ it('fires layeradd when markers are added while not on the map', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup();
+ group.on('layeradd', callback);
+
+ var marker = new L.Marker([1.5, 1.5]);
+ group.addLayer(marker);
+
+ expect(callback.callCount).to.be(1);
+ });
+
+ it('fires layeradd when vectors are added while not on the map', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup();
+ group.on('layeradd', 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);
+
+ expect(callback.callCount).to.be(1);
+ });
+
+ it('fires layeradd when markers are added while on the map', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup();
+ group.on('layeradd', callback);
+ map.addLayer(group);
+
+ var marker = new L.Marker([1.5, 1.5]);
+ group.addLayer(marker);
+
+ expect(callback.callCount).to.be(1);
+ });
+
+ it('fires layeradd when vectors are added while on the map', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup();
+ group.on('layeradd', 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);
+
+ expect(callback.callCount).to.be(1);
+ });
+
+ it('fires layeradd when markers are added using addLayers while on the map with chunked loading', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup({ chunkedLoading: true });
+ group.on('layeradd', callback);
+ map.addLayer(group);
+
+ var marker = new L.Marker([1.5, 1.5]);
+ group.addLayers([marker]);
+
+ expect(callback.callCount).to.be(1);
+ });
+
+ it('fires layeradd when vectors are added using addLayers while on the map with chunked loading', function() {
+ var callback = sinon.spy();
+
+ group = new L.MarkerClusterGroup({ chunkedLoading: true });
+ group.on('layeradd', 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]);
+
+ expect(callback.callCount).to.be(1);
+ });
});
/*
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index e9eec0b..2d315f9 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -86,11 +86,13 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Don't cluster non point data
if (!layer.getLatLng) {
this._nonPointGroup.addLayer(layer);
+ this.fire('layeradd', { layer: layer });
return this;
}
if (!this._map) {
this._needsClustering.push(layer);
+ this.fire('layeradd', { layer: layer });
return this;
}
@@ -106,6 +108,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
this._addLayer(layer, this._maxZoom);
+ this.fire('layeradd', { layer: layer });
// Refresh bounds and weighted positions.
this._topClusterLevel._recalculateBounds();
@@ -180,7 +183,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
},
//Takes an array of markers and adds them in bulk
- addLayers: function (layersArray) {
+ addLayers: function (layersArray, skipLayerAddEvent) {
if (!L.Util.isArray(layersArray)) {
return this.addLayer(layersArray);
}
@@ -229,6 +232,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Not point data, can't be clustered
if (!m.getLatLng) {
npg.addLayer(m);
+ if (!skipLayerAddEvent) {
+ this.fire('layeradd', { layer: m });
+ }
continue;
}
@@ -237,6 +243,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
this._addLayer(m, this._maxZoom);
+ if (!skipLayerAddEvent) {
+ this.fire('layeradd', { layer: m });
+ }
//If we just made a cluster of size 2 then we need to remove the other marker from the map (if it is) or we never will
if (m.__parent) {
@@ -584,7 +593,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Actually add our markers to the map:
l = this._needsClustering;
this._needsClustering = [];
- this.addLayers(l);
+ this.addLayers(l, true);
},
//Overrides FeatureGroup.onRemove
--
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