Skip to content
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

Fix undefined track_info data within "eledata_loaded" event #253

Merged
merged 1 commit into from
May 16, 2023
Merged

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
2 participants