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:
parent
f677f9c6d2
commit
873d4cab31
@ -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 () {
|
||||
var center = L.latLng(50.5, 30.51),
|
||||
bounds = L.latLngBounds(L.latLng(1, 102), L.latLng(11, 122)),
|
||||
|
@ -255,6 +255,13 @@ export var Map = Evented.extend({
|
||||
|
||||
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),
|
||||
|
||||
swPoint = this.project(bounds.getSouthWest(), zoom),
|
||||
|
Loading…
Reference in New Issue
Block a user