[Pkg-javascript-commits] [leaflet-markercluster] 402/479: Throw an error if a MarkerClusterGroup is added to a map with no maxZoom. Fixes #189

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:01:01 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 74e1443bb041f49ec68db4e8e587511788ef7a57
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Jul 1 09:45:09 2013 +1200

    Throw an error if a MarkerClusterGroup is added to a map with no maxZoom. Fixes #189
---
 spec/index.html           |  1 +
 spec/suites/onAddSpec.js  | 37 +++++++++++++++++++++++++++++++++++++
 src/MarkerClusterGroup.js |  4 ++++
 3 files changed, 42 insertions(+)

diff --git a/spec/index.html b/spec/index.html
index f9a9418..035626f 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -40,6 +40,7 @@
 	<script type="text/javascript" src="suites/CircleMarkerSupportSpec.js"></script>
 	<script type="text/javascript" src="suites/CircleSupportSpec.js"></script>
 
+	<script type="text/javascript" src="suites/onAddSpec.js"></script>
 	<script type="text/javascript" src="suites/clearLayersSpec.js"></script>
 	<script type="text/javascript" src="suites/eachLayerSpec.js"></script>
 	<script type="text/javascript" src="suites/eventsSpec.js"></script>
diff --git a/spec/suites/onAddSpec.js b/spec/suites/onAddSpec.js
new file mode 100644
index 0000000..c0e8493
--- /dev/null
+++ b/spec/suites/onAddSpec.js
@@ -0,0 +1,37 @@
+describe('onAdd', 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);
+
+		map.fitBounds(new L.LatLngBounds([
+			[1, 1],
+			[2, 2]
+		]));
+	});
+	afterEach(function () {
+		document.body.removeChild(div);
+	});
+
+
+	it('throws an error if maxZoom is not specified', function () {
+
+		var group = new L.MarkerClusterGroup();
+		var marker = new L.Marker([1.5, 1.5]);
+
+		group.addLayer(marker);
+
+		var ex = null;
+		try {
+			map.addLayer(group);
+		} catch (e) {
+			ex = e;
+		}
+
+		expect(ex).to.not.be(null);
+	});
+});
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 80b0652..cc5a1b8 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -370,6 +370,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		this._map = map;
 		var i, l, layer;
 
+		if (!isFinite(this._map.getMaxZoom())) {
+			throw "Map has no maxZoom specified";
+		}
+
 		this._featureGroup.onAdd(map);
 		this._nonPointGroup.onAdd(map);
 

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