diff --git a/src/Logic/DetermineLayout.ts b/src/Logic/DetermineLayout.ts index 0debbb5c6..ae2ffc734 100644 --- a/src/Logic/DetermineLayout.ts +++ b/src/Logic/DetermineLayout.ts @@ -14,11 +14,7 @@ import licenses from "../assets/generated/license_info.json" import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig" import { FixImages } from "../Models/ThemeConfig/Conversion/FixImages" import questions from "../assets/generated/layers/questions.json" -import { - DoesImageExist, - PrevalidateTheme, - ValidateThemeAndLayers, -} from "../Models/ThemeConfig/Conversion/Validation" +import { DoesImageExist, PrevalidateTheme, ValidateThemeAndLayers } from "../Models/ThemeConfig/Conversion/Validation" import { DesugaringContext } from "../Models/ThemeConfig/Conversion/Conversion" import { TagRenderingConfigJson } from "../Models/ThemeConfig/Json/TagRenderingConfigJson" import Hash from "./Web/Hash" @@ -109,11 +105,14 @@ export default class DetermineLayout { layoutId, "The layout to load into MapComplete" ).data - const layout = AllKnownLayouts.allKnownLayouts.get(layoutId?.toLowerCase()) - if (layout === undefined) { - throw "No builtin map theme with name " + layoutId + " exists" + const id = layoutId?.toLowerCase() + const layouts = AllKnownLayouts.allKnownLayouts + if (layouts.getConfig(id) === undefined) { + const alternatives = Utils.sortedByLevenshteinDistance(id, Array.from(layouts.keys()), i => i).slice(0, 3) + const msg = (`No builtin map theme with name ${layoutId} exists. Perhaps you meant one of ${alternatives.join(", ")}`) + throw msg } - return layout + return layouts.get(id) } public static async LoadLayoutFromHash( @@ -162,6 +161,7 @@ export default class DetermineLayout { return dict } + private static getSharedTagRenderingOrder(): string[] { return questions.tagRenderings.map((tr) => tr.id) } @@ -200,11 +200,11 @@ export default class DetermineLayout { id: json.id, description: json.description, descriptionTail: { - en: "
Layer only mode.
The loaded custom theme actually isn't a custom theme, but only contains a layer.", + en: "
Layer only mode.
The loaded custom theme actually isn't a custom theme, but only contains a layer." }, icon, title: json.name, - layers: [json], + layers: [json] } } @@ -217,7 +217,7 @@ export default class DetermineLayout { tagRenderings: DetermineLayout.getSharedTagRenderings(), tagRenderingOrder: DetermineLayout.getSharedTagRenderingOrder(), sharedLayers: knownLayersDict, - publicLayers: new Set(), + publicLayers: new Set() } json = new FixLegacyTheme().convertStrict(json) const raw = json @@ -241,7 +241,7 @@ export default class DetermineLayout { } return new LayoutConfig(json, false, { definitionRaw: JSON.stringify(raw, null, " "), - definedAtUrl: sourceUrl, + definedAtUrl: sourceUrl }) } diff --git a/src/all_themes_index.ts b/src/all_themes_index.ts index 5fac705c0..fb4f4fe0c 100644 --- a/src/all_themes_index.ts +++ b/src/all_themes_index.ts @@ -1,5 +1,4 @@ import { QueryParameters } from "./Logic/Web/QueryParameters" -import SvelteUIElement from "./UI/Base/SvelteUIElement" import AllThemesGui from "./UI/AllThemesGui.svelte" const layout = QueryParameters.GetQueryParameter("layout", undefined).data ?? "" diff --git a/src/index.ts b/src/index.ts index 975335b87..263584cb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,6 @@ async function getAvailableLayers(): Promise> { } async function main() { - // @ts-ignore try { if (!webgl_support()) { throw "WebGL is not supported or not enabled. This is essential for MapComplete to function, please enable this."