Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In leaflet/mapbox, why can't I set the duration of `map.fitBounds`?

I tried this:

map.fitBounds(L.polyline([L.latLng(40,9), L.latLng(1,2)]).getBounds(), {
  padding: [50, 50],
  maxZoom: 17,
  animate: true,
  duration: 10
});

I expect the animation to take 10 seconds to complete, but it completes very fast.. Does anyone have ideas about how to make the duration longer for fitBounds?

like image 457
Hanfei Sun Avatar asked Sep 17 '25 09:09

Hanfei Sun


1 Answers

It should be set as:

map.fitBounds(bounds, {
    padding: [50, 50],
    maxZoom: 18,
    animate: true,
    pan: {
        duration: 10
    }
});
like image 116
Jonatas Walker Avatar answered Sep 19 '25 07:09

Jonatas Walker