From 73aad8f2a215ccec50c9d4685a5fcf51545f56b6 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Fri, 30 Dec 2022 21:03:37 +0100 Subject: [PATCH] Progressing in implementing a tree representation of features. --- src/components/infos/Infos.tsx | 28 +++++++++++++++++++++--- src/components/tree/Tree.tsx | 39 ++++++++++++++++++++++++++++++++++ src/components/tree/index.ts | 1 + 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/components/tree/Tree.tsx create mode 100644 src/components/tree/index.ts diff --git a/src/components/infos/Infos.tsx b/src/components/infos/Infos.tsx index 703cce0..2407cc2 100644 --- a/src/components/infos/Infos.tsx +++ b/src/components/infos/Infos.tsx @@ -8,6 +8,7 @@ import EditIcon from '@suid/icons-material/Edit'; import { Paper, Stack } from '@suid/material'; import styled from '@suid/material/styles/styled'; import Dialog from '../dialog'; +import Tree from '../tree'; const Item = styled(Paper)(({ theme }) => ({ ...theme.typography.body2, @@ -19,6 +20,7 @@ const Item = styled(Paper)(({ theme }) => ({ const [open, setOpen] = createSignal(false); let selectedFeatures: Feature[] = []; +let hierarchy: any = {}; const level2Key = (feature: Feature) => feature.get('context').wptId || @@ -54,11 +56,11 @@ export const clickHandler = (event: any) => { } return 0; }); - let hierarchy: any = {}; selectedFeatures.map((feature: Feature) => { const gpxId = feature.get('context').gpxId; if (!hierarchy.hasOwnProperty(gpxId)) { hierarchy[gpxId] = { gpx: feature.get('context').gpx }; + hierarchy[gpxId].type = 'gpx'; } const l2key = level2Key(feature); if (!hierarchy[gpxId].hasOwnProperty(l2key)) { @@ -71,6 +73,7 @@ export const clickHandler = (event: any) => { hierarchy[gpxId][l2key].type = 'trk'; } else { hierarchy[gpxId][l2key].type = feature.get('type'); + feature; } } if (feature.get('type') === 'trkseg') { @@ -79,6 +82,8 @@ export const clickHandler = (event: any) => { hierarchy[gpxId][l2key][trksegId] = { trksegId, trkseg: feature.get('context').trkseg, + type: 'trkseg', + feature, }; } } @@ -108,6 +113,22 @@ export const clickHandler = (event: any) => { } }; +const FeaturesTree: Component<{ featuresHierarchy: any }> = ({ + featuresHierarchy, +}) => { + return ( + key.startsWith('gpx/')) + .map((key: string) => ( + + ))} + /> + ); +}; + const Infos: Component<{}> = (props) => { const [t, { add, locale, dict }] = useI18n(); const handleClick = () => { @@ -136,7 +157,8 @@ const Infos: Component<{}> = (props) => { alignItems='center' sx={{ width: 'calc(100% - 5px)' }} > - + + {/* {(feature) => { const geometry = feature.getGeometry(); const length = geometry @@ -162,7 +184,7 @@ const Infos: Component<{}> = (props) => { ); }} - + */} ); diff --git a/src/components/tree/Tree.tsx b/src/components/tree/Tree.tsx new file mode 100644 index 0000000..2edd577 --- /dev/null +++ b/src/components/tree/Tree.tsx @@ -0,0 +1,39 @@ +import { Paper, Stack } from '@suid/material'; +import styled from '@suid/material/styles/styled'; +import { Component, JSXElement, Show } from 'solid-js'; + +interface Props { + title: string; + content: JSXElement | undefined; + subTree: JSXElement | undefined; +} + +const Item = styled(Paper)(({ theme }) => ({ + ...theme.typography.body2, + padding: theme.spacing(1), + textAlign: 'center', + color: theme.palette.text.secondary, +})); + +const Tree: Component = ({ title, content, subTree }) => { + return ( + + +
{title}
+ +
{content}
+
+ +
{subTree}
+
+
+
+ ); +}; + +export default Tree; diff --git a/src/components/tree/index.ts b/src/components/tree/index.ts new file mode 100644 index 0000000..3c6564e --- /dev/null +++ b/src/components/tree/index.ts @@ -0,0 +1 @@ +export { default } from './Tree';