From b36ad82b614abe74e42854c0ee0d5078e6938f94 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 6 Dec 2022 21:56:23 +0100 Subject: [PATCH] Saving Wpt after edition. --- src/components/wpt/Wpt.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/wpt/Wpt.tsx b/src/components/wpt/Wpt.tsx index 12e1c58..53f5b1e 100644 --- a/src/components/wpt/Wpt.tsx +++ b/src/components/wpt/Wpt.tsx @@ -83,9 +83,13 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { }; createEffect(() => { - console.log({ caller: 'Wpt', vectorSource, wptId, wpt: wpt() }); + console.log({ caller: 'Wpt', vectorSource, wptId, wpt: cloneDeep(wpt()) }); - if (wpt() && !tree[wptId]) { + if (wpt() /* && !tree[wptId] */) { + const existingFeature = vectorSource.getFeatureById(wptId); + if (existingFeature) { + vectorSource.removeFeature(existingFeature); + } let geo: any = { type: 'FeatureCollection', features: [ @@ -96,6 +100,7 @@ export const Wpt: Component = ({ vectorSource, wptId: wptId }) => { coordinates: [wpt()?.$.lon, wpt()?.$.lat], }, properties: { type: 'wpt', ...wpt(), id: wptId, getTitle, edit }, + id: wptId, }, ], }; @@ -103,7 +108,7 @@ 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 }); + // setBranch(wptId, { features, updateHandler }); } });