Better sanity checks for avoiding loading infinite tiles (#5479)

* Sanity check to prevent loading tiles when bounds are `Infinity`

* Make linter happy

* Better sanity checks for avoiding loading infinite tiles

* typo
This commit is contained in:
Iván Sánchez Ortega 2017-04-25 15:00:47 +02:00 committed by Per Liedman
parent 6d6b07612e
commit 7e1740ecdf
2 changed files with 18 additions and 4 deletions

View File

@ -937,6 +937,20 @@ describe('GridLayer', function () {
});
});
describe("Sanity checks for infinity", function () {
it("Throws error on map center at plus Infinity longitude", function () {
expect(function () {
map.setCenter([Infinity, Infinity]);
L.gridLayer().addTo(map);
}).to.throwError('Attempted to load an infinite number of tiles');
});
it("Throws error on map center at minus Infinity longitude", function () {
expect(function () {
map.setCenter([-Infinity, -Infinity]);
L.gridLayer().addTo(map);
}).to.throwError('Attempted to load an infinite number of tiles');
});
});
});

View File

@ -632,10 +632,10 @@ export var GridLayer = Layer.extend({
tileRange.getTopRight().add([margin, -margin]));
// Sanity check: panic if the tile range contains Infinity somewhere.
if (tileRange.min.x === Infinity ||
tileRange.min.y === Infinity ||
tileRange.max.x === Infinity ||
tileRange.max.y === Infinity) { throw new Error('Attempted to load an infinite number of tiles'); }
if (!(isFinite(tileRange.min.x) &&
isFinite(tileRange.min.y) &&
isFinite(tileRange.max.x) &&
isFinite(tileRange.max.y))) { throw new Error('Attempted to load an infinite number of tiles'); }
for (var key in this._tiles) {
var c = this._tiles[key].coords;