I have two types of searches for putting markers on a map. One search fires based on a search query from an input form and the other fires on the moveend
event (i.e. "redo search on map movement"). The resultant data is not the same; the former uses a radius and the latter limits to within the bounds).
The issue is that with the query based search, I would like to fit the map to the markers returned. So, I use fitBounds()
for this which delegates internally and animates a pan to the best bounds around the markers.
At the end of the animation it fires a moveend
event firing off my other type of search and resetting my results, which is the behavior I do not want.
In order to work around the problem, I can use setTimeout
and a known duration for the panning options on fitBounds()
. With this, I can turn my event listener on moveend
off, then fitBounds
which takes .25 seconds, then setTimeout
for .25 seconds (in practice, a little longer) with a callback to add the moveend
listener back.
This works but it would be more practical if fitBounds or panning had an event or callback itself. Can you think of a better solution?
You can use moveend + zoomend events to catch end of map fitting.
Because at least one of them called in the end of fitBounds
execution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With