From 87d6375974bc688c80fb9605ff0e3e2eec67b0ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Wed, 6 Oct 2021 10:36:30 +0200
Subject: [PATCH] add padding to fitBounds

---
 src/views/feature/Feature_detail.vue |  2 +-
 src/views/feature/Feature_edit.vue   |  2 +-
 src/views/feature/Feature_list.vue   | 10 ++++++++--
 src/views/project/Project_detail.vue |  4 +++-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue
index c1a5260d..5cdbeaac 100644
--- a/src/views/feature/Feature_detail.vue
+++ b/src/views/feature/Feature_detail.vue
@@ -599,7 +599,7 @@ export default {
           if (feature) {
             const currentFeature = [feature];
             const featureGroup = mapUtil.addFeatures(currentFeature);
-            mapUtil.getMap().fitBounds(featureGroup.getBounds());
+            mapUtil.getMap().fitBounds(featureGroup.getBounds(), { padding: [25, 25] });
           }
         })
         .catch((error) => {
diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue
index bf455ac4..65eb4484 100644
--- a/src/views/feature/Feature_edit.vue
+++ b/src/views/feature/Feature_edit.vue
@@ -838,7 +838,7 @@ export default {
         } else if (geomType === "polygon") {
           L.polygon(geomJSON.coordinates).addTo(this.drawnItems);
         }
-        this.map.fitBounds(this.drawnItems.getBounds());
+        this.map.fitBounds(this.drawnItems.getBounds(), { padding: [25, 25] });
       } else {
         this.map.setView(
           this.$store.state.configuration.DEFAULT_MAP_VIEW.center,
diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue
index 875f2688..32a31531 100644
--- a/src/views/feature/Feature_list.vue
+++ b/src/views/feature/Feature_list.vue
@@ -603,7 +603,9 @@ export default {
       this.featureGroup.clearLayers();
       this.featureGroup = mapUtil.addFeatures(features, {});
       if (features.length > 0) {
-        mapUtil.getMap().fitBounds(this.featureGroup.getBounds());
+        mapUtil
+          .getMap()
+          .fitBounds(this.featureGroup.getBounds(), { padding: [25, 25] });
       }
     },
 
@@ -639,7 +641,9 @@ export default {
         (this.lat === "" || this.lng === "" || this.zoom === "") &&
         this.geojsonFeatures.length > 0
       ) {
-        mapUtil.getMap().fitBounds(this.featureGroup.getBounds());
+        mapUtil
+          .getMap()
+          .fitBounds(this.featureGroup.getBounds(), { padding: [25, 25] });
       }
       this.form.type.choices = [
         //* converting Set to an Array with spread "..."
@@ -666,6 +670,8 @@ export default {
     var mapDefaultViewZoom =
       this.$store.state.configuration.DEFAULT_MAP_VIEW.zoom;
 
+    console.log("MAP : ", document.getElementById("map"));
+
     this.map = mapUtil.createMap({
       zoom: this.zoom,
       lat: this.lat,
diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue
index ddff358b..b7fbff02 100644
--- a/src/views/project/Project_detail.vue
+++ b/src/views/project/Project_detail.vue
@@ -589,7 +589,9 @@ export default {
           const features = response.data.features;
           const featureGroup = mapUtil.addFeatures(features);
           if (featureGroup && featureGroup.getLayers().length > 0) {
-            mapUtil.getMap().fitBounds(featureGroup.getBounds());
+            mapUtil
+              .getMap()
+              .fitBounds(featureGroup.getBounds(), { padding: [25, 25] });
             self.$store.commit("map/SET_GEOJSON_FEATURES", features);
           }
         })
-- 
GitLab