diff --git a/src/Models/ThemeConfig/Conversion/FixImages.ts b/src/Models/ThemeConfig/Conversion/FixImages.ts index c0f3db458..2be9c0e36 100644 --- a/src/Models/ThemeConfig/Conversion/FixImages.ts +++ b/src/Models/ThemeConfig/Conversion/FixImages.ts @@ -191,7 +191,7 @@ export class ExtractImages extends Conversion< continue } allFoundImages.push({ - context: context + "." + foundElement.path.join("."), + context: context.path.join(".") + "." + foundElement.path.join("."), path: foundElement.leaf, }) } @@ -202,7 +202,7 @@ export class ExtractImages extends Conversion< for (const foundImage of allFoundImages) { if (foundImage.path.startsWith("<") && foundImage.path.endsWith(">")) { - // These is probably html - we ignore + // This is probably html const doc = parse_html(foundImage.path) const images = Array.from(doc.getElementsByTagName("img")) const paths = images.map((i) => i.getAttribute("src")) diff --git a/src/Models/ThemeConfig/LayoutConfig.ts b/src/Models/ThemeConfig/LayoutConfig.ts index d0d96c5a3..0306db182 100644 --- a/src/Models/ThemeConfig/LayoutConfig.ts +++ b/src/Models/ThemeConfig/LayoutConfig.ts @@ -11,6 +11,7 @@ import LanguageUtils from "../../Utils/LanguageUtils" import { RasterLayerProperties } from "../RasterLayerProperties" import { ConversionContext } from "./Conversion/ConversionContext" +import { Translatable } from "./Json/Translatable" /** * Minimal information about a theme @@ -18,12 +19,12 @@ import { ConversionContext } from "./Conversion/ConversionContext" export class LayoutInformation { id: string icon: string - title: any - shortDescription: any - definition?: any + title: Translatable | Translation + shortDescription: Translatable| Translation + definition?: Translatable| Translation mustHaveLanguage?: boolean hideFromOverview?: boolean - keywords?: any[] + keywords?: (Translatable| Translation)[] } export default class LayoutConfig implements LayoutInformation { @@ -71,13 +72,14 @@ export default class LayoutConfig implements LayoutInformation { public readonly osmApiTileSize: number public readonly official: boolean - public readonly usedImages: string[] + private usedImages: string[] public readonly extraLink?: ExtraLinkConfig public readonly definedAtUrl?: string public readonly definitionRaw?: string private readonly layersDict: Map + private readonly source: LayoutConfigJson constructor( json: LayoutConfigJson, @@ -90,6 +92,7 @@ export default class LayoutConfig implements LayoutInformation { if (json === undefined) { throw "Cannot construct a layout config, the parameter 'json' is undefined" } + this.source = json this.official = official this.id = json.id this.definedAtUrl = options?.definedAtUrl @@ -108,11 +111,7 @@ export default class LayoutConfig implements LayoutInformation { throw `The theme ${json.id} does not have a title defined.` } this.language = json.mustHaveLanguage ?? Object.keys(json.title) - this.usedImages = Array.from( - new ExtractImages(official, undefined) - .convertStrict(json, ConversionContext.construct([json.id], ["ExtractImages"])) - .map((i) => i.path) - ).sort() + { if (typeof json.title === "string") { throw `The title of a theme should always be a translation, as it sets the corresponding languages (${context}.title). The themenID is ${ @@ -130,17 +129,7 @@ export default class LayoutConfig implements LayoutInformation { if (json.description === undefined) { throw "Description not defined in " + this.id } - if (json.widenFactor <= 0) { - throw "Widenfactor too small, shoud be > 0" - } - if (json.widenFactor > 20) { - throw ( - "Widenfactor is very big, use a value between 1 and 5 (current value is " + - json.widenFactor + - ") at " + - context - ) - } + if (json["hideInOverview"]) { throw ( "The json for " + @@ -172,7 +161,7 @@ export default class LayoutConfig implements LayoutInformation { this.startZoom = json.startZoom this.startLat = json.startLat this.startLon = json.startLon - this.widenFactor = json.widenFactor ?? 1.5 + this.widenFactor = 1.5 this.defaultBackgroundId = json.defaultBackgroundId this.tileLayerSources = json.tileLayerSources ?? [] @@ -259,12 +248,11 @@ export default class LayoutConfig implements LayoutInformation { untranslated: Map total: number } { - const layout = this let total = 0 const untranslated = new Map() Utils.WalkObject( - [layout, extraInspection], + [this, extraInspection], (o) => { const translation = (o) if (translation.translations["*"] !== undefined) { @@ -330,4 +318,19 @@ export default class LayoutConfig implements LayoutInformation { console.log("Fallthrough", this, tags) return undefined } + + public getUsedImages(){ + if(this.usedImages){ + return this.usedImages + } + const json = this.source + // The 'favourite'-layer contains pretty much all images as it bundles all layers, so we exclude it + const jsonNoFavourites = {...json, layers: json.layers.filter(l => l["id"] !== "favourite")} + this.usedImages = Array.from( + new ExtractImages(this.official, undefined) + .convertStrict(jsonNoFavourites, ConversionContext.construct([json.id], ["ExtractImages"])) + .map((i) => i.path) + ).sort() + return this.usedImages + } } diff --git a/src/UI/BigComponents/CopyrightPanel.ts b/src/UI/BigComponents/CopyrightPanel.ts index f3b6f7634..61f3731d9 100644 --- a/src/UI/BigComponents/CopyrightPanel.ts +++ b/src/UI/BigComponents/CopyrightPanel.ts @@ -22,7 +22,7 @@ import GeoIndexedStore from "../../Logic/FeatureSource/Actors/GeoIndexedStore" import { RasterLayerPolygon } from "../../Models/RasterLayers" /** - * The attribution panel in the theme menu. + * The attribution panel in the theme menu. Shows the licenses of the artwork and of the map data */ export default class CopyrightPanel extends Combine { private static LicenseObject = CopyrightPanel.GenerateLicenses() @@ -40,7 +40,9 @@ export default class CopyrightPanel extends Combine { const t = Translations.t.general.attribution const layoutToUse = state.layout - const iconAttributions: BaseUIElement[] = Utils.Dedup(layoutToUse.usedImages).map( + + + const iconAttributions: BaseUIElement[] = (layoutToUse.getUsedImages()).map( CopyrightPanel.IconAttribution ) diff --git a/src/Utils.ts b/src/Utils.ts index 98f5ec134..f82054e1c 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1273,7 +1273,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be public static TransposeMap( d: Record ): Record { - const newD: Record = {} + const newD: Record = {} for (const k in d) { const vs = d[k]