Saving Wpt after edition.

This commit is contained in:
Eric van der Vlist 2022-12-06 21:56:23 +01:00
parent 156fefae3b
commit b36ad82b61
1 changed files with 8 additions and 3 deletions

View File

@ -83,9 +83,13 @@ export const Wpt: Component<Props> = ({ vectorSource, wptId: wptId }) => {
}; };
createEffect(() => { 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 = { let geo: any = {
type: 'FeatureCollection', type: 'FeatureCollection',
features: [ features: [
@ -96,6 +100,7 @@ export const Wpt: Component<Props> = ({ vectorSource, wptId: wptId }) => {
coordinates: [wpt()?.$.lon, wpt()?.$.lat], coordinates: [wpt()?.$.lon, wpt()?.$.lat],
}, },
properties: { type: 'wpt', ...wpt(), id: wptId, getTitle, edit }, properties: { type: 'wpt', ...wpt(), id: wptId, getTitle, edit },
id: wptId,
}, },
], ],
}; };
@ -103,7 +108,7 @@ export const Wpt: Component<Props> = ({ vectorSource, wptId: wptId }) => {
const features = new GeoJSON().readFeatures(geo); const features = new GeoJSON().readFeatures(geo);
console.log({ caller: 'Wpt', features }); console.log({ caller: 'Wpt', features });
vectorSource.addFeatures(features); vectorSource.addFeatures(features);
setBranch(wptId, { features, updateHandler }); // setBranch(wptId, { features, updateHandler });
} }
}); });