From 8188af202f3c58d0f22f01e9d28c51f0d021e6a8 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Tue, 19 Sep 2017 15:11:45 -0700 Subject: [PATCH] guard for offset edgecase in flyTo --- src/ui/camera.js | 2 +- test/unit/ui/camera.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/camera.js b/src/ui/camera.js index 227f09b3847..be14ef805a5 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -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); diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index ec655ff378d..2673ebbcf77 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -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) => {