diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 47561db7..0eba96c1 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -822,6 +822,36 @@ describe("Map", function () { }); map.fitBounds(bounds, {animate: false}); }); + + it('Fits to small bounds from small zoom', function (done) { + map.once('zoomend', function () { + map.once('zoomend', function () { + expect(map.getZoom()).to.eql(11); + expect(map.getCenter().equals(boundsCenter, 0.05)).to.eql(true); + done(); + }); + map.fitBounds(bounds); + }); + + bounds = L.latLngBounds([57.73, 11.93], [57.75, 11.95]); + boundsCenter = bounds.getCenter(); + map.setZoom(0); + }); + + it('Fits to large bounds from large zoom', function (done) { + map.once('zoomend', function () { + map.once('zoomend', function () { + expect(map.getZoom()).to.eql(0); + expect(map.getCenter().equals(boundsCenter, 0.05)).to.eql(true); + done(); + }); + map.fitBounds(bounds); + }); + + bounds = L.latLngBounds([90, -180], [-90, 180]); + boundsCenter = bounds.getCenter(); + map.setZoom(22); + }); }); diff --git a/src/map/Map.js b/src/map/Map.js index 89fd308a..9f1ad214 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -514,10 +514,11 @@ L.Map = L.Evented.extend({ nw = bounds.getNorthWest(), se = bounds.getSouthEast(), size = this.getSize(), - boundsSize = this.project(se, zoom).subtract(this.project(nw, zoom)).add(padding)._round(), + boundsSize = this.project(se, zoom).subtract(this.project(nw, zoom)).add(padding), snap = L.Browser.any3d ? this.options.zoomSnap : 1; var scale = Math.min(size.x / boundsSize.x, size.y / boundsSize.y); + scale = Math.round(scale * 1e9) / 1e9; zoom = this.getScaleZoom(scale, zoom); if (snap) {