Remove 'language' as field from the layoutConfigJson as it is now calculated based on the title

This commit is contained in:
Pieter Vander Vennet 2022-01-27 01:23:04 +01:00
parent 8b46a7e052
commit 0f47b84229
11 changed files with 40 additions and 37 deletions

View file

@ -344,9 +344,6 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
{ {
// Legacy format checks // Legacy format checks
if (this._isBuiltin) { if (this._isBuiltin) {
if (typeof json.language === "string") {
errors.push("The theme " + json.id + " has a string as language. Please use a list of strings")
}
if (json["units"] !== undefined) { if (json["units"] !== undefined) {
errors.push("The theme " + json.id + " has units defined - these should be defined on the layer instead. (Hint: use overrideAll: { '+units': ... }) ") errors.push("The theme " + json.id + " has units defined - these should be defined on the layer instead. (Hint: use overrideAll: { '+units': ... }) ")
} }

View file

@ -41,20 +41,16 @@ export interface LayoutConfigJson {
* Should be sortable, where the higher value is the later version * Should be sortable, where the higher value is the later version
*/ */
version: string; version: string;
/**
* The supported language(s).
* This should be a two-letter, lowercase code which identifies the language, e.g. "en", "nl", ...
* If the theme supports multiple languages, use a list: `["en","nl","fr"]` to allow the user to pick any of them
*/
language: string | string[];
/** /**
* Only used in 'generateLayerOverview': if present, every translation will be checked to make sure it is fully translated * Only used in 'generateLayerOverview': if present, every translation will be checked to make sure it is fully translated.
*
* This must be a list of two-letter, lowercase codes which identifies the language, e.g. "en", "nl", ...
*/ */
mustHaveLanguage?: string[] mustHaveLanguage?: string[]
/** /**
* The title, as shown in the welcome message and the more-screen * The title, as shown in the welcome message and the more-screen.
*/ */
title: string | any; title: string | any;

View file

@ -301,8 +301,9 @@ export default class LayerConfig extends WithContextLoader {
if (mapRendering === undefined) { if (mapRendering === undefined) {
return undefined return undefined
} }
const defaultTags = new UIEventSource(TagUtils.changeAsProperties(this.source.osmTags.asChange({id: "node/-1"}))) const baseTags = TagUtils.changeAsProperties(this.source.osmTags.asChange({id: "node/-1"}))
return mapRendering.GenerateLeafletStyle(defaultTags, false, {noSize: true}).html return mapRendering.GenerateLeafletStyle(new UIEventSource(baseTags), false,
{noSize: true, includeBadges: false}).html
} }
public GenerateDocumentation(usedInThemes: string[], layerIsNeededBy: Map<string, string[]>, dependencies: { public GenerateDocumentation(usedInThemes: string[], layerIsNeededBy: Map<string, string[]>, dependencies: {

View file

@ -66,14 +66,13 @@ export default class LayoutConfig {
this.maintainer = json.maintainer; this.maintainer = json.maintainer;
this.credits = json.credits; this.credits = json.credits;
this.version = json.version; this.version = json.version;
this.language = []; this.language = Array.from(Object.keys(json.title));
if (typeof json.language === "string") {
this.language = [json.language];
} else {
this.language = json.language;
}
{ {
if (typeof json.title === "string") {
console.error("The title is not a translation, it instead is ", json.title, "("+typeof json.title+")")
throw `The title of a theme should always be a translation, as it sets the corresponding languages (${context}.title)`
}
if (this.language.length == 0) { if (this.language.length == 0) {
throw `No languages defined. Define at least one language. (${context}.languages)` throw `No languages defined. Define at least one language. (${context}.languages)`
} }
@ -120,7 +119,7 @@ export default class LayoutConfig {
this.clustering = { this.clustering = {
maxZoom: 16, maxZoom: 16,
minNeededElements: 25, minNeededElements: 250,
}; };
if (json.clustering === false) { if (json.clustering === false) {
this.clustering = { this.clustering = {
@ -130,7 +129,7 @@ export default class LayoutConfig {
} else if (json.clustering) { } else if (json.clustering) {
this.clustering = { this.clustering = {
maxZoom: json.clustering.maxZoom ?? 18, maxZoom: json.clustering.maxZoom ?? 18,
minNeededElements: json.clustering.minNeededElements ?? 25, minNeededElements: json.clustering.minNeededElements ?? 250,
} }
} }

View file

@ -150,7 +150,8 @@ export default class PointRenderingConfig extends WithContextLoader {
tags: UIEventSource<any>, tags: UIEventSource<any>,
clickable: boolean, clickable: boolean,
options?: { options?: {
noSize: false | boolean noSize: false | boolean,
includeBadges: true | boolean
} }
): ):
{ {
@ -201,7 +202,11 @@ export default class PointRenderingConfig extends WithContextLoader {
const icon = this.GetSimpleIcon(tags) const icon = this.GetSimpleIcon(tags)
const iconAndBadges = new Combine([icon, this.GetBadges(tags)]) let badges = undefined;
if( options?.includeBadges ?? true){
badges = this.GetBadges(tags)
}
const iconAndBadges = new Combine([icon,badges ])
.SetClass("block relative") .SetClass("block relative")
if (!options?.noSize) { if (!options?.noSize) {

View file

@ -22,7 +22,8 @@ import {InputElement} from "../Input/InputElement";
import {DropDown} from "../Input/DropDown"; import {DropDown} from "../Input/DropDown";
export default class FilterView extends VariableUiElement { export default class FilterView extends VariableUiElement {
constructor(filteredLayer: UIEventSource<FilteredLayer[]>, tileLayers: { config: TilesourceConfig, isDisplayed: UIEventSource<boolean> }[]) { constructor(filteredLayer: UIEventSource<FilteredLayer[]>,
tileLayers: { config: TilesourceConfig, isDisplayed: UIEventSource<boolean> }[]) {
const backgroundSelector = new Toggle( const backgroundSelector = new Toggle(
new BackgroundSelector(), new BackgroundSelector(),
undefined, undefined,
@ -30,8 +31,11 @@ export default class FilterView extends VariableUiElement {
) )
super( super(
filteredLayer.map((filteredLayers) => { filteredLayer.map((filteredLayers) => {
// Create the views which toggle layers (and filters them) ...
let elements = filteredLayers?.map(l => FilterView.createOneFilteredLayerElement(l)) let elements = filteredLayers?.map(l => FilterView.createOneFilteredLayerElement(l))
// ... create views for non-interactive layers ...
elements = elements.concat(tileLayers.map(tl => FilterView.createOverlayToggle(tl))) elements = elements.concat(tileLayers.map(tl => FilterView.createOverlayToggle(tl)))
// ... and add the dropdown to select a different background
return elements.concat(backgroundSelector); return elements.concat(backgroundSelector);
} }
) )
@ -93,11 +97,6 @@ export default class FilterView extends VariableUiElement {
iconStyle iconStyle
); );
if (filteredLayer.layerDef.name === undefined) {
return;
}
const name: Translation = Translations.WT( const name: Translation = Translations.WT(
filteredLayer.layerDef.name filteredLayer.layerDef.name
); );

View file

@ -1,15 +1,16 @@
{ {
"id": "notes", "id": "notes",
"language": [
"en"
],
"maintainer": "MapComplete", "maintainer": "MapComplete",
"startLat": 0, "startLat": 0,
"startLon": 0, "startLon": 0,
"startZoom": 0, "startZoom": 0,
"title": "Notes on OpenStreetMap", "title": {
"en": "Notes on OpenStreetMap"
},
"version": "0.1", "version": "0.1",
"description": "A note is a pin on the map with some text to indicate something wrong.<br/><br/>Make sure to checkout the <a href='#filters'>filter view</a> to search for users and text.", "description": {
"en": "A note is a pin on the map with some text to indicate something wrong.<br/><br/>Make sure to checkout the <a href='#filters'>filter view</a> to search for users and text."
},
"icon": "./assets/svg/resolved.svg", "icon": "./assets/svg/resolved.svg",
"clustering": false, "clustering": false,
"enableDownload": true, "enableDownload": true,

View file

@ -14,7 +14,7 @@
"hu": "WC-térkép" "hu": "WC-térkép"
}, },
"description": { "description": {
"en": "A map of public toilets", "en": "OpenStreetMap has the biggest dataset of toilets. Worldwide, over 300.000 toilets are known in this map. And, best of all, if one is missing, you can easily add it yourself! <br/><br/> So, if you need to pee or poo, find a loo!",
"de": "Eine Karte mit öffentlich zugänglichen Toiletten", "de": "Eine Karte mit öffentlich zugänglichen Toiletten",
"fr": "Carte affichant les WC et toilettes publiques", "fr": "Carte affichant les WC et toilettes publiques",
"nl": "Een kaart met openbare toiletten", "nl": "Een kaart met openbare toiletten",

View file

@ -196,4 +196,10 @@ class LayerOverviewUtils {
} }
} }
try{
new LayerOverviewUtils().main(process.argv) new LayerOverviewUtils().main(process.argv)
}catch(e){
console.error("ERROR WHILE GENERATING THE LAYERS:", e)
console.log("If a weird error persists, 'npm run reset:layeroverview'")
}

View file

@ -1,6 +1,6 @@
import ScriptUtils from "./ScriptUtils"; import ScriptUtils from "./ScriptUtils";
import {writeFileSync} from "fs"; import {writeFileSync} from "fs";
import {FixLegacyTheme, UpdateLegacyLayer} from "../Models/ThemeConfig/LegacyJsonConvert"; import {FixLegacyTheme, UpdateLegacyLayer} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert";
/* /*
* This script reads all theme and layer files and reformats them inplace * This script reads all theme and layer files and reformats them inplace

View file

@ -16,7 +16,6 @@ export default class ThemeSpec extends T {
let themeConfigJson: LayoutConfigJson = { let themeConfigJson: LayoutConfigJson = {
description: "Descr", description: "Descr",
icon: "", icon: "",
language: ["en"],
layers: [ layers: [
{ {
builtin: "public_bookcase", builtin: "public_bookcase",