EfficiencyJunky / BikeLapse

A webapp built with leaflet.js and mapbox meant to make it easy to catalog bike rides that have been recorded with the DistanceLapse Video Creation System and Strava
4 stars 0 forks source link

Fix bug where only half of the XML nodes are added when combining GPX files #24

Closed EfficiencyJunky closed 4 years ago

EfficiencyJunky commented 4 years ago

When combining GPX (XML) files together, only every other node from each subsequent file is being added for some reason.

EfficiencyJunky commented 4 years ago

Turns out, I needed to use "cloneNode()" on each "trkpt" node I was adding to the original file.

Simply doing this caused the issue:

trkseg.appendChild(trkpts[j]);

Needed to CLONE the trkpts[j] element before appending it. so changed the code to this:

// use the cloneNode() function to clone the node and set the "deep" parameter to true
// setting deep to true means it will do a full clone of the node AND its descendants (child nodes)
let trkpt = trkpts[j].cloneNode(deep = true);

// append the cloned node to the trkseg array
trkseg.appendChild(trkpt);
EfficiencyJunky commented 4 years ago

resolved in commit: https://github.com/EfficiencyJunky/BikeLapse/commit/2e2f0911adaa19726c6cfe8cee67dc4b361d75e0