Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-1046: Fallback to default icon set if not found #1097

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/modules/drawing/DrawingModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useKmlDataManagement from '@/modules/drawing/useKmlDataManagement.composa
import { FeatureInfoPositions } from '@/store/modules/ui.store'
import { getIcon, parseIconUrl } from '@/utils/kmlUtils'
import log from '@/utils/logging'
import WarningMessage from '@/utils/WarningMessage.class'

const dispatcher = { dispatcher: 'DrawingModule.vue' }

Expand Down Expand Up @@ -88,7 +89,16 @@ watch(availableIconSets, () => {
const feature = drawingLayer.getSource()?.getFeatureById(featureId)?.get('editableFeature')
if (feature?.icon) {
const iconArgs = parseIconUrl(feature.icon.imageURL)
const icon = getIcon(iconArgs, null /*iconStyle*/, availableIconSets.value)
const icon = getIcon(iconArgs, null /*iconStyle*/, availableIconSets.value, () => {
store.dispatch('addWarnings', {
warnings: [
new WarningMessage('kml_icon_set_not_found', {
iconSetName: iconArgs.set,
}),
],
dispatcher: 'kmlUtils.js',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong dispatcher use the one on top of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this one is dispatched from kmlUtils.js as a callback. I follow the same approach as in https://github.com/geoadmin/web-mapviewer/blob/develop/src/modules/map/components/openlayers/OpenLayersKMLLayer.vue#L86-L112

or should I change that one too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no, the callback is defined outside of kmlUtils.js and the caller is the file that call the helper function in kmlUtils.js.
I think for clarity it might make more sense to keep the file that contains the definition as dispatcher. This dispatcher can be useful for debugging so you will first look in kmlUtils.js and it will be then hard to find the dispatch in this file.

})
})
if (icon) {
feature.icon = icon
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
"kml_gpx_file_empty": "Die KML/GPX-Datei ist leer",
"kml_icon_url_cors_issue": "Die KML-Datei „{layerName}“ enthält Symbol(e) mit der URL {url}, die keine CORS-Unterstützung bietet! Bitte wenden Sie sich an den Administrator dieser URL, um die Unterstützung für CORS hinzuzufügen.",
"kml_icon_url_scheme_http": "Die KML\" {layerName}\" enthält Symbole mit der {url}-URL in http. Ab dem 31. Januar 2025 wird die Unterstützung für diese Ressourcen eingestellt und nur https-Ressourcen werden unterstützt. Weitere Informationen finden Sie unter https://www.geo.admin.ch/de/informationen-ssl-zertifikate-http-protokoll",
"kml_icon_set_not_found": "Iconset \"{iconSetName}\" nicht gefunden, Fallback auf Standardsymbol",
"kml_no_text_elements": "Information: Die Labels werden nicht gespeichert",
"kml_style_default": "Standard",
"kml_style_geoadmin": "GeoAdmin",
Expand Down
1 change: 1 addition & 0 deletions src/modules/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
"kml_gpx_file_empty": "KML/GPX file is empty",
"kml_icon_url_cors_issue": "The KML \"{layerName}\" contains icon(s) with URL {url} that doesn't support CORS! Please contact the administrator of this URL to add support for CORS.",
"kml_icon_url_scheme_http": "The {layerName} KML contains icons with the URL {url} in http. As of January 31, 2025, support for these resources will be discontinued, and only https resources will be supported. For more information, see https://www.geo.admin.ch/en/important-imformation-ssl-certificates-http-protocols",
"kml_icon_set_not_found": "Iconset \"{iconSetName}\" not found, fallback to default icon",
"kml_no_text_elements": "Information: The labels won't be saved",
"kml_style_default": "default",
"kml_style_geoadmin": "GeoAdmin",
Expand Down
1 change: 1 addition & 0 deletions src/modules/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
"kml_gpx_file_empty": "Le fichier KML/GPX est vide",
"kml_icon_url_cors_issue": "Le KML « {layerName} » contient des icônes avec l'URL {url} qui ne supporte pas CORS ! Veuillez contacter l'administrateur de cette URL pour avoir du support de CORS.",
"kml_icon_url_scheme_http": "Le KML « {layerName} » contient des icônes avec l'URL {url} en http. A compter du 31 janvier 2025, le support pour ces ressources sera arrêté, et seules les ressources en https seront supportées. Pour plus d'informations, consultez https://www.geo.admin.ch/fr/informations-importantes-certification-ssl-protocole-http",
"kml_icon_set_not_found": "L'ensemble d'icônes « {iconSetName} » n'a pas été trouvé, retour à l'icône par défaut",
"kml_no_text_elements": "Information: Les étiquettes ne seront pas sauvées",
"kml_style_default": "défaut",
"kml_style_geoadmin": "GeoAdmin",
Expand Down
1 change: 1 addition & 0 deletions src/modules/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
"kml_gpx_file_empty": "Il file KML/GPX è vuoto",
"kml_icon_url_cors_issue": "Il KML “{layerName}” contiene icone con l'URL {url} che non supporta CORS! Contattare l'amministratore di questo URL per aggiungere il supporto per CORS.",
"kml_icon_url_scheme_http": "Il KML {layerName} contiene icone con l'URL {url} in http. A partire dal 31 gennaio 2025, il supporto per queste risorse sarà terminato e saranno supportate solo le risorse https. Per maggiori informazioni, vedere https://www.geo.admin.ch/it/informazioni-importanti-crtificati-ssl-protocollo-http",
"kml_icon_set_not_found": "Iconset \"{iconSetName}\" non trovato, torna all'icona predefinita",
"kml_no_text_elements": "Informazione: le etichette non saranno salvate",
"kml_style_default": "predefinito",
"kml_style_geoadmin": "GeoAdmin",
Expand Down
1 change: 1 addition & 0 deletions src/modules/i18n/locales/rm.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
"kml_gpx_file_empty": "La datoteca KML/GPX è vegnida empruva",
"kml_icon_url_cors_issue": "Il KML \"{layerName}\" cuntegna icona(s) cun URL {url} che na po nagin sustegnair CORS! As drizzai p.pl. a l'administratura da quella URL per agiuntar il sustegn dal CORS.",
"kml_icon_url_scheme_http": "Il MPML \" {layerName}\" cuntegna iconas cun il URL {–url} en il program da http. A partir dals 31 da schaner 2025 vegn il sustegn per questas resursas franà, i vegn rapportà mo pli da las resursas da https. Ulteriuras infurmaziuns sin https://www.geo.admin.ch/de/informationen-ssl-zertifikate-http-protokoll",
"kml_icon_set_not_found": "Iconset \"{iconSetName}\" na arakhlăs pes, palpale k-o defaultno ikona",
"kml_no_text_elements": " Infurmaziun: ils labels na vegnan betg memorisads",
"kml_style_default": "Standard",
"kml_style_geoadmin": "GeoAdmin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export default {
},
mounted() {
const iconSetNameToLookup = this.feature?.icon ? this.feature.icon.iconSetName : 'default'
this.currentIconSet = this.iconSets.find((iconSet) => iconSet.name === iconSetNameToLookup)
this.currentIconSet =
this.iconSets.find((iconSet) => iconSet.name === iconSetNameToLookup) ||
this.iconSets.find((iconSet) => iconSet.name === 'default')
},
methods: {
/**
Expand Down
8 changes: 6 additions & 2 deletions src/utils/kmlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function generateIconFromStyle(iconStyle, iconArgs) {
* @param {DrawingIconSet[] | null} availableIconSets
* @returns {DrawingIcon | null} Return the drawing icon or null in case of non geoadmin icon
*/
export function getIcon(iconArgs, iconStyle, availableIconSets) {
export function getIcon(iconArgs, iconStyle, availableIconSets, iconNotFoundCallback = null) {
if (!iconArgs) {
return null
}
Expand All @@ -299,7 +299,11 @@ export function getIcon(iconArgs, iconStyle, availableIconSets) {
}
const iconSet = availableIconSets.find((drawingIconSet) => drawingIconSet.name === iconArgs.set)
if (!iconSet) {
log.error(`Iconset ${iconArgs.set} not found, fallback to default icon`)
if (iconNotFoundCallback) {
iconNotFoundCallback()
} else {
log.error(`Iconset ${iconArgs.set} not found, fallback to default icon`)
}
return generateIconFromStyle(iconStyle, iconArgs)
}

Expand Down
Loading