Skip to content

Commit

Permalink
Fix max/min calculation for getBoundsZoom (fixes Leaflet#5136) (Leafl…
Browse files Browse the repository at this point in the history
…et#5137)

* Fix max/min calculation for getBoundsZoom (fixes Leaflet#5136)

* Added test for inside param of L.Map.getBoundsZoom()
  • Loading branch information
IvanSanchez authored Feb 2, 2017
1 parent 14c5f16 commit ddc3a9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions spec/suites/map/MapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe("Map", function () {
describe("#getBoundsZoom", function () {
var halfLength = 0.00025;
var bounds = [[-halfLength, -halfLength], [halfLength, halfLength]];
var wideBounds = [[-halfLength, -halfLength * 10], [halfLength, halfLength * 10]];
var padding = [100, 100];
var height = '400px';

Expand Down Expand Up @@ -219,6 +220,14 @@ describe("Map", function () {
map.setZoom(16);
expect(map.getBoundsZoom(bounds, false, padding)).to.eql(9);
});

it("respects the 'inside' parameter", function () {
var container = map.getContainer();
container.style.height = height;
document.body.appendChild(container);
expect(map.getBoundsZoom(wideBounds, false, padding)).to.be.equal(17);
expect(map.getBoundsZoom(wideBounds, true, padding)).to.be.equal(20);
});
});

describe('#setMaxBounds', function () {
Expand Down
6 changes: 4 additions & 2 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,11 @@ export var Map = Evented.extend({
se = bounds.getSouthEast(),
size = this.getSize().subtract(padding),
boundsSize = toBounds(this.project(se, zoom), this.project(nw, zoom)).getSize(),
snap = Browser.any3d ? this.options.zoomSnap : 1;
snap = Browser.any3d ? this.options.zoomSnap : 1,
scalex = size.x / boundsSize.x,
scaley = size.y / boundsSize.y,
scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley);

var scale = Math.min(size.x / boundsSize.x, size.y / boundsSize.y);
zoom = this.getScaleZoom(scale, zoom);

if (snap) {
Expand Down

0 comments on commit ddc3a9c

Please sign in to comment.