Removing existing features before adding new ones.

This commit is contained in:
Eric van der Vlist 2022-12-14 08:03:42 +01:00
parent 040122189c
commit 600ce534fe
3 changed files with 22 additions and 0 deletions

View File

@ -62,6 +62,7 @@ export const Rte: Component<Props> = ({ vectorSource, rteId }) => {
coordinates: [rte().rtept[0].$.lon, rte().rtept[0].$.lat], coordinates: [rte().rtept[0].$.lon, rte().rtept[0].$.lat],
}, },
properties: { type: 'rte-start', id: rteId }, properties: { type: 'rte-start', id: rteId },
id: `${rteId}/start`,
}, },
{ {
type: 'Feature', type: 'Feature',
@ -73,6 +74,7 @@ export const Rte: Component<Props> = ({ vectorSource, rteId }) => {
]), ]),
}, },
properties: { type: 'rte', id: rteId }, properties: { type: 'rte', id: rteId },
id:rteId
}, },
{ {
type: 'Feature', type: 'Feature',
@ -84,12 +86,19 @@ export const Rte: Component<Props> = ({ vectorSource, rteId }) => {
], ],
}, },
properties: { type: 'rte-finish', id: rteId }, properties: { type: 'rte-finish', id: rteId },
id: `${rteId}/end`,
}, },
], ],
}; };
const features = new GeoJSON().readFeatures(geo); const features = new GeoJSON().readFeatures(geo);
console.log({ caller: 'Rte', features }); console.log({ caller: 'Rte', features });
[`${rteId}/start`, rteId, `${rteId}/end`].forEach((id) => {
const feature = vectorSource.getFeatureById(id);
if (feature) {
vectorSource.removeFeature(feature);
}
});
vectorSource.addFeatures(features); vectorSource.addFeatures(features);
} }
}); });

View File

@ -62,6 +62,7 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
coordinates: [trkseg().trkpt[0].$.lon, trkseg().trkpt[0].$.lat], coordinates: [trkseg().trkpt[0].$.lon, trkseg().trkpt[0].$.lat],
}, },
properties: { type: 'trkseg-start', id: trksegId }, properties: { type: 'trkseg-start', id: trksegId },
id: `${trksegId}/start`,
}, },
{ {
type: 'Feature', type: 'Feature',
@ -73,6 +74,7 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
]), ]),
}, },
properties: { type: 'trkseg', id: trksegId }, properties: { type: 'trkseg', id: trksegId },
id: trksegId,
}, },
{ {
type: 'Feature', type: 'Feature',
@ -84,12 +86,19 @@ export const Trkseg: Component<Props> = ({ vectorSource, trksegId }) => {
], ],
}, },
properties: { type: 'trkseg-finish', id: trksegId }, properties: { type: 'trkseg-finish', id: trksegId },
id: `${trksegId}/end`,
}, },
], ],
}; };
const features = new GeoJSON().readFeatures(geo); const features = new GeoJSON().readFeatures(geo);
console.log({ caller: 'Trkseg', features }); console.log({ caller: 'Trkseg', features });
[`${trksegId}/start`, trksegId, `${trksegId}/end`].forEach((id) => {
const feature = vectorSource.getFeatureById(id);
if (feature) {
vectorSource.removeFeature(feature);
}
});
vectorSource.addFeatures(features); vectorSource.addFeatures(features);
} }
}); });

View File

@ -99,6 +99,10 @@ 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 });
const feature = vectorSource.getFeatureById(wptId);
if (feature) {
vectorSource.removeFeature(feature);
}
vectorSource.addFeatures(features); vectorSource.addFeatures(features);
} }
}); });