From 5a0facc8ac77ef959914f09abd9d58e265e3f6da Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Mon, 25 Sep 2017 19:50:45 +0300 Subject: [PATCH 1/6] limit animation duration on flyTo with maxDuration option --- src/ui/camera.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui/camera.js b/src/ui/camera.js index 1bb0c03b9d4..2be54cbb351 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -803,6 +803,10 @@ class Camera extends Evented { options.duration = 1000 * S / V; } + if (options.maxDuration) { + options.duration = Math.min(options.duration, options.maxDuration); + } + this.zooming = true; this.rotating = (startBearing !== bearing); this.pitching = (pitch !== startPitch); From 3886d8244930341f2684cfecb9ab8937d8b7d228 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Mon, 25 Sep 2017 22:17:30 +0300 Subject: [PATCH 2/6] add maxDuration description --- src/ui/camera.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/camera.js b/src/ui/camera.js index 2be54cbb351..b0471ff4c6c 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -665,6 +665,7 @@ class Camera extends Evented { * It does not correspond to a fixed physical distance, but varies by zoom level. * @param {number} [options.screenSpeed] The average speed of the animation measured in screenfuls * per second, assuming a linear timing curve. If `options.speed` is specified, this option is ignored. + * @param {number} [options.maxDuration] The animation's maximum duration, measured in milliseconds. * @param eventData Additional properties to be added to event objects of events triggered by this method. * @fires movestart * @fires zoomstart From c0197801fa07fc0ed86ab2114c0aaf008086eab0 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Mon, 25 Sep 2017 22:32:32 +0300 Subject: [PATCH 3/6] set the duration to 0 if flyTo duration exceeds maxDuration --- src/ui/camera.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/camera.js b/src/ui/camera.js index b0471ff4c6c..5cbcfaa9062 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -804,8 +804,8 @@ class Camera extends Evented { options.duration = 1000 * S / V; } - if (options.maxDuration) { - options.duration = Math.min(options.duration, options.maxDuration); + if (options.maxDuration && options.duration > options.maxDuration) { + options.duration = 0; } this.zooming = true; From 4100e87702cf842598fda590f856168617b9874c Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Tue, 26 Sep 2017 12:07:15 +0300 Subject: [PATCH 4/6] clarify flyTo maxDuration option description --- src/ui/camera.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/camera.js b/src/ui/camera.js index 5cbcfaa9062..318c6cdcfb6 100644 --- a/src/ui/camera.js +++ b/src/ui/camera.js @@ -666,6 +666,7 @@ class Camera extends Evented { * @param {number} [options.screenSpeed] The average speed of the animation measured in screenfuls * per second, assuming a linear timing curve. If `options.speed` is specified, this option is ignored. * @param {number} [options.maxDuration] The animation's maximum duration, measured in milliseconds. + * If duration exceeds maximum duration, it resets to 0. * @param eventData Additional properties to be added to event objects of events triggered by this method. * @fires movestart * @fires zoomstart From f941090b4a8b05b03d38b588c69ef8a5d4d7fb6c Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Wed, 27 Sep 2017 22:07:41 +0300 Subject: [PATCH 5/6] add flyTo maxDuration option test --- test/unit/ui/camera.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index 2673ebbcf77..e848e6e58ca 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -1201,6 +1201,22 @@ test('camera', (t) => { camera.flyTo(flyOptions); }); + t.test('resets duration to 0 if it exceeds maxDuration', (t) => { + let startTime, endTime, timeDiff; + const camera = createCamera({ center: [37.63454, 55.75868], zoom: 18}); + + camera + .on('movestart', () => { startTime = new Date(); }) + .on('moveend', () => { + endTime = new Date(); + timeDiff = endTime - startTime; + t.equalWithPrecision(timeDiff, 0, 1e-6); + t.end(); + }); + + camera.flyTo({ center: [-122.3998631, 37.7884307], maxDuration: 100 }); + }); + t.end(); }); From ed8fdc4d8b14f6fb543d2f07ff310e5e3047c056 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Wed, 27 Sep 2017 22:53:44 +0300 Subject: [PATCH 6/6] decrease flyTo maxDuration option test precision --- test/unit/ui/camera.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index e848e6e58ca..48667e605bc 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -1210,7 +1210,7 @@ test('camera', (t) => { .on('moveend', () => { endTime = new Date(); timeDiff = endTime - startTime; - t.equalWithPrecision(timeDiff, 0, 1e-6); + t.equalWithPrecision(timeDiff, 0, 1e+1); t.end(); });