Leaflet: Feature: add callback for animations

Created on 20 Feb 2017  路  7Comments  路  Source: Leaflet/Leaflet

Hello,
I'm using version 1.0.3

You can't set the boundary and use an animation at the same time, like this:

This.map.flyToBounds (myBounds) This.map.setMaxBounds (myBounds)
Exemple : http://playground-leaflet.rhcloud.com/yeya/1/edit

One solution is by adding "moveend" listener who will launch setMaxBounds once the animation finishes, but it's complicated and we must filter events.

Why not add a "end of the animation" callback function in parameters ?

Most helpful comment

It doesn't look like the linked example provides any useful information, am I missing something?

You could add a one-time moveend listener specifically for your flyTo animation:

map.flyToBounds(bounds);
map.once('moveend', function() {
    map.setMaxBounds(bounds);
});

All 7 comments

It doesn't look like the linked example provides any useful information, am I missing something?

You could add a one-time moveend listener specifically for your flyTo animation:

map.flyToBounds(bounds);
map.once('moveend', function() {
    map.setMaxBounds(bounds);
});

I think you aremissing somthing, look at the javascript tab.
Thanks for "once", it work.

There is a problem.
If the move of the map is automatic, by "flyTo" method and if we stop via a drag with mouse, event is not called.

Ok, could you provide an illustration of the issue?

I modified your previous example with a once('moveend'), and it works as I would expect if I pan the map in the middle of the fly to: the map's max bounds are correctly set and the map is locked around Paris: http://playground-leaflet.rhcloud.com/xih/edit?html,js,output

Ok, I've updated the example.
Now at the end of the movement, a marker is added to the center of Paris.

http://playground-leaflet.rhcloud.com/xiwi/1/edit?html,js,output

In some cases, when moving is stopped, the marker appears a little later (probably corresponding to the end of automatic movement).

In the other, it does not appear at all.
It appear if new moving on of the map.

I was able to reproduce this problem by just clicking (not dragging) the map while the flyTo animation was running.

My guess is that the click aborts the animation since the user begins a pan operation, but since the map is actually never dragged, no moveEnd event is fired. I would consider this a bug, so we will have to investigate further.

Ok,
Good news.

I repeat, sometimes the event is still launched.
Test clicking at the end of the movement to stop the map.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CallMarl picture CallMarl  路  3Comments

viswaug picture viswaug  路  4Comments

zdila picture zdila  路  3Comments

walterfn2 picture walterfn2  路  4Comments

remilev picture remilev  路  4Comments