Skip to content

Commit

Permalink
Fix flyTo when the final zoom value is not the requested one (mapbox#…
Browse files Browse the repository at this point in the history
…7222) (mapbox#7223)

* Fix flyTo when final zoom is not requested one (mapbox#7222)

This complete the fix for mapbox#6828 when the final zoom value is
different from the zoom requested.

* Fix final center position and add test case.
  • Loading branch information
benoitbzl authored and pirxpilot committed Jun 15, 2019
1 parent cf88c31 commit 0fcb522
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 0fcb522

Please sign in to comment.