From 2b5c1b64daaa4909e18662a4de565875f612d9ee Mon Sep 17 00:00:00 2001 From: Benoit Perrin Date: Tue, 4 Sep 2018 12:30:23 +0200 Subject: [PATCH] Fix flyTo when the final zoom value is not the requested one (#7222) (#7223) * Fix flyTo when final zoom is not requested one (#7222) This complete the fix for #6828 when the final zoom value is different from the zoom requested. * Fix final center position and add test case. --- src/ui/camera.js | 2 +- test/unit/ui/camera.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ui/camera.js b/src/ui/camera.js index 34c4f690534..1eab666d988 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -832,7 +832,7 @@ class Camera extends Evented { tr.pitch = interpolate(startPitch, pitch, k); } - const newCenter = tr.unproject(from.add(delta.mult(u(s))).mult(scale)); + const newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(scale)); tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset); this._fireMoveEvents(eventData); diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index d8b352cc7de..b6970bf3f28 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -919,6 +919,24 @@ test('camera', (t) => { t.end(); }); + t.test('Zoom out from the same position to the same position with animation', (t) => { + const pos = { lng: 0, lat: 0 }; + const camera = createCamera({zoom: 20, center: pos}); + const stub = t.stub(browser, 'now'); + + camera.once('zoomend', () => { + t.deepEqual(fixedLngLat(camera.getCenter()), fixedLngLat(pos)); + t.equal(camera.getZoom(), 19); + t.end(); + }); + + stub.callsFake(() => 0); + camera.flyTo({ zoom: 19, center: pos, duration: 2 }); + + stub.callsFake(() => 3); + camera.simulateFrame(); + }); + t.test('rotates to specified bearing', (t) => { const camera = createCamera(); camera.flyTo({ bearing: 90, animate: false });