Leaflet: Implement zoom/pan options in L.Map.flyTo()

Created on 22 Apr 2015  路  6Comments  路  Source: Leaflet/Leaflet

For API consistency, L.Map.flyTo() should take an options argument with the common pan/zoom options.

Also for API consistency, L.Map.flyTo() should return this.

(Also, make L.Map.flyToBounds() pass its options to L.Map.flyTo())

At least the options to not perform animations should be respected, and it would be nice to specify a custom animation time. I don't think there's an immediate need for the rest of the zoom/pan options.

Most helpful comment

If someone stumbles here some day, a duration key for the options object is implemented in https://github.com/Leaflet/Leaflet/blob/a54c2392389982dc618ba94b50ee8fbcb26f7949/src/map/anim/Map.FlyTo.js#L44

All 6 comments

Custom animation time isn't possible since flyTo calculates duration based on the distance it needs to travel. So there should be a different option controlling speed. But I agree it lacks an options argument.

Actually duration is quite trivial to implement and works without a hitch, see #3397. I agree that a speed option would be nice, but then flyTo() and fitBounds() would have different behaviours, which I think is a marginally bad idea.

Yeah, on a second look, this makes sense. Thanks!

On the other hand, a speed option makes sense, but should be implemented consistently across the board, both in flyTo() and in the animated panBy() and fitBounds(). I would give it a shot, but I don't have any idea what the units of the speed factor are.

If someone stumbles here some day, a duration key for the options object is implemented in https://github.com/Leaflet/Leaflet/blob/a54c2392389982dc618ba94b50ee8fbcb26f7949/src/map/anim/Map.FlyTo.js#L44

@almereyda

I was that guy who stumbled here some day. You are a god, good sir.

Here was my implementation:

map.flyTo([41, -96], 5, { duration: 0.8, })
Works great! The lower the number, the faster the speed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

walterfn2 picture walterfn2  路  4Comments

CallMarl picture CallMarl  路  3Comments

ssured picture ssured  路  3Comments

timwis picture timwis  路  3Comments

jblarsen picture jblarsen  路  3Comments