Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle edge case of empty bounds on _getBoundsCenterZoom #5157

Merged
merged 3 commits into from May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/suites/map/MapSpec.js
Expand Up @@ -833,6 +833,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)),
Expand Down
7 changes: 7 additions & 0 deletions src/map/Map.js
Expand Up @@ -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),
Expand Down