From c51412541fb6f48a373b8c338cdc6173c4700d68 Mon Sep 17 00:00:00 2001 From: Remek Zajac# Date: Tue, 28 Feb 2017 15:01:37 +0000 Subject: [PATCH] Fix #4337 eventData not passed during flyTo --- src/ui/camera.js | 2 +- test/unit/ui/camera.test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ui/camera.js b/src/ui/camera.js index c27de89f3e4..2797995003d 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -736,7 +736,7 @@ class Camera extends Evented { // When u₀ = u₁, the optimal path doesn’t require both ascent and descent. if (Math.abs(u1) < 0.000001) { // Perform a more or less instantaneous transition if the path is too short. - if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options); + if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options, eventData); const k = w1 < w0 ? -1 : 1; S = Math.abs(Math.log(w1 / w0)) / rho; diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index 97a5570c89c..c19369e8869 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -859,6 +859,41 @@ test('camera', (t) => { eventData); }); + t.test('for short flights, emits (solely) move events, preserving eventData', (t) => { + //As I type this, the code path for guiding super-short flights is (and will probably remain) different. + //As such; it deserves a separate test case. This test case flies the map from A to A. + const fromTo = { center: [100, 0] }; + const camera = createCamera(fromTo); + let movestarted, moved, rotated, pitched, zoomstarted, zoomed, zoomended; + const eventData = { data: 'ok' }; + + camera + .on('movestart', (d) => { movestarted = d.data; }) + .on('move', (d) => { moved = d.data; }) + .on('rotate', (d) => { rotated = d.data; }) + .on('pitch', (d) => { pitched = d.data; }) + .on('zoomstart', (d) => { zoomstarted = d.data; }) + .on('zoom', (d) => { zoomed = d.data; }) + .on('zoomend', (d) => { zoomended = d.data; }) + .on('moveend', function(d) { + t.notOk(this.zooming); + t.notOk(this.panning); + t.notOk(this.rotating); + + t.equal(movestarted, 'ok'); + t.equal(moved, 'ok'); + t.equal(zoomstarted, undefined); + t.equal(zoomed, undefined); + t.equal(zoomended, undefined); + t.equal(rotated, undefined); + t.equal(pitched, undefined); + t.equal(d.data, 'ok'); + t.end(); + }); + + camera.flyTo(fromTo, eventData); + }); + t.test('stops existing ease', (t) => { const camera = createCamera(); camera.flyTo({ center: [200, 0], duration: 100 });