forked from MapComplete/MapComplete
		
	Fix: generating layeroverview; performance: do not try to download ratings if no ratings element is present
This commit is contained in:
		
							parent
							
								
									c13d80f062
								
							
						
					
					
						commit
						fc62d41e1b
					
				
					 12 changed files with 67 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -1193,6 +1193,32 @@ class ExpandMarkerRenderings extends DesugaringStep<IconConfigJson> {
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super(
 | 
			
		||||
            "Adds the 'rating'-element if a reviews-element is used in the tagRenderings",
 | 
			
		||||
            ["titleIcons"],
 | 
			
		||||
            "AddRatingBadge"
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
 | 
			
		||||
        if (!json.tagRenderings) {
 | 
			
		||||
            return json
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const specialVis: RenderingSpecification[] = ValidationUtils.getAllSpecialVisualisations(
 | 
			
		||||
            <QuestionableTagRenderingConfigJson[]>json.tagRenderings
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        const calledFuncs = new Set<string>(specialVis.map((rs) => rs["func"]))
 | 
			
		||||
        if (calledFuncs.has("list_reviews")) {
 | 
			
		||||
            ;(<(string | TagRenderingConfigJson)[]>json.titleIcons).push("ratings")
 | 
			
		||||
        }
 | 
			
		||||
        return json
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class PrepareLayer extends Fuse<LayerConfigJson> {
 | 
			
		||||
    constructor(state: DesugaringContext) {
 | 
			
		||||
        super(
 | 
			
		||||
| 
						 | 
				
			
			@ -1223,6 +1249,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
 | 
			
		|||
                (layer) =>
 | 
			
		||||
                    new Concat(new ExpandTagRendering(state, layer, { noHardcodedStrings: true }))
 | 
			
		||||
            ),
 | 
			
		||||
            new AddRatingBadge(),
 | 
			
		||||
            new ExpandFilter(state)
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,7 +110,7 @@ export class DoesImageExist extends DesugaringStep<string> {
 | 
			
		|||
                )
 | 
			
		||||
            } else if (!this.doesPathExist(image)) {
 | 
			
		||||
                context.err(
 | 
			
		||||
                    `Image with path ${image} does not exist; it is used in ${context}.\n     Check for typo's and missing directories in the path.`
 | 
			
		||||
                    `Image with path ${image} does not exist.\n     Check for typo's and missing directories in the path.`
 | 
			
		||||
                )
 | 
			
		||||
            } else {
 | 
			
		||||
                context.err(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,12 @@ export default class ValidationUtils {
 | 
			
		|||
        renderingConfigs: (TagRenderingConfigJson | QuestionableTagRenderingConfigJson)[]
 | 
			
		||||
    ): RenderingSpecification[] {
 | 
			
		||||
        const visualisations: RenderingSpecification[] = []
 | 
			
		||||
        if (!Array.isArray(renderingConfigs)) {
 | 
			
		||||
            throw (
 | 
			
		||||
                "Could not inspect renderingConfigs, not an array: " +
 | 
			
		||||
                JSON.stringify(renderingConfigs)
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
        for (const renderConfig of renderingConfigs) {
 | 
			
		||||
            visualisations.push(...ValidationUtils.getSpecialVisualisationsWithArgs(renderConfig))
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue