Converting tracks without timestamps to routes during import.

This commit is contained in:
Eric van der Vlist 2022-12-13 15:17:50 +01:00
parent fdee3e8fcd
commit 3d2db84235
1 changed files with 34 additions and 0 deletions

View File

@ -202,6 +202,39 @@ const prune = (
// return extensions;
// };
const hasMissingTimestamps = (trk: Trk) => {
for (const trkseg of trk.trkseg!) {
for (const trkpt of trkseg.trkpt!) {
if (trkpt.time === undefined) {
return true;
}
}
}
return false;
};
const convertTrkToRteWhenNeeded = (gpx: Gpx) => {
if (gpx.trk === undefined) {
return;
}
const newTrks: Trk[] = [];
for (const trk of gpx.trk) {
if (hasMissingTimestamps(trk)) {
const rte = { ...trk, trkseg: undefined, rtept: [] };
for (const trkseg of trk.trkseg!) {
rte.rtept = rte.rtept.concat(trkseg.trkpt);
}
if (gpx.rte === undefined) {
gpx.rte = [];
}
gpx.rte.push(rte);
} else {
newTrks.push(trk);
}
}
gpx.trk = newTrks;
};
export const pruneAndSaveImportedGpx = async (params: any) => {
console.log({ caller: 'pruneAndSaveImportedGpx', params });
const { id, gpx, tech } = params;
@ -216,6 +249,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
extensions: gpx.extensions,
},
};
convertTrkToRteWhenNeeded(gpx);
let previousGpx: Gpx | null = null;
if (id === 'new') {
const currentDateTime = new Date().toISOString();