[CARTO] fix the GPX and KML imports in order to manage multiples draw types in the same file

This commit is contained in:
kara Diaby 2020-06-18 16:28:46 +02:00
parent 33dad952e6
commit 3dacff19d5

View file

@ -152,19 +152,20 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
featureCollection, featureCollection,
'post' 'post'
); );
let inputs = [...importInputs]; let inputs = [...importInputs];
const setInputs = inputs.map((input) => { const setInputs = inputs.map((input) => {
if (input.id === inputId) { if (input.id === inputId) {
input.disabled = true; input.disabled = true;
input.hasValue = true; input.hasValue = true;
resultFeatureCollection.features.forEach((feature) => { resultFeatureCollection.features.forEach((resultFeature) => {
if ( featureCollection.features.forEach((feature) => {
JSON.stringify(feature.geometry) === if (
JSON.stringify(featureCollection.features[0].geometry) JSON.stringify(resultFeature.geometry) ===
) { JSON.stringify(feature.geometry)
input.featureId = feature.properties.id; ) {
} input.featureIds.push(resultFeature.properties.id);
}
});
}); });
} }
return input; return input;
@ -189,7 +190,7 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
inputs.push({ inputs.push({
id: generateId(), id: generateId(),
disabled: false, disabled: false,
featureId: null, featureIds: [],
hasValue: false hasValue: false
}); });
setImportInputs(inputs); setImportInputs(inputs);
@ -203,9 +204,9 @@ function MapEditor({ featureCollection, url, preview, hasCadastres }) {
const inputToRemove = inputs.find((input) => input.id === inputId); const inputToRemove = inputs.find((input) => input.id === inputId);
for (const feature of featureCollection.features) { for (const feature of featureCollection.features) {
if (inputToRemove.featureId === feature.properties.id) { if (inputToRemove.featureIds.includes(feature.properties.id)) {
const featureToRemove = draw.get(feature.id); const featureToRemove = draw.get(feature.id);
await getJSON(`${url}/${inputToRemove.featureId}`, null, 'delete'); await getJSON(`${url}/${feature.properties.id}`, null, 'delete');
draw.delete(feature.id).getAll(); draw.delete(feature.id).getAll();
updateFeaturesList([featureToRemove]); updateFeaturesList([featureToRemove]);
} }