From b14db11938d3f3ca2405b8edaa68f7889c522592 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Thu, 29 Dec 2022 08:14:43 +0100 Subject: [PATCH] Adding context properties to OL features. --- src/components/gpx/Gpx.tsx | 18 +++++++++++++++--- src/components/rte/Rte.tsx | 28 +++++++++++++++++++--------- src/components/trk/Trk.tsx | 9 +++++++-- src/components/trkseg/Trkseg.tsx | 25 +++++++++++++++++++++---- src/components/wpt/Wpt.tsx | 16 ++++++++++++++-- 5 files changed, 76 insertions(+), 20 deletions(-) diff --git a/src/components/gpx/Gpx.tsx b/src/components/gpx/Gpx.tsx index b07a0b9..88e5fb8 100644 --- a/src/components/gpx/Gpx.tsx +++ b/src/components/gpx/Gpx.tsx @@ -83,7 +83,11 @@ export const Gpx: Component = ({ map, gpxId }) => { console.log({ caller: 'Gpx / loop', trkId }); return ( - + ); }} @@ -93,7 +97,11 @@ export const Gpx: Component = ({ map, gpxId }) => { console.log({ caller: 'Gpx / loop', rteId }); return ( - + ); }} @@ -103,7 +111,11 @@ export const Gpx: Component = ({ map, gpxId }) => { console.log({ caller: 'Gpx / loop', wptId }); return ( - + ); }} diff --git a/src/components/rte/Rte.tsx b/src/components/rte/Rte.tsx index c290b97..32aa061 100644 --- a/src/components/rte/Rte.tsx +++ b/src/components/rte/Rte.tsx @@ -7,9 +7,10 @@ import GeoJSON from 'ol/format/GeoJSON'; interface Props { rteId: string; vectorSource: VectorSource; + context: any; } -export const Rte: Component = ({ vectorSource, rteId }) => { +export const Rte: Component = ({ vectorSource, rteId, context }) => { const [rte, setRte] = createSignal(); const [dispatchId, setDispatchId] = createSignal(-1); @@ -61,7 +62,11 @@ export const Rte: Component = ({ vectorSource, rteId }) => { type: 'Point', coordinates: [rte().rtept[0].$.lon, rte().rtept[0].$.lat], }, - properties: { type: 'rte-start', id: rteId }, + properties: { + type: 'rte-start', + id: rteId, + context: { ...context, rte, rteId }, + }, id: `${rteId}/start`, }, { @@ -73,19 +78,24 @@ export const Rte: Component = ({ vectorSource, rteId }) => { rtept.$.lat, ]), }, - properties: { type: 'rte', id: rteId }, - id:rteId + properties: { + type: 'rte', + id: rteId, + context: { ...context, rte, rteId }, + }, + id: rteId, }, { type: 'Feature', geometry: { type: 'Point', - coordinates: [ - rte().rtept.at(-1).$.lon, - rte().rtept.at(-1).$.lat, - ], + coordinates: [rte().rtept.at(-1).$.lon, rte().rtept.at(-1).$.lat], + }, + properties: { + type: 'rte-finish', + id: rteId, + context: { ...context, rte, rteId }, }, - properties: { type: 'rte-finish', id: rteId }, id: `${rteId}/end`, }, ], diff --git a/src/components/trk/Trk.tsx b/src/components/trk/Trk.tsx index ab54717..1d56099 100644 --- a/src/components/trk/Trk.tsx +++ b/src/components/trk/Trk.tsx @@ -19,8 +19,9 @@ import VectorSource from 'ol/source/Vector'; interface Props { trkId: string; vectorSource: VectorSource; + context: any; } -export const Trk: Component = ({ vectorSource, trkId }) => { +export const Trk: Component = ({ vectorSource, trkId, context }) => { const [trk, setTrk] = createSignal(); const [dispatchId, setDispatchId] = createSignal(-1); @@ -70,7 +71,11 @@ export const Trk: Component = ({ vectorSource, trkId }) => { console.log({ caller: 'Trk / loop', trksegId }); return ( - + ); }} diff --git a/src/components/trkseg/Trkseg.tsx b/src/components/trkseg/Trkseg.tsx index fc760cd..94282b1 100644 --- a/src/components/trkseg/Trkseg.tsx +++ b/src/components/trkseg/Trkseg.tsx @@ -7,9 +7,14 @@ import GeoJSON from 'ol/format/GeoJSON'; interface Props { trksegId: string; vectorSource: VectorSource; + context: any; } -export const Trkseg: Component = ({ vectorSource, trksegId }) => { +export const Trkseg: Component = ({ + vectorSource, + trksegId, + context, +}) => { const [trkseg, setTrkseg] = createSignal(); const [dispatchId, setDispatchId] = createSignal(-1); @@ -61,7 +66,11 @@ export const Trkseg: Component = ({ vectorSource, trksegId }) => { type: 'Point', coordinates: [trkseg().trkpt[0].$.lon, trkseg().trkpt[0].$.lat], }, - properties: { type: 'trkseg-start', id: trksegId }, + properties: { + type: 'trkseg-start', + id: trksegId, + context: { ...context, trkseg, trksegId }, + }, id: `${trksegId}/start`, }, { @@ -73,7 +82,11 @@ export const Trkseg: Component = ({ vectorSource, trksegId }) => { trkpt.$.lat, ]), }, - properties: { type: 'trkseg', id: trksegId }, + properties: { + type: 'trkseg', + id: trksegId, + context: { ...context, trkseg, trksegId }, + }, id: trksegId, }, { @@ -85,7 +98,11 @@ export const Trkseg: Component = ({ vectorSource, trksegId }) => { trkseg().trkpt.at(-1).$.lat, ], }, - properties: { type: 'trkseg-finish', id: trksegId }, + properties: { + type: 'trkseg-finish', + id: trksegId, + context: { ...context, trkseg, trksegId }, + }, id: `${trksegId}/end`, }, ], diff --git a/src/components/wpt/Wpt.tsx b/src/components/wpt/Wpt.tsx index e2112ce..122c72a 100644 --- a/src/components/wpt/Wpt.tsx +++ b/src/components/wpt/Wpt.tsx @@ -11,6 +11,7 @@ import { Box, Button, Stack, TextField } from '@suid/material'; interface Props { wptId: string; vectorSource: VectorSource; + context: any; } enum Mode { @@ -18,7 +19,11 @@ enum Mode { EDIT, } -export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { +export const Wpt: Component = ({ + vectorSource, + wptId: wptId, + context, +}) => { const [t, { add, locale, dict }] = useI18n(); const [wpt, setWpt] = createSignal(); @@ -91,7 +96,14 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { type: 'Point', coordinates: [wpt()?.$.lon, wpt()?.$.lat], }, - properties: { type: 'wpt', ...wpt(), id: wptId, getTitle, edit }, + properties: { + type: 'wpt', + ...wpt(), + id: wptId, + getTitle, + edit, + context: { ...context, wpt, wptId }, + }, id: wptId, }, ],