Adding a button to force importing tracks as routes

This commit is contained in:
Eric van der Vlist 2023-04-15 20:24:35 +02:00
parent 856cd7637e
commit f17cc2e073
2 changed files with 14 additions and 6 deletions

View File

@ -150,7 +150,7 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
);
}
}
const doImport = async () => {
const doImport = async (forceImportAsRoutes: boolean = false) => {
setState('importing');
// console.log({ caller: 'GpxImport / JSON', file, gpx });
// if (gpx) {
@ -159,6 +159,7 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
action: 'pruneAndSaveImportedGpx',
params: {
id: gpxId(),
forceImportAsRoutes,
gpx: statsAndGpx()?.gpx,
tech:
typeof file === 'string'
@ -244,10 +245,17 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
<Button
variant='contained'
disabled={state() != 'init'}
onClick={doImport}
onClick={() => doImport(false)}
>
{t('import')}
</Button>
<Button
variant='contained'
disabled={state() != 'init'}
onClick={() => doImport(true)}
>
{t('importAllTrksAsRtes')}
</Button>
</CardActions>
</Show>
<Show when={picture() !== undefined}>

View File

@ -150,13 +150,13 @@ const hasMissingTimestamps = (trk: Trk) => {
return false;
};
const convertTrkToRteWhenNeeded = (gpx: Gpx) => {
const convertTrkToRteWhenNeeded = (gpx: Gpx, forceImportAsRoutes: boolean) => {
if (gpx.trk === undefined) {
return;
}
const newTrks: Trk[] = [];
for (const trk of gpx.trk) {
if (hasMissingTimestamps(trk)) {
if (forceImportAsRoutes || hasMissingTimestamps(trk)) {
const rte = { ...trk, trkseg: undefined, rtept: [] };
for (const trkseg of trk.trkseg!) {
rte.rtept = rte.rtept.concat(trkseg.trkpt);
@ -174,7 +174,7 @@ const convertTrkToRteWhenNeeded = (gpx: Gpx) => {
export const pruneAndSaveImportedGpx = async (params: any) => {
console.log({ caller: 'pruneAndSaveImportedGpx', params });
const { id, gpx, tech } = params;
const { id, gpx, tech, forceImportAsRoutes } = params;
let gpxId: IdGpx;
let docs: any[] = [];
const extensions = {
@ -186,7 +186,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
extensions: gpx.extensions,
},
};
convertTrkToRteWhenNeeded(gpx);
convertTrkToRteWhenNeeded(gpx, forceImportAsRoutes);
let previousGpx: Gpx | null = null;
let to: string[];
if (id === 'new') {