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

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

* Added test for inside param of L.Map.getBoundsZoom()
This commit is contained in:
Iván Sánchez Ortega 2017-02-02 16:21:10 +01:00 committed by GitHub
parent 14c5f1602c
commit ddc3a9ca61
2 changed files with 13 additions and 2 deletions

View File

@ -178,6 +178,7 @@ describe("Map", function () {
describe("#getBoundsZoom", function () { describe("#getBoundsZoom", function () {
var halfLength = 0.00025; var halfLength = 0.00025;
var bounds = [[-halfLength, -halfLength], [halfLength, halfLength]]; var bounds = [[-halfLength, -halfLength], [halfLength, halfLength]];
var wideBounds = [[-halfLength, -halfLength * 10], [halfLength, halfLength * 10]];
var padding = [100, 100]; var padding = [100, 100];
var height = '400px'; var height = '400px';
@ -219,6 +220,14 @@ describe("Map", function () {
map.setZoom(16); map.setZoom(16);
expect(map.getBoundsZoom(bounds, false, padding)).to.eql(9); 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 () { describe('#setMaxBounds', function () {

View File

@ -806,9 +806,11 @@ export var Map = Evented.extend({
se = bounds.getSouthEast(), se = bounds.getSouthEast(),
size = this.getSize().subtract(padding), size = this.getSize().subtract(padding),
boundsSize = toBounds(this.project(se, zoom), this.project(nw, zoom)).getSize(), 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); zoom = this.getScaleZoom(scale, zoom);
if (snap) { if (snap) {