forked from MapComplete/MapComplete
		
	fix: broken titleIcons (fix #1344)
This commit is contained in:
		
							parent
							
								
									3aba46ce32
								
							
						
					
					
						commit
						bdcf8a2601
					
				
					 6 changed files with 50 additions and 30 deletions
				
			
		|  | @ -7,22 +7,22 @@ import { | |||
|     FirstOf, | ||||
|     Fuse, | ||||
|     On, | ||||
|     SetDefault | ||||
| } from "./Conversion"; | ||||
| import { LayerConfigJson } from "../Json/LayerConfigJson"; | ||||
| import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"; | ||||
| import { Utils } from "../../../Utils"; | ||||
| import RewritableConfigJson from "../Json/RewritableConfigJson"; | ||||
| import SpecialVisualizations from "../../../UI/SpecialVisualizations"; | ||||
| import Translations from "../../../UI/i18n/Translations"; | ||||
| import { Translation } from "../../../UI/i18n/Translation"; | ||||
| import tagrenderingconfigmeta from "../../../assets/tagrenderingconfigmeta.json"; | ||||
| import { AddContextToTranslations } from "./AddContextToTranslations"; | ||||
| import FilterConfigJson from "../Json/FilterConfigJson"; | ||||
| import predifined_filters from "../../../assets/layers/filters/filters.json"; | ||||
| import { TagConfigJson } from "../Json/TagConfigJson"; | ||||
| import PointRenderingConfigJson from "../Json/PointRenderingConfigJson"; | ||||
| import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"; | ||||
|     SetDefault, | ||||
| } from "./Conversion" | ||||
| import { LayerConfigJson } from "../Json/LayerConfigJson" | ||||
| import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson" | ||||
| import { Utils } from "../../../Utils" | ||||
| import RewritableConfigJson from "../Json/RewritableConfigJson" | ||||
| import SpecialVisualizations from "../../../UI/SpecialVisualizations" | ||||
| import Translations from "../../../UI/i18n/Translations" | ||||
| import { Translation } from "../../../UI/i18n/Translation" | ||||
| import tagrenderingconfigmeta from "../../../assets/tagrenderingconfigmeta.json" | ||||
| import { AddContextToTranslations } from "./AddContextToTranslations" | ||||
| import FilterConfigJson from "../Json/FilterConfigJson" | ||||
| import predifined_filters from "../../../assets/layers/filters/filters.json" | ||||
| import { TagConfigJson } from "../Json/TagConfigJson" | ||||
| import PointRenderingConfigJson from "../Json/PointRenderingConfigJson" | ||||
| import LineRenderingConfigJson from "../Json/LineRenderingConfigJson" | ||||
| 
 | ||||
| class ExpandFilter extends DesugaringStep<LayerConfigJson> { | ||||
|     private static readonly predefinedFilters = ExpandFilter.load_filters() | ||||
|  | @ -99,12 +99,13 @@ class ExpandTagRendering extends Conversion< | |||
|     private readonly _options: { | ||||
|         /* If true, will copy the 'osmSource'-tags into the condition */ | ||||
|         applyCondition?: true | boolean | ||||
|         noHardcodedStrings?: false | boolean | ||||
|     } | ||||
| 
 | ||||
|     constructor( | ||||
|         state: DesugaringContext, | ||||
|         self: LayerConfigJson, | ||||
|         options?: { applyCondition?: true | boolean } | ||||
|         options?: { applyCondition?: true | boolean; noHardcodedStrings?: false | boolean } | ||||
|     ) { | ||||
|         super( | ||||
|             "Converts a tagRenderingSpec into the full tagRendering, e.g. by substituting the tagRendering by the shared-question", | ||||
|  | @ -130,7 +131,7 @@ class ExpandTagRendering extends Conversion< | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private lookup(name: string): TagRenderingConfigJson[] { | ||||
|     private lookup(name: string): TagRenderingConfigJson[] | undefined { | ||||
|         const direct = this.directLookup(name) | ||||
|         if (direct === undefined) { | ||||
|             return undefined | ||||
|  | @ -159,9 +160,9 @@ class ExpandTagRendering extends Conversion< | |||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Looks up a tagRendering based on the name. | ||||
|      * Looks up a tagRendering or group of tagRenderings based on the name. | ||||
|      */ | ||||
|     private directLookup(name: string): TagRenderingConfigJson[] { | ||||
|     private directLookup(name: string): TagRenderingConfigJson[] | undefined { | ||||
|         const state = this._state | ||||
|         if (state.tagRenderings.has(name)) { | ||||
|             return [state.tagRenderings.get(name)] | ||||
|  | @ -192,7 +193,7 @@ class ExpandTagRendering extends Conversion< | |||
|             const id_ = id.substring(1) | ||||
|             matchingTrs = layerTrs.filter((tr) => tr.group === id_ || tr.labels?.indexOf(id_) >= 0) | ||||
|         } else { | ||||
|             matchingTrs = layerTrs.filter((tr) => tr.id === id) | ||||
|             matchingTrs = layerTrs.filter((tr) => tr.id === id || tr.labels?.indexOf(id) >= 0) | ||||
|         } | ||||
| 
 | ||||
|         const contextWriter = new AddContextToTranslations<TagRenderingConfigJson>("layers:") | ||||
|  | @ -237,8 +238,24 @@ class ExpandTagRendering extends Conversion< | |||
|             if (lookup === undefined) { | ||||
|                 const isTagRendering = ctx.indexOf("On(mapRendering") < 0 | ||||
|                 if (isTagRendering) { | ||||
|                     warnings.push(ctx + "A literal rendering was detected: " + tr) | ||||
|                     warnings.push( | ||||
|                         `${ctx}: A literal rendering was detected: ${tr} | ||||
|     Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` +
 | ||||
|                             Array.from(state.sharedLayers.keys()).join(", ") | ||||
|                     ) | ||||
|                 } | ||||
| 
 | ||||
|                 if (this._options?.noHardcodedStrings && this._state.sharedLayers.size > 0) { | ||||
|                     errors.push( | ||||
|                         ctx + | ||||
|                             "Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " + | ||||
|                             tr + | ||||
|                             " \n    Did you perhaps forget to add the layer as prefix, such as `icons." + | ||||
|                             tr + | ||||
|                             "`? " | ||||
|                     ) | ||||
|                 } | ||||
| 
 | ||||
|                 return [ | ||||
|                     { | ||||
|                         render: tr, | ||||
|  | @ -867,7 +884,11 @@ export class PrepareLayer extends Fuse<LayerConfigJson> { | |||
|                 (layer) => new Each(new PreparePointRendering(state, layer)) | ||||
|             ), | ||||
|             new SetDefault("titleIcons", ["icons.defaults"]), | ||||
|             new On("titleIcons", (layer) => new Concat(new ExpandTagRendering(state, layer))), | ||||
|             new On( | ||||
|                 "titleIcons", | ||||
|                 (layer) => | ||||
|                     new Concat(new ExpandTagRendering(state, layer, { noHardcodedStrings: true })) | ||||
|             ), | ||||
|             new ExpandFilter() | ||||
|         ) | ||||
|     } | ||||
|  |  | |||
|  | @ -714,7 +714,6 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> { | |||
|                 `At ${context}: minzoom is ${json.minzoom}, this should be at most ${Constants.userJourney.minZoomLevelToAddNewPoints} as a preset is set. Why? Selecting the pin for a new item will zoom in to level before adding the point. Having a greater minzoom will hide the points, resulting in possible duplicates` | ||||
|             ) | ||||
|         } | ||||
| 
 | ||||
|         { | ||||
|             // duplicate ids in tagrenderings check
 | ||||
|             const duplicates = Utils.Dedup( | ||||
|  |  | |||
|  | @ -52,7 +52,7 @@ | |||
|       }, | ||||
|       "render": "<img src='./assets/layers/bike_shop/pump.svg'/>" | ||||
|     }, | ||||
|     "defaults" | ||||
|     "icons.defaults" | ||||
|   ], | ||||
|   "description": { | ||||
|     "en": "A facility where bicycles can be lent for longer period of times", | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ | |||
|       "render": "<a href='https://fietsambassade.gent.be/' target='_blank'><img src='./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg'/></a>", | ||||
|       "condition": "operator=De Fietsambassade Gent" | ||||
|     }, | ||||
|     "defaults" | ||||
|     "icons.defaults" | ||||
|   ], | ||||
|   "source": { | ||||
|     "osmTags": { | ||||
|  | @ -315,4 +315,4 @@ | |||
|     "cs": "Vrstva zobrazující automaty na cyklistické duše (buď speciální automaty na cyklistické duše, nebo klasické automaty s cyklistickými dušemi a případně dalšími předměty souvisejícími s jízdními koly, jako jsou světla, rukavice, zámky, ...)", | ||||
|     "ca": "Una capa que mostra màquines expenedores per a tubs de bicicleta (ja siguin màquines expenedores de tubs de bicicleta o màquines expenedores clàssiques amb tubs de bicicleta i opcionalment objectes addicionals relacionats amb la bicicleta com ara llums, guants, panys, ...)" | ||||
|   } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -158,7 +158,7 @@ | |||
|       "render": "<a href='https://fietsambassade.gent.be/' target='_blank'><img src='./assets/themes/cyclofix/fietsambassade_gent_logo_small.svg'/></a>", | ||||
|       "condition": "operator=De Fietsambassade Gent" | ||||
|     }, | ||||
|     "defaults" | ||||
|     "icons.defaults" | ||||
|   ], | ||||
|   "tagRenderings": [ | ||||
|     "images", | ||||
|  | @ -1015,4 +1015,4 @@ | |||
|     "fr": "Une couche montrant les pompes à vélo et les centres de réparation", | ||||
|     "cs": "Vrstva zobrazující vzduchové kompresory na jízdní kola a stojany na nářadí pro opravu jízdních kol" | ||||
|   } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -197,7 +197,7 @@ | |||
|       "condition": "service:bicycle:cleaning=yes", | ||||
|       "render": "<img src='./assets/layers/bike_cleaning/bike_cleaning_icon.svg'/>" | ||||
|     }, | ||||
|     "defaults" | ||||
|     "icons.defaults" | ||||
|   ], | ||||
|   "description": { | ||||
|     "en": "A shop specifically selling bicycles or related items", | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue