This question already has an answer here:

I would like to do button like Fly to Bern button in the below link.

Is it possible to do ?


var flyToBern = document.getElementById('fly-to-bern');
flyToBern.addEventListener('click', function() {
  var duration = 2000;
  var start = +new Date();
  var pan = ol.animation.pan({
    duration: duration,
    source: /** @type {ol.Coordinate} */ (view.getCenter()),
    start: start
  var bounce = ol.animation.bounce({
    duration: duration,
    resolution: 4 * view.getResolution(),
    start: start
  map.beforeRender(pan, bounce);
}, false);

marked as duplicate by MappaGnosis, John Powell, PolyGeo Nov 12 '15 at 9:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


It is possible with Leaflet 1.0, but with a more simple API (you specify only target latlng and duration of the "flyTo" animation).

See Leaflet Fly To Location post for details.

However it does not do anything if you are already on the target position I think.

  • but I cannot just use flyTo.js. It will bring up a error. Unless I use v1.0.0-beta.2 version of leaflet. Do you have any example by using leaflet-0.7.2 version. – Hu Kenneth Nov 12 '15 at 10:47
  • Nope sorry, you need Leaflet 1.0 unfortunately. Or import the code yourself and debug whatever needs to. – ghybs Nov 12 '15 at 10:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.