From ec5d90f76855061b063025a4cd4f705bef29f9e2 Mon Sep 17 00:00:00 2001 From: evlist Date: Mon, 28 Nov 2022 08:38:21 +0100 Subject: [PATCH] Diffrent flags for start and finish --- src/components/gpx/Gpx.tsx | 22 ++-------- src/components/gpx/styles.ts | 40 +++++++++++++++++++ .../flag-finish-b-o-svgrepo-com-green.svg | 1 + src/icons/flag-finish-b-o-svgrepo-com-red.svg | 1 + src/icons/flag-start-b-svgrepo-com-green.svg | 17 ++++++++ 5 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 src/components/gpx/styles.ts create mode 100644 src/icons/flag-finish-b-o-svgrepo-com-green.svg create mode 100644 src/icons/flag-finish-b-o-svgrepo-com-red.svg create mode 100644 src/icons/flag-start-b-svgrepo-com-green.svg diff --git a/src/components/gpx/Gpx.tsx b/src/components/gpx/Gpx.tsx index f189612..a9ea3f2 100644 --- a/src/components/gpx/Gpx.tsx +++ b/src/components/gpx/Gpx.tsx @@ -7,31 +7,15 @@ 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'; + + +import style from './styles'; 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, diff --git a/src/components/gpx/styles.ts b/src/components/gpx/styles.ts new file mode 100644 index 0000000..7d8d486 --- /dev/null +++ b/src/components/gpx/styles.ts @@ -0,0 +1,40 @@ +import { Circle, Fill, Icon, Stroke, Style } from 'ol/style'; +import startIcon from '../../icons/flag-start-b-svgrepo-com-green.svg'; +import finishIcon from '../../icons/flag-finish-b-o-svgrepo-com-red.svg'; +import { Feature } from 'ol'; + +const trackStrokeStyle = new Stroke({ + color: 'blue', + width: 2, +}); + +const trtksegStartImageStyle = new Icon({ + src: startIcon, + scale: 0.2, + opacity: 0.6, +}); + +const trtksegFinishImageStyle = new Icon({ + src: finishIcon, + scale: 0.2, + opacity: 0.6, +}); + +const trtksegStyle = new Style({ stroke: trackStrokeStyle }); +const trtksegStartStyle = new Style({ image: trtksegStartImageStyle }); +const trtksegFinishStyle = new Style({ image: trtksegFinishImageStyle }); + +export const style = (feature: Feature, resolution: number) => { + const type = feature.get('type'); + if (type === 'trkseg') { + return trtksegStyle; + } + if (type === 'trkseg-start') { + return trtksegStartStyle; + } + if (type === 'trkseg-finish') { + return trtksegFinishStyle; + } +}; + +export default style; diff --git a/src/icons/flag-finish-b-o-svgrepo-com-green.svg b/src/icons/flag-finish-b-o-svgrepo-com-green.svg new file mode 100644 index 0000000..4dbfc58 --- /dev/null +++ b/src/icons/flag-finish-b-o-svgrepo-com-green.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/flag-finish-b-o-svgrepo-com-red.svg b/src/icons/flag-finish-b-o-svgrepo-com-red.svg new file mode 100644 index 0000000..266aaad --- /dev/null +++ b/src/icons/flag-finish-b-o-svgrepo-com-red.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/icons/flag-start-b-svgrepo-com-green.svg b/src/icons/flag-start-b-svgrepo-com-green.svg new file mode 100644 index 0000000..46a6948 --- /dev/null +++ b/src/icons/flag-start-b-svgrepo-com-green.svg @@ -0,0 +1,17 @@ +