-
Notifications
You must be signed in to change notification settings - Fork 84
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
{{track_info}} not always correctly build #283
Comments
Hi @CoppensD, If you some have time to investigate as explained in there #241 (and there #253) otherwise just think differently, eg: _waitFor(() => undefined !== controlElevation?.track_info?.distance).then(() => console.log(controlElevation.track_info)); /**
* Function to wait for predicates.
*
* @param { () => Boolean } predicate - A function that returns a bool
* @param { number } [timeout] - Optional maximum waiting time in ms after rejected
*
* @see https://gist.github.com/chrisjhoughton/7890239?permalink_comment_id=4411125#gistcomment-4411125
*/
function _waitFor(predicate, timeout) {
return new Promise((resolve, reject) => {
const check = () => {
if (!predicate()) return;
clearInterval(interval);
resolve();
};
const interval = setInterval(check, 100);
check();
if (timeout) {
setTimeout(() => { clearInterval(interval); reject(); }, timeout);
}
});
} 👋 Raruto |
I already worked with I digged a bit further and noticed that I also noticed that my controlElevation.on("eledata_added", function(e){
console.log(e);
console.log("added");
})
controlElevation.on("eledata_loaded", ({ layer, name, track_info }) => {
console.log(track_info); // only name visible
console.log(track_info.distance); // undefined --> only when eledata_added is outputting after eledata_loaded
});
controlElevation.load(gpxFile); |
For me this solved by adding my custom summary in the |
As I have already pointed out in other issues, this is most likely a problem related to a misbehave of the internal "homemade" dependencies lazy loader: leaflet-elevation/src/control.js Lines 809 to 810 in bd9316b
leaflet-elevation/src/control.js Lines 480 to 481 in bd9316b
When loading them statically, in the usual HTML way (eg. Otherwise, please try to look at the code and propose your own solution. 👋 Raruto |
Not sure if this is the best solution but I added the same lines from leaflet-elevation/src/control.js Lines 32 to 44 in bd9316b
the lines I added between lines 38 and 39 if (this._data.length) {
this._start.setLatLng(this._data[0].latlng);
this._end.setLatLng(this._data[this._data.length - 1].latlng);
} |
Checklist
Subject of the issue
Like described in #241 when using a custom summary the track_info is not always displayed.
The default summary is always correct and shown.
But when you want to access the
{{track_info}}
object it's sometimes incomplete.In console.log I get this for the track_info
After a few refreshes I get
and then I show the correct data for the track_info
My code is created as described in the demo for custom summary or #241
Steps to reproduce
https://raruto.github.io/leaflet-elevation/examples/leaflet-elevation_custom-summary.html
did quite a few refreshes and suddenly I get no info
0
Environment
Windows 11 - Chrome version 120.0.6099.224
Link to your project
No response
Additional info
No response
The text was updated successfully, but these errors were encountered: