jieter / Leaflet.Sync

Synchronized view of two maps.
http://jieter.github.io/Leaflet.Sync/examples/dual.html
BSD 3-Clause "New" or "Revised" License
235 stars 53 forks source link

Fire moveend event on synced map when drag finishes #35

Closed Thuranel closed 7 years ago

Thuranel commented 7 years ago

This pull request is for issue #34.

This PR changes the following: When dragging the map, the 'move' event is called instead of 'moveend'. On dragend, the 'moveend' event is called on the synced maps.

These changes make it so the appropriate event is called. Before these changes 'moveend' was called on every single move. Therefore, not when the move ended like the event says. Here's a fiddle showing the issue: https://jsfiddle.net/Thuranel/zmp3qfqe/

Now, the 'moveend' event is only called at the end of dragging and the 'move' event is called while dragging the map. This keep the usual behavior while firing the appropriate events. Here's a fiddle showing the behavior with this PR: https://jsfiddle.net/Thuranel/gmjcom01/

jieter commented 7 years ago

@Thuranel Great, looks good.

Did you try to add a test for this?

Thuranel commented 7 years ago

Here you go!

There is probably one test missing to make sure that the 'move' event is called on every single tick of dragging, but I've been looking at it all morning and it doesn't seem possible to simulate multiple ticks with phantomjs because everything happens all at once. My understanding is that since there is no delay between the drag and the drop the _updatePosition function is only called once. Also, if you try to make a timeout between the drag and the drop or before asserting, it seems that the test framework doesn't wait for everything to finish before arriving at the end of the test and claiming the test passed (because the assert has not been run yet). If there was a way to wait for one frame we could probably make a test to see if the event is fired more than once.

Until then, that's the best I got. The basic behavior is tested and should be good.

jieter commented 7 years ago

great, thanks for the effort. Every test is better than nothing!

jieter commented 7 years ago

released leaflet.sync@0.0.7