Round scale to avoid float rounding issues in fitBounds
Reverts _round() fix from b511c7bcc8
.
Close #4395.
This commit is contained in:
parent
8c9759aa2f
commit
36b60b7c88
@ -822,6 +822,36 @@ describe("Map", function () {
|
|||||||
});
|
});
|
||||||
map.fitBounds(bounds, {animate: false});
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -514,10 +514,11 @@ L.Map = L.Evented.extend({
|
|||||||
nw = bounds.getNorthWest(),
|
nw = bounds.getNorthWest(),
|
||||||
se = bounds.getSouthEast(),
|
se = bounds.getSouthEast(),
|
||||||
size = this.getSize(),
|
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;
|
snap = L.Browser.any3d ? this.options.zoomSnap : 1;
|
||||||
|
|
||||||
var scale = Math.min(size.x / boundsSize.x, size.y / boundsSize.y);
|
var scale = Math.min(size.x / boundsSize.x, size.y / boundsSize.y);
|
||||||
|
scale = Math.round(scale * 1e9) / 1e9;
|
||||||
zoom = this.getScaleZoom(scale, zoom);
|
zoom = this.getScaleZoom(scale, zoom);
|
||||||
|
|
||||||
if (snap) {
|
if (snap) {
|
||||||
|
Loading…
Reference in New Issue
Block a user