From 792498ef4a304d0f2c8cd8094887354e18997b24 Mon Sep 17 00:00:00 2001 From: Andria Capai Date: Wed, 18 Sep 2024 15:42:40 +0200 Subject: [PATCH] fix: duplicated geom "not saved" on edition - Refact and manage use case where the user wants to create new geometrie --> saved --> and wants to edit the geom created Reviewed-by: andriacap --- .../leaflet-draw/leaflet-draw.component.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/GN2CommonModule/map/leaflet-draw/leaflet-draw.component.ts b/frontend/src/app/GN2CommonModule/map/leaflet-draw/leaflet-draw.component.ts index 9689f65c4c..0225025ee0 100644 --- a/frontend/src/app/GN2CommonModule/map/leaflet-draw/leaflet-draw.component.ts +++ b/frontend/src/app/GN2CommonModule/map/leaflet-draw/leaflet-draw.component.ts @@ -151,14 +151,29 @@ export class LeafletDrawComponent implements OnInit, OnChanges { }); this.map.on(this._Le.Draw.Event.DRAWSTOP, (e) => { - if (this._currentGeojson) { - const layer: L.Layer = this.mapservice.createGeojson(this._currentGeojson.geometry, false); - if (!this.mapservice.leafletDrawFeatureGroup.hasLayer(layer)) { - this.loadDrawfromGeoJson(this._currentGeojson.geometry); - } + const geojson = this._currentGeojson?.geometry || this.geojson; + + if (this._currentDraw) { + this.handleDrawStopWithCurrentDraw(geojson); + } else { + this.handleDrawStopWithoutCurrentDraw(geojson); } }); } + handleDrawStopWithCurrentDraw(geojson: any): void { + if (!this.mapservice.leafletDrawFeatureGroup.hasLayer(this._currentDraw) && geojson) { + this.loadDrawfromGeoJson(geojson); + } + } + + handleDrawStopWithoutCurrentDraw(geojson: any): void { + this.mapservice.removeAllLayers(this.map, this.mapservice.fileLayerFeatureGroup); + const layer: L.Layer = this.mapservice.createGeojson(geojson, false); + + if (!this.mapservice.leafletDrawFeatureGroup.hasLayer(layer)) { + this.loadDrawfromGeoJson(geojson); + } + } getGeojsonFromFeatureGroup(layerType) { let geojson: any = this.mapservice.leafletDrawFeatureGroup.toGeoJSON();