diff --git a/src/assets/js/map-util.js b/src/assets/js/map-util.js index f673e00ca6f3b97116c71f5a9b2005222a5b612d..89acc5e36ddc956b36bb996065b2988299592335 100644 --- a/src/assets/js/map-util.js +++ b/src/assets/js/map-util.js @@ -177,7 +177,31 @@ const mapUtil = { return map; }, + addGeocoders: function(configuration){ + let geocoder; + const geocoderLabel = configuration.SELECTED_GEOCODER.PROVIDER; + if (geocoderLabel) { + const LIMIT_RESULTS = 5; + if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.ADDOK + ) { + geocoder = L.Control.Geocoder.addok({ limit: LIMIT_RESULTS }); + } else if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.PHOTON + ) { + geocoder = L.Control.Geocoder.photon(); + } else if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.NOMINATIM + ) { + geocoder = L.Control.Geocoder.nominatim(); + } + L.Control.geocoder({ + placeholder: "Chercher une adresse...", + geocoder: geocoder, + }).addTo(map); + } + }, addLayers: function (layers, serviceMap, optionsMap) { if (layers) { layers.forEach((layer) => { diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index 77549eed22ce09805c276a5c7d04469f90d4edf9..6a1babc626e9d645d8dc9b0bbbeadf4babb2b7a1 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -7,7 +7,7 @@ axios.defaults.headers.common['X-CSRFToken'] = (name => { return (value != null) ? unescape(value[1]) : null; })('csrftoken'); -const DJANGO_API_BASE = this.state.configuration.VUE_APP_DJANGO_API_BASE + const feature = { namespaced: true, @@ -101,7 +101,7 @@ const feature = { if (routeName === "editer-signalement") { axios - .put(`${DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) + .put(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) .then((response) => { if (response.status === 200 && response.data) { router.push({ @@ -118,7 +118,7 @@ const feature = { }); } else { axios - .post(`${DJANGO_API_BASE}features/`, geojson) + .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) .then((response) => { if (response.status === 201 && response.data) { dispatch("SEND_ATTACHMENTS", response.data.id) @@ -147,7 +147,7 @@ const feature = { } formdata.append("data", JSON.stringify(data)); axios - .post(`${DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) + .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) .then((response) => { if (response.status === 200 && response.data) { console.log(response, response.data) @@ -167,7 +167,7 @@ const feature = { } */ DELETE_FEATURE({ state }, feature_id) { console.log("Deleting feature:", feature_id, state) - const url=`${DJANGO_API_BASE}features/${feature_id}`; + const url=`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${feature_id}`; axios .delete(url, { }) diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index 9fd5c74a5e8e9a8743f1f9b0f2098c9bb3260022..fd26f608b8873ef298864d7c8176b3c61b7ece54 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -1,5 +1,6 @@ <template> <div v-frag> + <script type="application/javascript" :src="baseUrl+'/resources/leaflet-control-geocoder-1.13.0/Control.Geocoder.js'"></script> <div class="fourteen wide column"> <h1 v-if="feature && currentRouteName === 'editer-signalement'"> Mise à jour du signalement "{{ feature.title || feature.feature_id }}" @@ -266,6 +267,7 @@ export default { return { map: null, feature_type:null, + baseUrl:this.$store.state.configuration.BASE_URL, file: null, showGeoRef: false, showGeoPositionBtn: true, @@ -877,6 +879,11 @@ export default { ); this.onFeatureTypeLoaded(); this.initExtraForms(); + + setTimeout( + function () { + mapUtil.addGeocoders(this.$store.state.configuration); + }.bind(this), 1000); }) diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index 8d9572aa257f844f3a6c8e16514d1b047fd5724c..daed7b508e0c52872e51ee77c78c8b847320dd45 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -233,7 +233,7 @@ {{ feature.properties.updated_on }} </td> <td class="center" v-if="user"> - {{ feature.properties.display_creator }} + {{ feature.properties.creator.username }} </td> </tr> <tr v-if="getFilteredFeatures().length === 0" class="odd"> @@ -326,8 +326,6 @@ <script> import { mapGetters, mapState } from "vuex"; - -import L from "leaflet"; import { mapUtil } from "@/assets/js/map-util.js"; import SidebarLayers from "@/components/map-layers/SidebarLayers"; import Dropdown from "@/components/Dropdown.vue"; @@ -459,8 +457,8 @@ export default { bProp=b.properties.updated_on; } else if(this.sort.column=='display_creator') { - aProp=a.properties.display_creator; - bProp=b.properties.display_creator; + aProp=a.properties.creator.username; + bProp=b.properties.creator.username; } //ascending @@ -595,37 +593,6 @@ export default { ...new Set(this.geojsonFeatures.map((el) => el.properties.feature_type.title)), //* use Set to eliminate duplicate values ]; }, - addGeocoders(){ - let geocoder; - - // Get the settings.py variable SELECTED_GEOCODER_PROVIDER. This way avoids XCC attacks - const geocoderLabel = - this.$store.state.configuration.SELECTED_GEOCODER.PROVIDER; - if (geocoderLabel) { - const LIMIT_RESULTS = 5; - if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.ADDOK - ) { - geocoder = L.Control.Geocoder.addok({ limit: LIMIT_RESULTS }); - } else if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.PHOTON - ) { - geocoder = L.Control.Geocoder.photon(); - } else if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.NOMINATIM - ) { - geocoder = L.Control.Geocoder.nominatim(); - } - - L.Control.geocoder({ - placeholder: "Chercher une adresse...", - geocoder: geocoder, - }).addTo(this.map); - } - }, }, created() { @@ -659,7 +626,6 @@ export default { }); // --------- End sidebar events ---------- - console.log(this.$store.state.map.geojsonFeatures); if(this.$store.state.map.geojsonFeatures){ this.loadFeatures(this.$store.state.map.geojsonFeatures); } @@ -678,14 +644,11 @@ export default { }); } - setTimeout( function () { - this.addGeocoders(); - }.bind(this), 1000) + mapUtil.addGeocoders(this.$store.state.configuration); + }.bind(this), 1000); - - }, }; </script>