Throw an error if a MarkerClusterGroup is added to a map with no maxZoom. Fixes #189

This commit is contained in:
danzel
2013-07-01 09:45:09 +12:00
parent 768cb5b533
commit 74e1443bb0
3 changed files with 42 additions and 0 deletions
+1
View File
@@ -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>
+37
View File
@@ -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);
});
});
+4
View File
@@ -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);