Skip to content

Commit

Permalink
guard for offset edgecase in flyTo
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Sep 19, 2017
1 parent 244d1e7 commit 8188af2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/camera.js
Expand Up @@ -785,7 +785,7 @@ class Camera extends Evented {
let S = (r(1) - r0) / rho;

// When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
if (Math.abs(u1) < 0.000001 || isNaN(S)) {
if (Math.abs(u1) < 0.000001 || isNaN(S) || S === Infinity) {
// Perform a more or less instantaneous transition if the path is too short.
if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options, eventData);

Expand Down
7 changes: 7 additions & 0 deletions test/unit/ui/camera.test.js
Expand Up @@ -788,7 +788,14 @@ test('camera', (t) => {
const camera = createCamera({zoom: 22, center:[0, 0]});
t.doesNotThrow(()=>camera.flyTo({zoom:10, center:[0, 0]}));
t.end();
});

t.test('does not throw when cameras current zoom is above maxzoom and an offset creates infinite zoom out factor', (t)=>{
const transform = new Transform(0, 20.9999, true);
transform.resize(512, 512);
const camera = new Camera(transform, {}).jumpTo({zoom: 21, center:[0, 0]});
t.doesNotThrow(()=>camera.flyTo({zoom:7.5, center:[0, 0], offset:[0, 70]}));
t.end();
});

t.test('zooms to specified level', (t) => {
Expand Down

0 comments on commit 8188af2

Please sign in to comment.