GPX import.
This commit is contained in:
1 parent
5de30283b1
commit
83e14932a4
7 files changed
+128
-8
No files matched your search
@@ -0,0 +1,18 @@
|
||||
.container {
|
||||
position: fixed !important;
|
||||
top: 6px;
|
||||
margin-left: calc(100% - 80px) !important;
|
||||
}
|
||||
.label {
|
||||
--opacity: 0.6;
|
||||
--ion-background-color: white;
|
||||
}
|
||||
|
||||
.inputFile {
|
||||
width: 0.1px;
|
||||
height: 0.1px;
|
||||
opacity: 0;
|
||||
overflow: hidden;
|
||||
/* position: absolute; */
|
||||
z-index: -1;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { Component } from 'solid-js';
|
||||
|
||||
import CloudUploadIcon from '@suid/icons-material/CloudUpload';
|
||||
|
||||
import GPX from '../../lib/gpx-parser-builder/src/gpx';
|
||||
|
||||
import css from './GpxImport.module.css';
|
||||
import { findStartTime } from '../../lib/gpx';
|
||||
import dispatch from '../../workers/dispatcher-main';
|
||||
import { intToGpxId } from '../../lib/ids';
|
||||
|
||||
const GpxImport: Component = () => {
|
||||
const onChangeHandler = (event: any) => {
|
||||
console.log('On change handler');
|
||||
const file: File = event.target.files[0];
|
||||
const fileReader = new FileReader();
|
||||
fileReader.readAsText(file);
|
||||
|
||||
fileReader.addEventListener(
|
||||
'load',
|
||||
() => {
|
||||
// this will then display a text file
|
||||
console.log(fileReader.result);
|
||||
const gpx = GPX.parse(fileReader.result);
|
||||
console.log(`gpx: ${JSON.stringify(gpx)}`);
|
||||
const startTime = new Date(findStartTime(gpx)!);
|
||||
dispatch({
|
||||
action: 'pruneAndSaveImportedGpx',
|
||||
params: {
|
||||
id: { gpx: intToGpxId(startTime.valueOf()) },
|
||||
gpx: gpx,
|
||||
tech: {
|
||||
lastModified: new Date(file.lastModified).toISOString(),
|
||||
importDate: new Date().toISOString(),
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
type: file.type,
|
||||
},
|
||||
},
|
||||
});
|
||||
// pushGpx(db, {
|
||||
// gpx,
|
||||
// metadata: {
|
||||
// lastModified: new Date(file.lastModified).toISOString(),
|
||||
// importDate: new Date().toISOString(),
|
||||
// name: file.name,
|
||||
// size: file.size,
|
||||
// type: file.type,
|
||||
// },
|
||||
// });
|
||||
},
|
||||
false
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div class={css.container}>
|
||||
<label for='gpx-import' class={css.label}>
|
||||
<CloudUploadIcon />
|
||||
</label>
|
||||
<input
|
||||
type='file'
|
||||
id='gpx-import'
|
||||
class={css.inputFile}
|
||||
accept='.gpx'
|
||||
onChange={onChangeHandler}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default GpxImport;
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from './GpxImport';
|
||||
@@ -21,6 +21,7 @@ import { Circle, Fill, Stroke, Style, Icon } from 'ol/style';
|
||||
import GetLocation, { getCurrentLocation } from '../get-location';
|
||||
import ShowLocationIcon from '../get-location/ShowLocationIcon.svg';
|
||||
import { Back, Forward } from '../back-forward';
|
||||
import GpxImport from '../gpx-import';
|
||||
|
||||
const [getState, setState] = createSignal({
|
||||
lon: 0,
|
||||
@@ -161,6 +162,14 @@ const Map: Component = () => {
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
new Control({
|
||||
// @ts-ignore
|
||||
element: (
|
||||
<div>
|
||||
<GpxImport />
|
||||
</div>
|
||||
),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
olMap.on(['moveend'], changeListener);
|
||||
|
||||
Reference in new issue
Block a user