From fe7c4af04e506149949a597a3cf011af39529c12 Mon Sep 17 00:00:00 2001
From: florent <flavelle@neogeo.fr>
Date: Thu, 21 Apr 2022 14:10:48 +0200
Subject: [PATCH] fix delete feature type

---
 src/components/Map/EditingToolbar.vue |  1 -
 src/services/edition-service.js       |  1 -
 src/services/map-service.js           | 57 ++++++++++++---------------
 src/store/modules/map.store.js        |  4 +-
 src/views/Feature/FeatureEdit.vue     |  4 --
 src/views/Project/ProjectDetail.vue   |  5 +--
 6 files changed, 30 insertions(+), 42 deletions(-)

diff --git a/src/components/Map/EditingToolbar.vue b/src/components/Map/EditingToolbar.vue
index 52a995a4..90a93077 100644
--- a/src/components/Map/EditingToolbar.vue
+++ b/src/components/Map/EditingToolbar.vue
@@ -57,7 +57,6 @@ export default {
   },
   methods: {
     update(){
-      console.log(this.editionService.editing_feature);
       editionService.activeUpdateFeature();
     },
     deleteObj(){
diff --git a/src/services/edition-service.js b/src/services/edition-service.js
index 2930278b..bbedfdf2 100644
--- a/src/services/edition-service.js
+++ b/src/services/edition-service.js
@@ -90,7 +90,6 @@ const editionService = {
 
     this.draw.on('drawend', (evt) => {
       var feature = evt.feature;
-      console.log(feature);
       this.setEditingFeature(feature);
       this.draw.setActive(false);
     });
diff --git a/src/services/map-service.js b/src/services/map-service.js
index 968dfe43..1fccea57 100644
--- a/src/services/map-service.js
+++ b/src/services/map-service.js
@@ -57,7 +57,7 @@ const mapService = {
     return this.map;
   },
   destroyMap() {
-    this.map=undefined;
+    this.map = undefined;
   },
   createMap(el, options) {
     const {
@@ -69,7 +69,11 @@ const mapService = {
       zoomControl = true,
       interactions = { doubleClickZoom: false, mouseWheelZoom: false, dragPan: true },
     } = options;
-    console.log(options, zoomControl);
+
+    if (el.innerHTML) {
+      el.innerHTML = '';
+    }
+
     this.map = new Map({
       layers: [],
       target: el,
@@ -107,11 +111,13 @@ const mapService = {
       },
     });
     let overlay = this.overlay;
-    closer.onclick = function () {
-      overlay.setPosition(undefined);
-      closer.blur();
-      return false;
-    };
+    if (closer) {
+      closer.onclick = function () {
+        overlay.setPosition(undefined);
+        closer.blur();
+        return false;
+      };
+    }
     this.map.addOverlay(this.overlay);
 
     this.map.on('click', this.onMapClick.bind(this));
@@ -119,14 +125,12 @@ const mapService = {
   },
  
   onMapClick(event) {
-    console.log(event);
     let self = this;
     const features = this.map.getFeaturesAtPixel(event.pixel, {
       layerFilter(l) {
         return l === self.mvtLayer;
       },
     });
-    console.log(features);
     if (features && features.length > 0) {
       const popupContent = this._createContentPopup(features[0],
         this.mvtLayer.featureTypes, this.mvtLayer.project_slug);
@@ -136,7 +140,6 @@ const mapService = {
     //const queryableLayerSelected = document.getElementById(`queryable-layers-selector-${this.wmsParams.basemapId}`).getElementsByClassName('selected')[0].textContent;
     //console.log(queryableLayerSelected);
     if (this.layers) {
-      console.log(this.layers.find(x => x.query));
       let queryLayer = this.layers.find(x => x.query);
       // pour compatibilité avec le proxy django
       let proxyparams = [
@@ -152,9 +155,7 @@ const mapService = {
         'info_format', 'x', 'y', 'i', 'j',
       ];
       if (queryLayer) {
-        console.log('get feature infos');
         let url = this.getFeatureInfoUrl(event, queryLayer);
-        console.log(url);
         let urlInfos = url.split('?');
         const urlParams = new URLSearchParams(urlInfos[1]);
         let params = {};
@@ -229,7 +230,6 @@ const mapService = {
     return url;
   },
   fitBounds(bounds) {
-    console.log(bounds);
     let ext = boundingExtent([[bounds[0][1], bounds[0][0]], [bounds[1][1], bounds[1][0]]]);
     ext = transformExtent(ext, 'EPSG:4326', 'EPSG:3857');
     this.map.getView().fit(ext, { padding: [25, 25, 25, 25] });
@@ -242,7 +242,6 @@ const mapService = {
   },
 
   addLayers: function (layers, serviceMap, optionsMap, schemaType) {
-    console.log('addLayers');
     this.layers = layers;
     if (layers) { //* if admin has defined basemaps for this project
       layers.forEach((layer) => {
@@ -252,7 +251,6 @@ const mapService = {
             options.noWrap = true;
             options.opacity = layer.opacity;
             if (layer.schema_type === 'wms') {
-              console.log(layer);
               if (layer.queryable) {
                 options.title = layer.title;
                 dictLayersToLeaflet[layer.id] = this.addWMSLayer(layer.service, options);
@@ -341,7 +339,6 @@ const mapService = {
   },
 
   addVectorTileLayer: function (url, project_id, project_slug, featureTypes, form_filters) {
-    console.log(url, project_slug, featureTypes, form_filters);
     let format_cfg = {/*featureClass: Feature*/ };
 
     let mvt = new MVT(format_cfg);
@@ -352,7 +349,7 @@ const mapService = {
     options.format = mvt;
     let layerSource = new VectorTileSource(options);
     layerSource.setTileUrlFunction((p0) => {
-      return url+'/?tile=' + p0[0] + '/' + p0[1] + '/' + p0[2] + '&project_id=' + project_id;
+      return url+'?tile=' + p0[0] + '/' + p0[1] + '/' + p0[2] + '&project_id=' + project_id;
     });
     const styleFunction = (feature) => this.getStyle(feature, featureTypes, form_filters);
     this.mvtLayer = new VectorTileLayer({
@@ -442,25 +439,24 @@ const mapService = {
   },
 
   addFeatures: function (features, filter, addToMap = true, featureTypes) {
-    console.log(features, filter, addToMap, featureTypes);
+    console.log(addToMap);
     let drawSource = new VectorSource();
     let retour;
     // TODO verifier utilité de cette boucle et remplacer par readFeatures plutot
     features.forEach((feature) => {
-      console.log(feature);
       retour = new GeoJSON().readFeature(feature, { dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857' });
       drawSource.addFeature(retour);
-      const featureProperties = feature.properties ? feature.properties : feature;
-      const featureType = featureTypes
-        .find((ft) => ft.slug === (featureProperties.feature_type.slug || featureProperties.feature_type));
-      let filters = [];
-      if (filter) {
-        const typeCheck = filter.featureType && featureProperties.feature_type.slug === filter.featureType;
-        const statusCheck = filter.featureStatus && featureProperties.status.value === filter.featureStatus;
-        const titleCheck = filter.featureTitle && featureProperties.title.includes(filter.featureTitle);
-        filters = [typeCheck, statusCheck, titleCheck];
-      }
-      console.log(featureType, filters);
+      // const featureProperties = feature.properties ? feature.properties : feature;
+      // const featureType = featureTypes
+      //   .find((ft) => ft.slug === (featureProperties.feature_type.slug || featureProperties.feature_type));
+      // let filters = [];
+      // if (filter) {
+      //   const typeCheck = filter.featureType && featureProperties.feature_type.slug === filter.featureType;
+      //   const statusCheck = filter.featureStatus && featureProperties.status.value === filter.featureStatus;
+      //   const titleCheck = filter.featureTitle && featureProperties.title.includes(filter.featureTitle);
+      //   filters = [typeCheck, statusCheck, titleCheck];
+      // }
+      // console.log(featureType, filters);
 
     });
     const styleFunction = (feature) => this.getStyle(feature, featureTypes, filter);
@@ -554,7 +550,6 @@ const mapService = {
 
   addOverlay(loc) {
     var pos = fromLonLat(loc);
-    console.log(loc);
     var marker = new Overlay({
       position: pos, 
       positioning: OverlayPositioning.CENTER_CENTER,
diff --git a/src/store/modules/map.store.js b/src/store/modules/map.store.js
index f4276788..17947bf7 100644
--- a/src/store/modules/map.store.js
+++ b/src/store/modules/map.store.js
@@ -108,8 +108,8 @@ const map = {
       const mapDefaultViewCenter = [46, 2]; // defaultMapView.center;
       const mapDefaultViewZoom = 5; // defaultMapView.zoom;
       mapService.createMap(el, {
-        mapDefaultViewCenter,
-        mapDefaultViewZoom,
+        mapDefaultViewCenter: mapDefaultViewCenter,
+        mapDefaultViewZoom: mapDefaultViewZoom,
       });
       commit('SET_MAP', mapService.getMap());   
       mapService.addLayers(
diff --git a/src/views/Feature/FeatureEdit.vue b/src/views/Feature/FeatureEdit.vue
index 7c01064e..892a50f4 100644
--- a/src/views/Feature/FeatureEdit.vue
+++ b/src/views/Feature/FeatureEdit.vue
@@ -787,11 +787,9 @@ export default {
     onFeatureTypeLoaded() {
      
       var geomType = this.feature_type.geom_type;
-      console.log(geomType);
       editionService.addEditionControls(geomType);
       editionService.draw.on('drawend', (evt) => {
         var feature = evt.feature;
-        console.log('draw end'+feature);
         this.updateGeomField(new GeoJSON().writeGeometry(feature.getGeometry(),{ dataProjection:'EPSG:4326',featureProjection:'EPSG:3857' }));
         if (this.feature_type.geomType === 'point') {
           this.showGeoPositionBtn = false;
@@ -800,7 +798,6 @@ export default {
       });
       editionService.modify.on('modifyend', (evt) => {
         let feature = evt.features.getArray()[0];
-        console.log(feature);
         this.updateGeomField(new GeoJSON().writeGeometry(feature.getGeometry(),{ dataProjection:'EPSG:4326',featureProjection:'EPSG:3857' }));
       });
       //this.changeMobileBtnOrder();
@@ -825,7 +822,6 @@ export default {
         editionService.drawSource.clear();
       }
       if (geomFeatureJSON) {
-        console.log('updateMap');
         let retour = new GeoJSON().readFeature(geomFeatureJSON,{ dataProjection:'EPSG:4326',featureProjection:'EPSG:3857' });
         editionService.startEditFeature(retour);
        
diff --git a/src/views/Project/ProjectDetail.vue b/src/views/Project/ProjectDetail.vue
index fd982259..73d81291 100644
--- a/src/views/Project/ProjectDetail.vue
+++ b/src/views/Project/ProjectDetail.vue
@@ -74,7 +74,7 @@
               id="map"
               ref="map"
             />
-            <div 
+            <div
               id="popup" 
               class="ol-popup"
             >
@@ -377,7 +377,7 @@ export default {
         .then((response) => {
           this.CLOSE_PROJECT_MODAL();
           if (response === 'success') {
-            this.GET_PROJECT();
+            this.GET_PROJECT(this.slug);
             this.retrieveProjectInfo();
             this.DISPLAY_MESSAGE({
               comment: `Le type de signalement ${this.featureTypeToDelete.title} a bien été supprimé.`,
@@ -421,7 +421,6 @@ export default {
 
     async initMap() {
       if (this.project && this.permissions.can_view_project) {
-        console.log('initMap');
         await this.INITIATE_MAP(this.$refs.map);
         this.checkForOfflineFeature();
         let project_id = this.$route.params.slug.split('-')[0];
-- 
GitLab