diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 953cced9..650e4ad1 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -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'; @@ -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 () { diff --git a/src/map/Map.js b/src/map/Map.js index 8b6ba24e..99c1214d 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -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) {