diff --git a/src/ui/camera.js b/src/ui/camera.js index 5987a8312c5..a1282c6c443 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -852,7 +852,7 @@ class Camera extends Evented { // s: The distance traveled along the flight path, measured in ρ-screenfuls. const s = k * S; const scale = 1 / w(s); - tr.zoom = startZoom + tr.scaleZoom(scale); + tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(scale); if (this._rotating) { tr.bearing = interpolate(startBearing, bearing, k); diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index 161a6aed921..6d918d4378e 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -912,6 +912,13 @@ test('camera', (t) => { t.end(); }); + t.test('zooms to integer level without floating point errors', (t) => { + const camera = createCamera({zoom: 0.6}); + camera.flyTo({ zoom: 2, animate: false }); + t.equal(camera.getZoom(), 2); + t.end(); + }); + t.test('rotates to specified bearing', (t) => { const camera = createCamera(); camera.flyTo({ bearing: 90, animate: false });