[Pkg-javascript-commits] [leaflet-markercluster] 432/479: Add getLayers and test it. fixes #222
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:01:04 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 1ac2d9ef6808310e8ca97886d85c2e2cd03eff7b
Author: danzel <danzel at localhost.geek.nz>
Date: Mon Oct 21 11:02:10 2013 +1300
Add getLayers and test it. fixes #222
---
spec/index.html | 1 +
spec/suites/getLayersSpec.js | 48 ++++++++++++++++++++++++++++++++++++++++++++
src/MarkerClusterGroup.js | 9 +++++++++
3 files changed, 58 insertions(+)
diff --git a/spec/index.html b/spec/index.html
index d7cae1c..6b00aae 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -46,6 +46,7 @@
<script type="text/javascript" src="suites/eachLayerSpec.js"></script>
<script type="text/javascript" src="suites/eventsSpec.js"></script>
<script type="text/javascript" src="suites/getBoundsSpec.js"></script>
+ <script type="text/javascript" src="suites/getLayersSpec.js"></script>
<script type="text/javascript" src="suites/NonPointSpec.js"></script>
diff --git a/spec/suites/getLayersSpec.js b/spec/suites/getLayersSpec.js
new file mode 100644
index 0000000..1c45096
--- /dev/null
+++ b/spec/suites/getLayersSpec.js
@@ -0,0 +1,48 @@
+describe('getLayers', function () {
+ var map, div;
+ beforeEach(function () {
+ div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '200px';
+ document.body.appendChild(div);
+
+ map = L.map(div, { maxZoom: 18 });
+
+ map.fitBounds(new L.LatLngBounds([
+ [1, 1],
+ [2, 2]
+ ]));
+ });
+ afterEach(function () {
+ document.body.removeChild(div);
+ });
+
+ it('hits polygons and markers before adding to map', function () {
+ var group = new L.MarkerClusterGroup();
+ var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+ var marker = new L.Marker([1.5, 1.5]);
+
+ group.addLayers([polygon, marker]);
+
+ var layers = group.getLayers();
+
+ expect(layers.length).to.be(2);
+ expect(layers).to.contain(marker);
+ expect(layers).to.contain(polygon);
+ });
+
+ it('hits polygons and markers after adding to map', function () {
+ var group = new L.MarkerClusterGroup();
+ var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+ var marker = new L.Marker([1.5, 1.5]);
+
+ group.addLayers([polygon, marker]);
+ map.addLayer(group);
+
+ var layers = group.getLayers();
+
+ expect(layers.length).to.be(2);
+ expect(layers).to.contain(marker);
+ expect(layers).to.contain(polygon);
+ });
+});
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 91678a7..896d855 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -308,6 +308,15 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._nonPointGroup.eachLayer(method, context);
},
+ //Overrides LayerGroup.getLayers
+ getLayers: function () {
+ var layers = [];
+ this.eachLayer(function (l) {
+ layers.push(l);
+ });
+ return layers;
+ },
+
//Returns true if the given layer is in this MarkerClusterGroup
hasLayer: function (layer) {
if (!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