From 8d15a00b81d4e59b66d07d91025422b85bafb90c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 6 Nov 2016 14:55:53 -0700 Subject: [PATCH] Add a tour to the animation example --- examples/animation.html | 3 ++- examples/animation.js | 52 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/examples/animation.html b/examples/animation.html index 966b88f68f..54fa0cd014 100644 --- a/examples/animation.html +++ b/examples/animation.html @@ -10,9 +10,10 @@ tags: "animation"
- + + diff --git a/examples/animation.js b/examples/animation.js index 39a39dd939..6765e4ee38 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -110,17 +110,57 @@ onClick('spin-to-rome', function() { }); }); -onClick('fly-to-bern', function() { +function flyTo(location, done) { var duration = 2000; + var zoom = view.getZoom(); + var parts = 2; + var called = false; + function callback(complete) { + --parts; + if (called) { + return; + } + if (parts === 0 || !complete) { + called = true; + done(complete); + } + } view.animate({ - center: bern, + center: location, duration: duration - }); + }, callback); view.animate({ - zoom: view.getZoom() - 0.5, + zoom: zoom - 1, duration: duration / 2 }, { - zoom: view.getZoom() + 1, + zoom: zoom, duration: duration / 2 - }); + }, callback); +} + +onClick('fly-to-bern', function() { + flyTo(bern, function() {}); }); + +function tour() { + var locations = [london, bern, rome, moscow, istanbul]; + var index = -1; + function next(more) { + if (more) { + ++index; + if (index < locations.length) { + var delay = index === 0 ? 0 : 750; + setTimeout(function() { + flyTo(locations[index], next); + }, delay); + } else { + alert('Tour complete'); + } + } else { + alert('Tour cancelled'); + } + } + next(true); +} + +onClick('tour', tour);