-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load event may get lost #24
Comments
Very good points. Overloading I guess another solution is to overload |
Maybe we should look at the behaviour of some existing layer classes within leaflet which also do asynchronous loading. I can think of the tile layers only at the moment, and these definitely only start loading once you add them to a map. |
Don't forget that JS is single threaded. On Load event cannot be processed until your code returns to event loop. Therefore the code is completely fine. |
The example code of the readme is:
To me this looks like a race condition. If the constructor of L.GPX can load its data fast enough then the "loaded" event may get fired before the event handler is attached via
on(..)
. I think you somehow try to work around that for the case when the XML is directly handed over (which would make it a blocking operation) by usingsetTimeout(..)
without a delay value. But still, this doesn't solve the fundamental problem.A possible way to solve this problem is to delay the loading until the object gets added to the map. This can be done by overloading the
onAdd(map)
method of the class and doing the loading there, essentially callingthis._parse(gpx, options, this.options.async)
, and probably inside _parse calling the onAdd method of the parent class when done loading.The text was updated successfully, but these errors were encountered: