Handle edge case of empty bounds on _getBoundsCenterZoom (#5157)

* Handle edge case of empty bounds on _getBoundsCenterZoom

* Unit test for map._getBoundsCenterZoom
This commit is contained in:
Iván Sánchez Ortega 2017-05-11 22:33:46 +02:00 committed by Per Liedman
parent f677f9c6d2
commit 873d4cab31
2 changed files with 18 additions and 0 deletions

View File

@ -842,6 +842,17 @@ describe("Map", function () {
}); });
}); });
describe('#_getBoundsCenterZoom', function () {
var center = L.latLng(50.5, 30.51);
it('Returns valid center on empty bounds in unitialized map', function () {
// Edge case from #5153
var centerAndZoom = map._getBoundsCenterZoom([center, center]);
expect(centerAndZoom.center).to.eql(center);
expect(centerAndZoom.zoom).to.eql(Infinity);
});
});
describe('#fitBounds', function () { describe('#fitBounds', function () {
var center = L.latLng(50.5, 30.51), var center = L.latLng(50.5, 30.51),
bounds = L.latLngBounds(L.latLng(1, 102), L.latLng(11, 122)), bounds = L.latLngBounds(L.latLng(1, 102), L.latLng(11, 122)),

View File

@ -255,6 +255,13 @@ export var Map = Evented.extend({
zoom = (typeof options.maxZoom === 'number') ? Math.min(options.maxZoom, zoom) : zoom; zoom = (typeof options.maxZoom === 'number') ? Math.min(options.maxZoom, zoom) : zoom;
if (zoom === Infinity) {
return {
center: bounds.getCenter(),
zoom: zoom
};
}
var paddingOffset = paddingBR.subtract(paddingTL).divideBy(2), var paddingOffset = paddingBR.subtract(paddingTL).divideBy(2),
swPoint = this.project(bounds.getSouthWest(), zoom), swPoint = this.project(bounds.getSouthWest(), zoom),