From 9b98de9974586f544eaa9fcbfd4186829b2fc85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Wed, 13 Oct 2021 11:31:42 +0200 Subject: [PATCH] prevent featureGeojson not updated if no features existing for project --- src/views/feature/Feature_list.vue | 17 +++++++++-------- src/views/project/Project_detail.vue | 5 +++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index 79b7f134..3756c3da 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -331,10 +331,10 @@ export default { }, onFilterChange() { - var features = this.filteredFeatures; - this.featureGroup.clearLayers(); - this.featureGroup = mapUtil.addFeatures(features, {}); - if (features.length > 0) { + if (this.featureGroup) { + const features = this.filteredFeatures; + this.featureGroup.clearLayers(); + this.featureGroup = mapUtil.addFeatures(features, {}); mapUtil .getMap() .fitBounds(this.featureGroup.getBounds(), { padding: [25, 25] }); @@ -365,15 +365,16 @@ export default { }); // --------- End sidebar events ---------- - if (this.$store.state.map.geojsonFeatures) { - this.loadFeatures(this.$store.state.map.geojsonFeatures); - } else { + if (this.features && this.features.length > 0) { + //* features are updated consistently, then if features exists, we can fetch the geojson version const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/?output=geojson`; this.featureLoading = true; axios .get(url) .then((response) => { - this.loadFeatures(response.data.features); + if (response.status === 200 && response.data.features.length > 0) { + this.loadFeatures(response.data.features); + } this.featureLoading = false; }) .catch((error) => { diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index 50879543..b7718812 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -590,7 +590,6 @@ export default { if (this.project && this.permissions.can_view_project) { this.$store.dispatch("map/INITIATE_MAP"); const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/?output=geojson`; - let self = this; axios .get(url) .then((response) => { @@ -600,7 +599,9 @@ export default { mapUtil .getMap() .fitBounds(featureGroup.getBounds(), { padding: [25, 25] }); - self.$store.commit("map/SET_GEOJSON_FEATURES", features); + this.$store.commit("map/SET_GEOJSON_FEATURES", features); + } else { + this.$store.commit("map/SET_GEOJSON_FEATURES", []); } }) .catch((error) => { -- GitLab