From 0fcb522fd4fa5714ec0eac6c9f50054ac387cf96 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 a8e8714dd5f..90c6a5c2898 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 d0086688b54..be25acabea4 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -912,6 +912,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 });