Round scale to avoid float rounding issues in fitBounds

Reverts _round() fix from b511c7bcc8.

Close #4395.
This commit is contained in:
Per Liedman 2016-04-06 22:58:00 +02:00 committed by Yohan Boniface
parent 8c9759aa2f
commit 36b60b7c88
2 changed files with 32 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -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) {