Timing issue with fitBounds and map.on

8 views
Skip to first unread message

Frank Poppe

unread,
Apr 5, 2025, 12:55:55 PMApr 5
to Leaflet
Hi,
I notice some timing issue which I cannot find a reference to. The situation is this.
  • I have a trigger on the moveend event.
  • There are markers that, when clicked, show new markers detailing the situation around that marker; and a fitBounds event is executed on that new group of markers.
  • As this would generate the moveEnd event, while I don't want to activate that during that action, I do a map.off on the event call before the fitBounds, and a map.on after it.
But it appears that the moveend action is already activated before the fitBounds finishes, so it fires.
If I encapsulate the map.on in a setTimeout function I get the behaviour I want. A timeout of about 300 ms seems to be needed, but that might be heavily dependent on hardware or number of markers.

Is there any better method than this kludge?
Reply all
Reply to author
Forward
0 new messages