diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 650e4ad1..00841665 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -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)), diff --git a/src/map/Map.js b/src/map/Map.js index 8da16f3b..9ea70db0 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -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),