From 12cfa9337a71deab0ade47fad60383317c427052 Mon Sep 17 00:00:00 2001 From: evlist Date: Sun, 27 Nov 2022 22:48:35 +0100 Subject: [PATCH] Starting to add some style to trksegs. --- src/components/gpx-import/GpxImport.tsx | 38 ++++++++++++++--------- src/components/gpx/Gpx.tsx | 21 ++++++++++++- src/icons/flag-finish-b-o-svgrepo-com.svg | 1 + src/icons/flag-start-b-svgrepo-com.svg | 1 + 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 src/icons/flag-finish-b-o-svgrepo-com.svg create mode 100644 src/icons/flag-start-b-svgrepo-com.svg diff --git a/src/components/gpx-import/GpxImport.tsx b/src/components/gpx-import/GpxImport.tsx index b84d45e..2a5a45d 100644 --- a/src/components/gpx-import/GpxImport.tsx +++ b/src/components/gpx-import/GpxImport.tsx @@ -25,22 +25,30 @@ const GpxImport: Component = () => { 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, + if (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, + }, }, - }, - }); - refetchGpxList(); + }); + refetchGpxList(); + } else { + console.error({ + message: "can't parse GPX file", + xml: fileReader.result, + }); + } + // TODO: error handling }, false ); diff --git a/src/components/gpx/Gpx.tsx b/src/components/gpx/Gpx.tsx index 61ffe0a..f189612 100644 --- a/src/components/gpx/Gpx.tsx +++ b/src/components/gpx/Gpx.tsx @@ -7,12 +7,31 @@ import Trk from '../trk'; import getUri from '../../lib/ids'; import VectorSource from 'ol/source/Vector'; import VectorLayer from 'ol/layer/Vector'; +import { Circle, Fill, Icon, Stroke, Style } from 'ol/style'; +import startIcon from '../../icons/flag-start-b-svgrepo-com.svg'; interface Props { gpxId: string; map: () => OlMap | null; } +console.log({ caller: startIcon }); + +const style = [ + new Style({ + stroke: new Stroke({ + color: 'blue', + width: 2, + }), + image: new Icon({ + src: startIcon, + color: 'green', + scale: 0.2, + opacity: 0.6, + }), + }), +]; + export const Gpx: Component = ({ map, gpxId }) => { const [gpx] = createResource( gpxId, @@ -26,7 +45,7 @@ export const Gpx: Component = ({ map, gpxId }) => { ); const vectorSource = new VectorSource(); - const vectorLayer = new VectorLayer({ source: vectorSource }); + const vectorLayer = new VectorLayer({ source: vectorSource, style }); createEffect(() => map()?.addLayer(vectorLayer)); createEffect(() => { diff --git a/src/icons/flag-finish-b-o-svgrepo-com.svg b/src/icons/flag-finish-b-o-svgrepo-com.svg new file mode 100644 index 0000000..13b4208 --- /dev/null +++ b/src/icons/flag-finish-b-o-svgrepo-com.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/flag-start-b-svgrepo-com.svg b/src/icons/flag-start-b-svgrepo-com.svg new file mode 100644 index 0000000..f082b9f --- /dev/null +++ b/src/icons/flag-start-b-svgrepo-com.svg @@ -0,0 +1 @@ + \ No newline at end of file