better gpx route error handling

This commit is contained in:
Fedor Katurov 2020-01-24 17:00:23 +07:00
parent e995b46641
commit 3ffba24994
2 changed files with 19 additions and 13 deletions

View file

@ -384,13 +384,15 @@ function* uploadGpx({ file }: ReturnType<typeof editorUploadGpx>) {
editorSetGpx({ editorSetGpx({
list: [ list: [
...list, ...list,
...gpx.map(item => ({ ...gpx
enabled: true, .filter(item => item.latlngs && item.latlngs.length)
latlngs: item.latlngs, .map(item => ({
color: getRandomColor(), enabled: true,
name: item.name || `Track #${list.length + 1}`, latlngs: item.latlngs,
id: uuid() as string, color: getRandomColor(),
})), name: item.name || `Track #${list.length + 1}`,
id: uuid() as string,
})),
], ],
}) })
); );

View file

@ -93,12 +93,16 @@ export const importGpxTrack = async (file: File) => {
if (!gpx || !gpx.trk) return null; if (!gpx || !gpx.trk) return null;
const latlngs: LatLng[] = gpx.trk.reduce((trk_res, trk) => { const latlngs: LatLng[] = gpx.trk.reduce((trk_res, trk) => {
return trk.trkseg.reduce((trkseg_res, trkseg) => { return trk.trkseg
return [ ? trk.trkseg.reduce((trkseg_res, trkseg) => {
...trkseg_res, return trkseg.trkpt
...trkseg.trkpt.map(pnt => ({ lat: pnt['$'].lat, lng: pnt['$'].lon })), ? [
]; ...trkseg_res,
}, trk_res); ...trkseg.trkpt.map(pnt => ({ lat: pnt['$'].lat, lng: pnt['$'].lon })),
]
: trkseg_res;
}, trk_res)
: trk_res;
}, []); }, []);
return [ return [