Skip to content

Load event may get lost #24

@letmaik

Description

@letmaik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions