Another sanity check, another bunch of fixed layers; add tagrendering-steal possibility, add some styling to TV-theme

This commit is contained in:
Pieter Vander Vennet 2021-11-10 18:42:31 +01:00
parent 10ac6a72e2
commit 746273f594
57 changed files with 602 additions and 940 deletions

View file

@ -1,16 +1,18 @@
import * as known_layers from "../assets/generated/known_layers_and_themes.json"
import {Utils} from "../Utils";
import LayerConfig from "../Models/ThemeConfig/LayerConfig";
import BaseUIElement from "../UI/BaseUIElement";
import Combine from "../UI/Base/Combine";
import Title from "../UI/Base/Title";
import List from "../UI/Base/List";
import {AllKnownLayouts} from "./AllKnownLayouts";
import {isNullOrUndefined} from "util";
import {Layer} from "leaflet";
import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson";
import SharedTagRenderings from "./SharedTagRenderings";
import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson";
import WithContextLoader from "../Models/ThemeConfig/WithContextLoader";
export default class AllKnownLayers {
public static inited = (_ => {
WithContextLoader.getKnownTagRenderings = (id => AllKnownLayers.getTagRendering(id))
return true
})()
// Must be below the list...
public static sharedLayers: Map<string, LayerConfig> = AllKnownLayers.getSharedLayers();
@ -64,7 +66,7 @@ export default class AllKnownLayers {
return sharedLayers;
}
private static getSharedLayersJson(): Map<string, any> {
private static getSharedLayersJson(): Map<string, LayerConfigJson> {
const sharedLayers = new Map<string, any>();
for (const layer of known_layers.layers) {
sharedLayers.set(layer.id, layer);
@ -73,4 +75,41 @@ export default class AllKnownLayers {
return sharedLayers;
}
/**
* Gets the appropriate tagRenderingJSON
* Allows to steal them from other layers.
* This will add the tags of the layer to the configuration though!
* @param renderingId
*/
static getTagRendering(renderingId: string): TagRenderingConfigJson {
if(renderingId.indexOf(".") < 0){
return SharedTagRenderings.SharedTagRenderingJson.get(renderingId)
}
const [layerId, id] = renderingId.split(".")
const layer = AllKnownLayers.getSharedLayersJson().get(layerId)
if(layer === undefined){
if(Utils.runningFromConsole){
// Probably generating the layer overview
return <TagRenderingConfigJson> {
id: "dummy"
}
}
throw "Builtin layer "+layerId+" not found"
}
const renderings = layer?.tagRenderings ?? []
for (const rendering of renderings) {
if(rendering["id"] === id){
const found = <TagRenderingConfigJson> JSON.parse(JSON.stringify(rendering))
if(found.condition === undefined){
found.condition = layer.source.osmTags
}else{
found.condition = {and: [found.condition, layer.source.osmTags]}
}
return found
}
}
throw `The rendering with id ${id} was not found in the builtin layer ${layerId}. Try one of ${Utils.NoNull(renderings.map(r => r["id"])).join(", ")}`
}
}

View file

@ -43,4 +43,5 @@ export default class SharedTagRenderings {
return dict;
}
}