diff --git a/src/assets/js/map-util.js b/src/assets/js/map-util.js index eab2239b783a756ba2d1fbc2f1e296d1db03495f..3c00b6df99f07e8c38df0e25701ec5539acc2781 100644 --- a/src/assets/js/map-util.js +++ b/src/assets/js/map-util.js @@ -298,24 +298,23 @@ const mapUtil = { // Redraw the layers this.addLayers(layers); }, - // eslint-disable-next-line no-unused-vars + + retrieveFeatureColor: function (featureType, properties) { + if (featureType && featureType.colors_style && featureType.colors_style.custom_field_name) { + const currentValue = properties[featureType.colors_style.custom_field_name]; + const colorStyle = featureType.colors_style.colors[currentValue]; + return colorStyle ? colorStyle : featureType.color + } + }, + addVectorTileLayer: function (url, project_slug, featureTypes, form_filters) { layerMVT = L.vectorGrid.protobuf(url, { vectorTileLayerStyles: { - "default": function (properties, zoom) { - // console.log(properties); - - let featureType = featureTypes.find((x) => x.slug.split('-')[0] === '' + properties.feature_type_id); - let color = featureType.color; - if (featureType.colors_style && featureType.colors_style.custom_field_name) { - let currentValue = properties[featureType.colors_style.custom_field_name]; - let colorValue = featureType.colors_style.colors[currentValue]; - if (colorValue) { - color = colorValue; - } + "default": (properties) => { + const featureType = featureTypes.find((x) => x.slug.split('-')[0] === '' + properties.feature_type_id); + const color = this.retrieveFeatureColor(featureType, properties) - } - let hiddenStyle = ({ + const hiddenStyle = ({ radius: 0, fillOpacity: 0.5, weight: 0, @@ -347,21 +346,19 @@ const mapUtil = { fill: true, color: color, }); - }, }, // subdomains: "0123", // key: 'abcdefghi01234567890', interactive: true, - maxNativeZoom: 14, + maxNativeZoom: 18, getFeatureId: function (f) { return f.properties.id; } }); - let self = this; - layerMVT.on('click', function (e) { // The .on method attaches an event handler - console.log("click on mvt", e); - const popupContent = self._createContentPopup(e.layer, featureTypes, project_slug); + layerMVT.on('click', (e) => { // The .on method attaches an event handler + console.log("e", e); + const popupContent = this._createContentPopup(e.layer, featureTypes, project_slug); L.popup() .setContent(popupContent) .setLatLng(e.latlng) @@ -372,16 +369,12 @@ const mapUtil = { }, addFeatures: function (features, filter, addToMap = true, featureTypes) { - let featureGroup = new L.FeatureGroup(); + const featureGroup = new L.FeatureGroup(); features.forEach((feature) => { - let featureType = featureTypes.find((x) => x.slug === feature.properties.feature_type.slug); - if (!featureType) { - featureType = feature.properties.feature_type; - } + const featureType = featureTypes.find((ft) => ft.slug === (feature.properties.feature_type.slug || feature.properties.feature_type)); let filters = []; - if (filter) { const typeCheck = filter.featureType && feature.properties.feature_type.slug === filter.featureType; const statusCheck = filter.featureStatus && feature.properties.status.value === filter.featureStatus; @@ -390,30 +383,20 @@ const mapUtil = { } if (!filter || !Object.values(filter).some(val => val) || Object.values(filter).some(val => val) && filters.length && filters.every(val => val !== false)) { - const geomJSON = flip(feature.geometry); - const popupContent = this._createContentPopup(feature); // Look for a custom field let customField; let customFieldOption; - if (Object.keys(feature.properties).some(el => featureType.customfield_set.map(e => e.name).includes(el))) { + if (Object.keys(feature.properties).some(el => featureType.customfield_set && featureType.customfield_set.map(e => e.name).includes(el))) { customField = Object.keys(feature.properties).filter(el => featureType.customfield_set.map(e => e.name).includes(el)); customFieldOption = feature.properties[customField[0]]; } + const color = this.retrieveFeatureColor(featureType, feature.properties) || feature.properties.color; - let color; - if (customFieldOption && featureType.colors_style) { - color = featureType.colors_style.value.colors[customFieldOption].value - } else { - color = feature.properties.color; - } - if (color == undefined) { - color = featureType.color; - } if (geomJSON.type === 'Point') { - if (customFieldOption && featureType.colors_style) { + if (customFieldOption && featureType.colors_style && featureType.colors_style.value && featureType.colors_style.value.icons) { const iconHTML = ` <i class="fas fa-${featureType.colors_style.value.icons[customFieldOption]} fa-2x" @@ -483,9 +466,9 @@ const mapUtil = { let feature_url = feature.properties.feature_url; if (featureTypes) { // => VectorTile feature_type = featureTypes.find((x) => x.slug.split('-')[0] === '' + feature.properties.feature_type_id); - status = statusList.find((x) => x.value == feature.properties.status).name; + status = statusList.find((x) => x.value === feature.properties.status).name; date_maj = formatDate(new Date(feature.properties.updated_on)); - feature_type_url = '/geocontrib/projet/' + project_slug + '/type_signalement/' + feature_type.slug + '/'; + feature_type_url = '/geocontrib/projet/' + project_slug + '/type-signalement/' + feature_type.slug + '/'; feature_url = feature_type_url + 'signalement/' + feature.properties.feature_id + '/'; //status=feature.properties.status; } else { @@ -520,4 +503,4 @@ const mapUtil = { }, }; -export { mapUtil } \ No newline at end of file +export { mapUtil } diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index 40e10c25703b2a6db077fb1bf2736aa092422899..529584b5452c7d94e04a0860afeda65010aacce8 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -916,7 +916,6 @@ export default { }, updateGeomField(newGeom) { - //this.geometry = newGeom; this.form.geom.value = newGeom.geometry; this.updateStore(); }, @@ -933,19 +932,16 @@ export default { mapDefaultViewZoom, }); const currentFeatureId = this.$route.params.slug_signal; - setTimeout( - function () { - let project_id = this.$route.params.slug.split("-")[0]; - const mvtUrl = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}features.mvt/?tile={z}/{x}/{y}&project_id=${project_id}`; - - mapUtil.addVectorTileLayer( - mvtUrl, - this.$route.params.slug, - this.$store.state.feature_type.feature_types - ); - }.bind(this), - 1000 - ); + setTimeout(() => { + let project_id = this.$route.params.slug.split("-")[0]; + const mvtUrl = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}features.mvt/?tile={z}/{x}/{y}&project_id=${project_id}`; + + mapUtil.addVectorTileLayer( + mvtUrl, + this.$route.params.slug, + this.$store.state.feature_type.feature_types + ); + }, 1000); const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/?feature_type__slug=${this.$route.params.slug_type_signal}&output=geojson`; axios .get(url) @@ -1029,12 +1025,9 @@ export default { this.onFeatureTypeLoaded(); this.initExtraForms(this.feature); - setTimeout( - function () { - mapUtil.addGeocoders(this.$store.state.configuration); - }.bind(this), - 1000 - ); + setTimeout(() => { + mapUtil.addGeocoders(this.$store.state.configuration); + }, 1000); }); }, diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue index d4890fe479c76744e7ae01d8c223e65693f11176..bb69a28bbc5351239cb9382aa181bfb36fe91ff4 100644 --- a/src/views/feature_type/Feature_type_edit.vue +++ b/src/views/feature_type/Feature_type_edit.vue @@ -245,6 +245,10 @@ export default { "archived_on", "deletion_on", "feature_type", + "display_creator", + "display_last_editor", + "project", + "creator", ], }; }, diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index e866ac9cde74c9360d6b95906e846170198f9a7d..56b7bd35dd3439318ba4ea878f02b41054b9c156 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -236,6 +236,7 @@ v-if=" project && type.is_editable && + type.geom_type === 'point' && permissions && permissions.can_create_feature_type && isOffline() != true