changeset 2310:92b21df288e2

client: use user specific extent only on initial load The map initialization is executed each time you go from a non-map view (configuration etc.) back to the map. Thus we cannot move the map to the user specific extent everytime the map is initialized. The fix that this commit introduces is maybe a bit ugly but an ideal solution would require more work. The problem is that the map cannot be initialized with the users bounding box right away. There is already a default map extent, defined by center and zoom. This needs to be overwritten by the user specific extent.
author Markus Kottlaender <markus@intevation.de>
date Mon, 18 Feb 2019 15:38:54 +0100
parents 77adbdd24d52
children 716c0eba89a2
files client/src/components/Maplayer.vue client/src/store/map.js
diffstat 2 files changed, 33 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Maplayer.vue	Mon Feb 18 15:33:01 2019 +0100
+++ b/client/src/components/Maplayer.vue	Mon Feb 18 15:38:54 2019 +0100
@@ -53,6 +53,7 @@
   computed: {
     ...mapGetters("map", ["getLayerByName", "getVSourceByName"]),
     ...mapState("map", [
+      "initialLoad",
       "extent",
       "layers",
       "openLayersMap",
@@ -181,32 +182,35 @@
     });
     this.$store.dispatch("map/openLayersMap", map);
 
-    var currentUser = this.$store.state.user.user;
-    HTTP.get("/users/" + currentUser, {
-      headers: {
-        "X-Gemma-Auth": localStorage.getItem("token"),
-        "Content-type": "text/xml; charset=UTF-8"
-      }
-    })
-      .then(response => {
-        this.$store.commit("map/moveToBoundingBox", {
-          boundingBox: [
-            response.data.extent.x1,
-            response.data.extent.y1,
-            response.data.extent.x2,
-            response.data.extent.y2
-          ],
-          zoom: 17,
-          preventZoomOut: true
+    if (this.initialLoad) {
+      this.$store.commit("map/initialLoad", false);
+      var currentUser = this.$store.state.user.user;
+      HTTP.get("/users/" + currentUser, {
+        headers: {
+          "X-Gemma-Auth": localStorage.getItem("token"),
+          "Content-type": "text/xml; charset=UTF-8"
+        }
+      })
+        .then(response => {
+          this.$store.commit("map/moveToBoundingBox", {
+            boundingBox: [
+              response.data.extent.x1,
+              response.data.extent.y1,
+              response.data.extent.x2,
+              response.data.extent.y2
+            ],
+            zoom: 17,
+            preventZoomOut: true
+          });
+        })
+        .catch(error => {
+          const { status, data } = error.response;
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: `${status}: ${data.message || data}`
+          });
         });
-      })
-      .catch(error => {
-        const { status, data } = error.response;
-        displayError({
-          title: this.$gettext("Backend Error"),
-          message: `${status}: ${data.message || data}`
-        });
-      });
+    }
 
     // TODO make display of layers more dynamic, e.g. from a list
 
--- a/client/src/store/map.js	Mon Feb 18 15:33:01 2019 +0100
+++ b/client/src/store/map.js	Mon Feb 18 15:38:54 2019 +0100
@@ -63,6 +63,7 @@
 const init = () => {
   return {
     openLayersMap: null,
+    initialLoad: true,
     extent: {
       lat: 6155376,
       lon: 1819178,
@@ -475,6 +476,9 @@
     }
   },
   mutations: {
+    initialLoad: (state, initialLoad) => {
+      state.initialLoad = initialLoad;
+    },
     extent: (state, extent) => {
       state.extent = extent;
     },