diff --git a/src/services/feature-api.js b/src/services/feature-api.js index c01a7bce1872e25abb260bfba2bdd5abade5bf2a..3618c8687cd360acd707e991b6f8bd050e5768c7 100644 --- a/src/services/feature-api.js +++ b/src/services/feature-api.js @@ -12,7 +12,11 @@ const featureAPI = { response.status === 200 && response.data ) { - return response.data; + const bbox = response.data; + return [ + [bbox[2], bbox[3]], + [bbox[0], bbox[1]], + ]; } else { return null; } diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index 23a1d44323e64b539ad2993262b8f6c40784f400..408091df72d8955bc4a332ddd4fef83f14128038 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -377,11 +377,7 @@ export default { .getFeaturesBbox(this.project.slug, queryParams) .then((bbox) => { if (bbox) { - const bounds = [ - [bbox[2], bbox[3]], - [bbox[0], bbox[1]], - ]; - mapUtil.getMap().fitBounds(bounds, { padding: [25, 25] }); + mapUtil.getMap().fitBounds(bbox, { padding: [25, 25] }); } }); }, diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index 2e7066dd2d7090c0176df277e063a6f34fb0cc60..070b25508651a827577bb4dbdc60ef20f16e58ff 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -395,7 +395,8 @@ > <div class="content"> <div> - <router-link :to="getRouteUrl(item.related_feature.feature_url)" + <router-link + :to="getRouteUrl(item.related_feature.feature_url)" >"{{ item.comment }}"</router-link > </div> @@ -539,14 +540,9 @@ import frag from "vue-frag"; import { mapUtil } from "@/assets/js/map-util.js"; import { mapGetters, mapState } from "vuex"; import projectAPI from "@/services/project-api"; +import featureAPI from "@/services/feature-api"; -import axios from '@/axios-client.js'; - -// axios.defaults.headers.common['X-CSRFToken'] = (name => { -// var re = new RegExp(name + "=([^;]+)"); -// var value = re.exec(document.cookie); -// return (value !== null) ? unescape(value[1]) : null; -// })('csrftoken'); +import axios from "@/axios-client.js"; export default { name: "Project_details", @@ -580,7 +576,7 @@ export default { is_suscriber: false, tempMessage: null, featureTypeLoading: true, - featuresLoading: true + featuresLoading: true, }; }, @@ -605,8 +601,8 @@ export default { refreshId() { return "?ver=" + Math.random(); }, - getRouteUrl(url){ - return '/'+url.replace(this.$store.state.configuration.BASE_URL,''); // remove duplicate /geocontrib + getRouteUrl(url) { + return "/" + url.replace(this.$store.state.configuration.BASE_URL, ""); // remove duplicate /geocontrib }, isOffline() { return navigator.onLine === false; @@ -730,7 +726,6 @@ export default { initMap() { if (this.project && this.permissions.can_view_project) { this.$store.dispatch("map/INITIATE_MAP", this.$refs.map); - const url = `${this.API_BASE_URL}projects/${this.$route.params.slug}/feature/?output=geojson`; this.checkForOfflineFeature(); let project_id = this.$route.params.slug.split("-")[0]; const mvtUrl = `${this.API_BASE_URL}features.mvt/?tile={z}/{x}/{y}&project_id=${project_id}`; @@ -739,34 +734,22 @@ export default { this.$route.params.slug, this.$store.state.feature_type.feature_types ); - axios - .get(url) - .then((response) => { - let features = response.data.features; - this.arraysOffline.forEach( - (x) => (x.geojson.properties.color = "red") - ); - features = response.data.features.concat( - this.arraysOffline.map((x) => x.geojson) - ); - const featureGroup = mapUtil.addFeatures( - features, - {}, - true, - this.$store.state.feature_type.feature_types - ); - if (featureGroup && featureGroup.getLayers().length > 0) { - mapUtil - .getMap() - .fitBounds(featureGroup.getBounds(), { padding: [25, 25] }); - this.$store.commit("map/SET_GEOJSON_FEATURES", features); - } else { - this.$store.commit("map/SET_GEOJSON_FEATURES", []); + this.arraysOffline.forEach((x) => (x.geojson.properties.color = "red")); + const features = this.arraysOffline.map((x) => x.geojson); + mapUtil.addFeatures( + features, + {}, + true, + this.$store.state.feature_type.feature_types + ); + + featureAPI + .getFeaturesBbox(this.project.slug) + .then((bbox) => { + if (bbox) { + mapUtil.getMap().fitBounds(bbox, { padding: [25, 25] }); } - }) - .catch((error) => { - throw error; }); } }, @@ -782,14 +765,14 @@ export default { }, mounted() { - this.$store.dispatch('GET_PROJECT_INFO', this.slug) - .then(() => { - this.featureTypeLoading = false; - setTimeout(this.initMap, 1000); - }); - this.$store.dispatch('feature/GET_PROJECT_FEATURES', { - project_slug: this.slug - }) + this.$store.dispatch("GET_PROJECT_INFO", this.slug).then(() => { + this.featureTypeLoading = false; + setTimeout(this.initMap, 1000); + }); + this.$store + .dispatch("feature/GET_PROJECT_FEATURES", { + project_slug: this.slug, + }) .then(() => { this.featuresLoading = false; });