From 21a63ec54c0a22f396b2840a054dd7606dca8986 Mon Sep 17 00:00:00 2001 From: evlist Date: Thu, 8 Dec 2022 21:27:40 +0100 Subject: [PATCH] Cleanup (remove the tree/branch mechanism which isn't useful). --- src/components/infos/Infos.tsx | 6 ------ src/components/map/Map.tsx | 18 ------------------ src/components/map/index.ts | 2 +- src/components/trkseg/Trkseg.tsx | 12 +----------- src/components/wpt/Wpt.tsx | 26 +++----------------------- 5 files changed, 5 insertions(+), 59 deletions(-) diff --git a/src/components/infos/Infos.tsx b/src/components/infos/Infos.tsx index 9b84b81..c80a9c0 100644 --- a/src/components/infos/Infos.tsx +++ b/src/components/infos/Infos.tsx @@ -2,11 +2,8 @@ import { Grid, IconButton } from '@suid/material'; import { Feature } from 'ol'; import { Geometry } from 'ol/geom'; import { Component, createSignal, For, Show } from 'solid-js'; -import { unwrap } from 'solid-js/store'; import { useI18n } from '@solid-primitives/i18n'; -import CloseIcon from '@suid/icons-material/Close'; import EditIcon from '@suid/icons-material/Edit'; -import { tree } from '../map'; import { Paper, Stack } from '@suid/material'; import styled from '@suid/material/styles/styled'; import Dialog from '../dialog'; @@ -29,7 +26,6 @@ export const clickHandler = (event: any) => { caller: ' / clickHandler', event, features, - tree: unwrap(tree), }); selectedFeatures.map((feature) => feature.set('isSelected', false)); selectedFeatures = features; @@ -42,8 +38,6 @@ export const clickHandler = (event: any) => { feature, id, }); - const branch = tree[id]; - if (branch?.updateHandler) branch.updateHandler(feature); }); if (features.length > 0) { setOpen(true); diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index b041f47..52ecd13 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -46,23 +46,6 @@ const [getState, setState] = createSignal({ export { getState }; -interface Branch { - vectorLayer?: VectorLayer; - features?: Feature[]; - hidden?: boolean; - updateHandler?: (feature: Feature) => void; -} - -interface Tree { - [key: string]: Branch; -} - -const [tree, setTree] = createStore({}); -export { tree }; -export const setBranch = (key: string, branch: Branch) => { - setTree({ ...tree, [key]: branch }); -}; - const Map: Component = () => { const [getMap, setMap] = createSignal(null); const params = useParams(); @@ -208,7 +191,6 @@ const Map: Component = () => { olMap.on(['singleclick'], clickHandler); setMap(olMap); - setBranch('/', { vectorLayer: vectorLayer }); }); return ( diff --git a/src/components/map/index.ts b/src/components/map/index.ts index 54ef3de..718cf08 100644 --- a/src/components/map/index.ts +++ b/src/components/map/index.ts @@ -1 +1 @@ -export { default, getState, tree, setBranch } from './Map'; +export { default, getState } from './Map'; diff --git a/src/components/trkseg/Trkseg.tsx b/src/components/trkseg/Trkseg.tsx index 151eefb..cdab2ed 100644 --- a/src/components/trkseg/Trkseg.tsx +++ b/src/components/trkseg/Trkseg.tsx @@ -1,10 +1,8 @@ import { Component, createEffect, createResource } from 'solid-js'; - import dispatch from '../../workers/dispatcher-main'; import VectorSource from 'ol/source/Vector'; import GeoJSON from 'ol/format/GeoJSON'; -import { setBranch, tree } from '../map'; import { Feature } from 'ol'; interface Props { @@ -27,7 +25,7 @@ export const Trkseg: Component = ({ vectorSource, trksegId }) => { createEffect(() => { console.log({ caller: 'Trkseg', vectorSource, trksegId, trkseg: trkseg() }); - if (trkseg() && !tree[trksegId]) { + if (trkseg()) { let geo: any = { type: 'FeatureCollection', features: [ @@ -67,17 +65,9 @@ export const Trkseg: Component = ({ vectorSource, trksegId }) => { const features = new GeoJSON().readFeatures(geo); console.log({ caller: 'Trkseg', features }); vectorSource.addFeatures(features); - setBranch(trksegId, { features, updateHandler }); } }); - const updateHandler = (feature: Feature) => { - console.log({ - caller: 'Trkseg / updateHandler / clicked', - feature, - }); - }; - return <>; }; diff --git a/src/components/wpt/Wpt.tsx b/src/components/wpt/Wpt.tsx index c389a29..1aeec41 100644 --- a/src/components/wpt/Wpt.tsx +++ b/src/components/wpt/Wpt.tsx @@ -1,20 +1,12 @@ -import { - Component, - createEffect, - createResource, - createSignal, - onCleanup, -} from 'solid-js'; +import { Component, createEffect, createSignal, onCleanup } from 'solid-js'; import dispatch, { cancelDispatch } from '../../workers/dispatcher-main'; import VectorSource from 'ol/source/Vector'; import GeoJSON from 'ol/format/GeoJSON'; -import { setBranch, tree } from '../map'; -import { Feature } from 'ol'; import { useI18n } from '@solid-primitives/i18n'; import { cloneDeep } from 'lodash'; import Dialog from '../dialog'; -import { Box, Button, Grid, Stack, TextField } from '@suid/material'; +import { Box, Button, Stack, TextField } from '@suid/material'; interface Props { wptId: string; @@ -85,7 +77,7 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { createEffect(() => { console.log({ caller: 'Wpt', vectorSource, wptId, wpt: cloneDeep(wpt()) }); - if (wpt() /* && !tree[wptId] */) { + if (wpt()) { const existingFeature = vectorSource.getFeatureById(wptId); if (existingFeature) { vectorSource.removeFeature(existingFeature); @@ -108,17 +100,9 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { const features = new GeoJSON().readFeatures(geo); console.log({ caller: 'Wpt', features }); vectorSource.addFeatures(features); - // setBranch(wptId, { features, updateHandler }); } }); - const updateHandler = (feature: Feature) => { - console.log({ - caller: 'Wpt / updateHandler / clicked', - feature, - }); - }; - const closeHandler = () => { setMode(Mode.CLOSED); }; @@ -129,10 +113,6 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { wptId, editedWpt: editedWpt(), }); - // const newWpt = wpt(); - // if (newWpt) { - // newWpt.name = name.value; - // } dispatch({ action: 'putWpt', params: { id: wptId, wpt: editedWpt() } }); setMode(Mode.CLOSED); };