From 74e1443bb041f49ec68db4e8e587511788ef7a57 Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 1 Jul 2013 09:45:09 +1200 Subject: [PATCH] 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(+) create mode 100644 spec/suites/onAddSpec.js diff --git a/spec/index.html b/spec/index.html index f9a9418e8..035626fde 100644 --- a/spec/index.html +++ b/spec/index.html @@ -40,6 +40,7 @@ + diff --git a/spec/suites/onAddSpec.js b/spec/suites/onAddSpec.js new file mode 100644 index 000000000..c0e8493b5 --- /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 80b06528b..cc5a1b894 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);