Cleanup (remove the tree/branch mechanism which isn't useful).

This commit is contained in:
Eric van der Vlist 2022-12-08 21:27:40 +01:00
parent 38224d73da
commit 21a63ec54c
5 changed files with 5 additions and 59 deletions

View File

@ -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: '<Infos/> / 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);

View File

@ -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<Tree>({});
export { tree };
export const setBranch = (key: string, branch: Branch) => {
setTree({ ...tree, [key]: branch });
};
const Map: Component = () => {
const [getMap, setMap] = createSignal<OlMap | null>(null);
const params = useParams();
@ -208,7 +191,6 @@ const Map: Component = () => {
olMap.on(['singleclick'], clickHandler);
setMap(olMap);
setBranch('/', { vectorLayer: vectorLayer });
});
return (

View File

@ -1 +1 @@
export { default, getState, tree, setBranch } from './Map';
export { default, getState } from './Map';

View File

@ -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<Props> = ({ 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<Props> = ({ 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 <></>;
};

View File

@ -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<Props> = ({ 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<Props> = ({ 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<Props> = ({ 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);
};