From 15abd45a9bd77ba19dfb494c7dd9c921fd78a333 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Fri, 26 May 2017 19:47:01 +0200 Subject: [PATCH] fix thrown exception with certain calls to 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 f4e20536582..3003ea53562 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -758,7 +758,7 @@ class Camera extends Evented { S = (r(1) - r0) / rho; // When u₀ = u₁, the optimal path doesn’t require both ascent and descent. - if (Math.abs(u1) < 0.000001) { + if (Math.abs(u1) < 0.000001 || isNaN(S)) { // 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 b1483723949..30c35047797 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -784,6 +784,13 @@ test('camera', (t) => { t.end(); }); + t.test('does not throw when cameras current zoom is sufficiently greater than passed zoom option', (t)=>{ + const camera = createCamera({zoom: 22, center:[0,0]}); + t.doesNotThrow(()=>camera.flyTo({zoom:10, center:[0,0]})); + t.end(); + + }); + t.test('zooms to specified level', (t) => { const camera = createCamera(); camera.flyTo({ zoom: 3.2, animate: false });