Adding a button to force importing tracks as routes
This commit is contained in:
parent
856cd7637e
commit
f17cc2e073
|
@ -150,7 +150,7 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const doImport = async () => {
|
const doImport = async (forceImportAsRoutes: boolean = false) => {
|
||||||
setState('importing');
|
setState('importing');
|
||||||
// console.log({ caller: 'GpxImport / JSON', file, gpx });
|
// console.log({ caller: 'GpxImport / JSON', file, gpx });
|
||||||
// if (gpx) {
|
// if (gpx) {
|
||||||
|
@ -159,6 +159,7 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
|
||||||
action: 'pruneAndSaveImportedGpx',
|
action: 'pruneAndSaveImportedGpx',
|
||||||
params: {
|
params: {
|
||||||
id: gpxId(),
|
id: gpxId(),
|
||||||
|
forceImportAsRoutes,
|
||||||
gpx: statsAndGpx()?.gpx,
|
gpx: statsAndGpx()?.gpx,
|
||||||
tech:
|
tech:
|
||||||
typeof file === 'string'
|
typeof file === 'string'
|
||||||
|
@ -244,10 +245,17 @@ const ImportSingleFile: Component<Props> = ({ file: file }) => {
|
||||||
<Button
|
<Button
|
||||||
variant='contained'
|
variant='contained'
|
||||||
disabled={state() != 'init'}
|
disabled={state() != 'init'}
|
||||||
onClick={doImport}
|
onClick={() => doImport(false)}
|
||||||
>
|
>
|
||||||
{t('import')}
|
{t('import')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant='contained'
|
||||||
|
disabled={state() != 'init'}
|
||||||
|
onClick={() => doImport(true)}
|
||||||
|
>
|
||||||
|
{t('importAllTrksAsRtes')}
|
||||||
|
</Button>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={picture() !== undefined}>
|
<Show when={picture() !== undefined}>
|
||||||
|
|
|
@ -150,13 +150,13 @@ const hasMissingTimestamps = (trk: Trk) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const convertTrkToRteWhenNeeded = (gpx: Gpx) => {
|
const convertTrkToRteWhenNeeded = (gpx: Gpx, forceImportAsRoutes: boolean) => {
|
||||||
if (gpx.trk === undefined) {
|
if (gpx.trk === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newTrks: Trk[] = [];
|
const newTrks: Trk[] = [];
|
||||||
for (const trk of gpx.trk) {
|
for (const trk of gpx.trk) {
|
||||||
if (hasMissingTimestamps(trk)) {
|
if (forceImportAsRoutes || hasMissingTimestamps(trk)) {
|
||||||
const rte = { ...trk, trkseg: undefined, rtept: [] };
|
const rte = { ...trk, trkseg: undefined, rtept: [] };
|
||||||
for (const trkseg of trk.trkseg!) {
|
for (const trkseg of trk.trkseg!) {
|
||||||
rte.rtept = rte.rtept.concat(trkseg.trkpt);
|
rte.rtept = rte.rtept.concat(trkseg.trkpt);
|
||||||
|
@ -174,7 +174,7 @@ const convertTrkToRteWhenNeeded = (gpx: Gpx) => {
|
||||||
|
|
||||||
export const pruneAndSaveImportedGpx = async (params: any) => {
|
export const pruneAndSaveImportedGpx = async (params: any) => {
|
||||||
console.log({ caller: 'pruneAndSaveImportedGpx', params });
|
console.log({ caller: 'pruneAndSaveImportedGpx', params });
|
||||||
const { id, gpx, tech } = params;
|
const { id, gpx, tech, forceImportAsRoutes } = params;
|
||||||
let gpxId: IdGpx;
|
let gpxId: IdGpx;
|
||||||
let docs: any[] = [];
|
let docs: any[] = [];
|
||||||
const extensions = {
|
const extensions = {
|
||||||
|
@ -186,7 +186,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => {
|
||||||
extensions: gpx.extensions,
|
extensions: gpx.extensions,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
convertTrkToRteWhenNeeded(gpx);
|
convertTrkToRteWhenNeeded(gpx, forceImportAsRoutes);
|
||||||
let previousGpx: Gpx | null = null;
|
let previousGpx: Gpx | null = null;
|
||||||
let to: string[];
|
let to: string[];
|
||||||
if (id === 'new') {
|
if (id === 'new') {
|
||||||
|
|
Loading…
Reference in New Issue