-
Notifications
You must be signed in to change notification settings - Fork 124
Description
The example code of the readme is:
new L.GPX(gpx, {async: true}).on('loaded', function(e) {
map.fitBounds(e.target.getBounds());
}).addTo(map);
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 using setTimeout(..)
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 calling this._parse(gpx, options, this.options.async)
, and probably inside _parse calling the onAdd method of the parent class when done loading.