diff --git a/src/services/map-service.js b/src/services/map-service.js index a55a86cf4d4e25e08cfbca2de5eabc7d74ee1ef5..be9485cd98c00785705b6abd9ac157cb56dbd061 100644 --- a/src/services/map-service.js +++ b/src/services/map-service.js @@ -379,75 +379,80 @@ const mapService = { const properties = feature.getProperties(); let featureType; // GeoJSON - if(properties.feature_type){ + if(properties && properties.feature_type){ featureType = featureTypes .find((ft) => ft.slug === (properties.feature_type.slug || properties.feature_type)); } else { //MVT featureType = featureTypes.find((x) => x.slug.split('-')[0] === '' + properties.feature_type_id); } - const color = this.retrieveFeatureColor(featureType, properties); - const colorValue = + + if (featureType) { + const color = this.retrieveFeatureColor(featureType, properties); + const colorValue = color.value && color.value.length ? color.value : typeof color === 'string' && color.length ? color : '#000000'; - const rgbaColor = asArray(colorValue); - //* set opacity from feature-type colors_style - rgbaColor[3] = this.retrieveFeatureOpacity(featureType, properties) || 0.5;//opacity - const hiddenStyle = new Style(); - - const defaultStyle = new Style( - { - image: new Circle({ - fill: new Fill( - { - color: rgbaColor, - }, - ), + const rgbaColor = asArray(colorValue); + //* set opacity from feature-type colors_style + rgbaColor[3] = this.retrieveFeatureOpacity(featureType, properties) || 0.5;//opacity + + const defaultStyle = new Style( + { + image: new Circle({ + fill: new Fill( + { + color: rgbaColor, + }, + ), + stroke: new Stroke( + { + color: colorValue, + width: 2, + }, + ), + radius: 5, + }), stroke: new Stroke( { color: colorValue, width: 2, }, ), - radius: 5, - }), - stroke: new Stroke( - { - color: colorValue, - width: 2, - }, - ), - fill: new Fill( - { - color: rgbaColor, - }, - ), - }, - ); - - // Filtre sur le feature type - if(formFilters){ - if (formFilters.type && formFilters.type.selected) { - if (featureType.title !== formFilters.type.selected) { - return hiddenStyle; + fill: new Fill( + { + color: rgbaColor, + }, + ), + }, + ); + + const hiddenStyle = new Style(); // hide the feature to apply filters + // Filtre sur le feature type + if(formFilters){ + if (formFilters.type && formFilters.type.selected) { + if (featureType.title !== formFilters.type.selected) { + return hiddenStyle; + } } - } - // Filtre sur le statut - if (formFilters.status && formFilters.status.selected.value) { - if (properties.status !== formFilters.status.selected.value) { - return hiddenStyle; + // Filtre sur le statut + if (formFilters.status && formFilters.status.selected.value) { + if (properties.status !== formFilters.status.selected.value) { + return hiddenStyle; + } } - } - // Filtre sur le titre - if (formFilters.title) { - if (!properties.title.toLowerCase().includes(formFilters.title.toLowerCase())) { - return hiddenStyle; + // Filtre sur le titre + if (formFilters.title) { + if (!properties.title.toLowerCase().includes(formFilters.title.toLowerCase())) { + return hiddenStyle; + } } } + return defaultStyle; + } else { + console.error('No corresponding featureType found.'); + return; } - - return defaultStyle; }, addFeatures: function (features, filter, featureTypes, addToMap = true) {