Skip to content

Conversation

@Raruto
Copy link
Owner

@Raruto Raruto commented Apr 28, 2023

Subject of the issue

Calling load() and on('eledata_loaded') sequentially does not ensure that all src/handlers files are downloaded at callback execution time, that is:

// waits until 'foo.gpx' is downloaded
controlElevation.on('eledata_loaded', ({track_info}) => console.log(track_info.distance)); // NB implicit dynamic import('src/handlers/distance.js')

// fetch 'foo.gpx'
controlElevation.load('foo.gpx'); 

Solution adopted

Refactor _loadLayer() function, in order to wait until this._modulesLoaded == true before triggering "eledata_loaded" event, that is:

const event_data = { data: geojson, layer: layer, name: this.track_info.name, track_info: this.track_info };

if (this._modulesLoaded) {
  this._fireEvt("eledata_loaded", event_data);
} else {
  this.once('modules_loaded', () => this._fireEvt("eledata_loaded", event_data));
}

Closes: #241

@Raruto Raruto changed the title Fix undefined track_info data within "eledata_loaded" event Fix undefined track_info data within "eledata_loaded" event Apr 28, 2023
@Raruto
Copy link
Owner Author

Raruto commented Apr 28, 2023

@haldo98 let me know what you think about it

@haldo98
Copy link

haldo98 commented Apr 29, 2023

I'll give it a try....

Thank U

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

track_info.distance is undefined within "eledata_loaded" event

3 participants