forked from MapComplete/MapComplete
		
	Fix: restore loading of custom themes
This commit is contained in:
		
							parent
							
								
									649ed1f53a
								
							
						
					
					
						commit
						bcb2ecf6ab
					
				
					 3 changed files with 47 additions and 8 deletions
				
			
		| 
						 | 
					@ -20,9 +20,14 @@ import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages"
 | 
				
			||||||
import Svg from "../Svg"
 | 
					import Svg from "../Svg"
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    DoesImageExist,
 | 
					    DoesImageExist,
 | 
				
			||||||
    PrevalidateTheme,
 | 
					    PrevalidateTheme, ValidateTagRenderings,
 | 
				
			||||||
    ValidateThemeAndLayers,
 | 
					    ValidateThemeAndLayers,
 | 
				
			||||||
} from "../Models/ThemeConfig/Conversion/Validation"
 | 
					} from "../Models/ThemeConfig/Conversion/Validation"
 | 
				
			||||||
 | 
					import {DesugaringContext, Each, On} from "../Models/ThemeConfig/Conversion/Conversion";
 | 
				
			||||||
 | 
					import {PrepareLayer, RewriteSpecial} from "../Models/ThemeConfig/Conversion/PrepareLayer";
 | 
				
			||||||
 | 
					import {AllSharedLayers} from "../Customizations/AllSharedLayers";
 | 
				
			||||||
 | 
					import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
 | 
				
			||||||
 | 
					import questions from "../assets/tagRenderings/questions.json";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class DetermineLayout {
 | 
					export default class DetermineLayout {
 | 
				
			||||||
    private static readonly _knownImages = new Set(Array.from(licenses).map((l) => l.path))
 | 
					    private static readonly _knownImages = new Set(Array.from(licenses).map((l) => l.path))
 | 
				
			||||||
| 
						 | 
					@ -64,7 +69,7 @@ export default class DetermineLayout {
 | 
				
			||||||
        ).data
 | 
					        ).data
 | 
				
			||||||
        const layout = AllKnownLayouts.allKnownLayouts.get(layoutId?.toLowerCase())
 | 
					        const layout = AllKnownLayouts.allKnownLayouts.get(layoutId?.toLowerCase())
 | 
				
			||||||
        if (layout === undefined) {
 | 
					        if (layout === undefined) {
 | 
				
			||||||
            throw "No layout with name " + layoutId + " exists"
 | 
					            throw "No builtin map theme with name " + layoutId + " exists"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return layout
 | 
					        return layout
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -146,9 +151,41 @@ export default class DetermineLayout {
 | 
				
			||||||
                : undefined,
 | 
					                : undefined,
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
            .SetClass("flex flex-col clickable")
 | 
					            .SetClass("flex flex-col clickable")
 | 
				
			||||||
            .AttachTo("centermessage")
 | 
					            .AttachTo("maindiv")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static getSharedTagRenderings(): Map<string, TagRenderingConfigJson> {
 | 
				
			||||||
 | 
					        const dict = new Map<string, TagRenderingConfigJson>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const prep = new RewriteSpecial()
 | 
				
			||||||
 | 
					        const validator = new ValidateTagRenderings()
 | 
				
			||||||
 | 
					        for (const key in questions) {
 | 
				
			||||||
 | 
					            if (key === "id") {
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            questions[key].id = key
 | 
				
			||||||
 | 
					            questions[key]["source"] = "shared-questions"
 | 
				
			||||||
 | 
					            const config = prep.convertStrict(
 | 
				
			||||||
 | 
					                <TagRenderingConfigJson>questions[key],
 | 
				
			||||||
 | 
					                "questions.json:" + key
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            delete config["#"]
 | 
				
			||||||
 | 
					            validator.convertStrict(
 | 
				
			||||||
 | 
					                config,
 | 
				
			||||||
 | 
					                "generate-layer-overview:tagRenderings/questions.json:" + key
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            dict.set(key, config)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        dict.forEach((value, key) => {
 | 
				
			||||||
 | 
					            if (key === "id") {
 | 
				
			||||||
 | 
					                return
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            value.id = value.id ?? key
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return dict
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    private static prepCustomTheme(json: any, sourceUrl?: string, forceId?: string): LayoutConfig {
 | 
					    private static prepCustomTheme(json: any, sourceUrl?: string, forceId?: string): LayoutConfig {
 | 
				
			||||||
        if (json.layers === undefined && json.tagRenderings !== undefined) {
 | 
					        if (json.layers === undefined && json.tagRenderings !== undefined) {
 | 
				
			||||||
            const iconTr = json.mapRendering.map((mr) => mr.icon).find((icon) => icon !== undefined)
 | 
					            const iconTr = json.mapRendering.map((mr) => mr.icon).find((icon) => icon !== undefined)
 | 
				
			||||||
| 
						 | 
					@ -170,8 +207,8 @@ export default class DetermineLayout {
 | 
				
			||||||
            const layer = known_layers.layers[key]
 | 
					            const layer = known_layers.layers[key]
 | 
				
			||||||
            knownLayersDict.set(layer.id, <LayerConfigJson>layer)
 | 
					            knownLayersDict.set(layer.id, <LayerConfigJson>layer)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const converState = {
 | 
					        const convertState: DesugaringContext = {
 | 
				
			||||||
            tagRenderings: SharedTagRenderings.SharedTagRenderingJson,
 | 
					            tagRenderings: DetermineLayout.getSharedTagRenderings(),
 | 
				
			||||||
            sharedLayers: knownLayersDict,
 | 
					            sharedLayers: knownLayersDict,
 | 
				
			||||||
            publicLayers: new Set<string>(),
 | 
					            publicLayers: new Set<string>(),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -183,7 +220,7 @@ export default class DetermineLayout {
 | 
				
			||||||
            "While fixing the images"
 | 
					            "While fixing the images"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        json.enableNoteImports = json.enableNoteImports ?? false
 | 
					        json.enableNoteImports = json.enableNoteImports ?? false
 | 
				
			||||||
        json = new PrepareTheme(converState).convertStrict(json, "While preparing a dynamic theme")
 | 
					        json = new PrepareTheme(convertState).convertStrict(json, "While preparing a dynamic theme")
 | 
				
			||||||
        console.log("The layoutconfig is ", json)
 | 
					        console.log("The layoutconfig is ", json)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        json.id = forceId ?? json.id
 | 
					        json.id = forceId ?? json.id
 | 
				
			||||||
| 
						 | 
					@ -214,7 +251,7 @@ export default class DetermineLayout {
 | 
				
			||||||
        console.log("Downloading map theme from ", link)
 | 
					        console.log("Downloading map theme from ", link)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        new FixedUiElement(`Downloading the theme from the <a href="${link}">link</a>...`).AttachTo(
 | 
					        new FixedUiElement(`Downloading the theme from the <a href="${link}">link</a>...`).AttachTo(
 | 
				
			||||||
            "centermessage"
 | 
					            "maindiv"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -310,7 +310,7 @@ export default class SpecialVisualizations {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (template["type"] !== undefined) {
 | 
					        if (template["type"] !== undefined) {
 | 
				
			||||||
            console.trace(
 | 
					            console.trace(
 | 
				
			||||||
                "Got a non-expanded template while constructing the specification:",
 | 
					                "Got a non-expanded template while constructing the specification, it still has a 'special-key':",
 | 
				
			||||||
                template
 | 
					                template
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            throw "Got a non-expanded template while constructing the specification"
 | 
					            throw "Got a non-expanded template while constructing the specification"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								index.ts
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								index.ts
									
										
									
									
									
								
							| 
						 | 
					@ -3,6 +3,7 @@ import DetermineLayout from "./Logic/DetermineLayout"
 | 
				
			||||||
import ThemeViewState from "./Models/ThemeViewState"
 | 
					import ThemeViewState from "./Models/ThemeViewState"
 | 
				
			||||||
import SvelteUIElement from "./UI/Base/SvelteUIElement"
 | 
					import SvelteUIElement from "./UI/Base/SvelteUIElement"
 | 
				
			||||||
import ThemeViewGUI from "./UI/ThemeViewGUI.svelte"
 | 
					import ThemeViewGUI from "./UI/ThemeViewGUI.svelte"
 | 
				
			||||||
 | 
					import {FixedUiElement} from "./UI/Base/FixedUiElement";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Miscelleanous
 | 
					// Miscelleanous
 | 
				
			||||||
Utils.DisableLongPresses()
 | 
					Utils.DisableLongPresses()
 | 
				
			||||||
| 
						 | 
					@ -16,4 +17,5 @@ DetermineLayout.GetLayout()
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    .catch((err) => {
 | 
					    .catch((err) => {
 | 
				
			||||||
        console.error("Error while initializing: ", err, err.stack)
 | 
					        console.error("Error while initializing: ", err, err.stack)
 | 
				
			||||||
 | 
					        new FixedUiElement(err).SetClass("block alert").AttachTo("maindiv")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue