From 597cb8629a31aa3f45560206bce6956a64664d91 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Wed, 15 Feb 2023 12:02:56 +0100 Subject: [PATCH] Displaying last position of each gpx --- src/components/gpx/styles.ts | 23 ++++++++++++++++++++++ src/components/trkseg/Trkseg.tsx | 33 +++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/components/gpx/styles.ts b/src/components/gpx/styles.ts index e78b96f..bbe9632 100644 --- a/src/components/gpx/styles.ts +++ b/src/components/gpx/styles.ts @@ -257,6 +257,29 @@ const styles = { return styles; }, memoizeOptions), }, + 'trkseg-finish': { + getParameters: (feature: Feature) => { + const positions: Set = feature.get('positions'); + return { + isLast: positions.has('gpx-end') && positions.has('trk-end'), + }; + }, + getStyle: memoize((params: any) => { + // console.log({ caller: 'getStyle', params }); + const { isLast } = params; + if (isLast) { + return new Style({ + image: new Icon({ + src: wptIcon, + scale: 1 / 15, + opacity: 0.9, + anchor: [0.5, 1], + }), + }); + } + return null; + }, memoizeOptions), + }, rte: { getParameters: (feature: Feature) => { return { diff --git a/src/components/trkseg/Trkseg.tsx b/src/components/trkseg/Trkseg.tsx index 4c839eb..c28c202 100644 --- a/src/components/trkseg/Trkseg.tsx +++ b/src/components/trkseg/Trkseg.tsx @@ -35,19 +35,47 @@ export const Trkseg: Component = ({ }); }; + const positions = () => { + let result = new Set(); + if (context.trk && context.gpx) { + const trkId = context.trkId; + if (trkId === context.gpx().trk.at(0)) { + result.add('gpx-start'); + } + if (trkId === context.gpx().trk.at(-1)) { + result.add('gpx-end'); + } + if (trksegId === context.trk().trkseg.at(0)) { + result.add('trk-start'); + } + if (trksegId === context.trk().trkseg.at(-1)) { + result.add('trk-end'); + } + } + return result; + }; + onCleanup(() => { console.log({ caller: 'Trkseg / onCleanup', trksegId, trkseg: trkseg(), params, + context, }); destroyCachedSignal(params); clearFeatures(); }); createEffect(() => { - console.log({ caller: 'Trkseg', vectorSource, trksegId, trkseg: trkseg() }); + console.log({ + caller: 'Trkseg', + vectorSource, + trksegId, + trkseg: trkseg(), + context, + trk: context.trk(), + }); if (trkseg() && trkseg().trkpt && trkseg().trkpt.length > 0) { let geo: any = { @@ -66,6 +94,7 @@ export const Trkseg: Component = ({ type: 'trkseg-start', id: trksegId, context: { ...context, trkseg, trksegId }, + positions: positions(), }, id: `${trksegId}/start`, }, @@ -81,6 +110,7 @@ export const Trkseg: Component = ({ type: 'trkseg', id: trksegId, context: { ...context, trkseg, trksegId }, + positions: positions(), }, id: trksegId, }, @@ -97,6 +127,7 @@ export const Trkseg: Component = ({ type: 'trkseg-finish', id: trksegId, context: { ...context, trkseg, trksegId }, + positions: positions(), }, id: `${trksegId}/end`, },