From 1a1477ca4350bc490397be5da751eb74e6a55871 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 23 Apr 2021 16:50:07 +0200 Subject: [PATCH] Add override-all option to layers --- Customizations/AllKnownLayers.ts | 2 -- Customizations/JSON/LayoutConfig.ts | 23 +++++++++++++++++------ Customizations/JSON/LayoutConfigJson.ts | 6 ++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Customizations/AllKnownLayers.ts b/Customizations/AllKnownLayers.ts index ae059e5..68bd2f1 100644 --- a/Customizations/AllKnownLayers.ts +++ b/Customizations/AllKnownLayers.ts @@ -1,5 +1,4 @@ import LayerConfig from "./JSON/LayerConfig"; -import {LayerConfigJson} from "./JSON/LayerConfigJson"; import * as known_layers from "../assets/generated/known_layers_and_themes.json" import {Utils} from "../Utils"; @@ -9,7 +8,6 @@ export default class AllKnownLayers { // Must be below the list... public static sharedLayers: Map = AllKnownLayers.getSharedLayers(); public static sharedLayersJson: Map = AllKnownLayers.getSharedLayersJson(); - private static sharedLayersListRaw: LayerConfigJson[] = known_layers.layers; private static getSharedLayers(): Map { const sharedLayers = new Map(); diff --git a/Customizations/JSON/LayoutConfig.ts b/Customizations/JSON/LayoutConfig.ts index 734f254..67396de 100644 --- a/Customizations/JSON/LayoutConfig.ts +++ b/Customizations/JSON/LayoutConfig.ts @@ -93,8 +93,13 @@ export default class LayoutConfig { this.defaultBackgroundId = json.defaultBackgroundId; this.layers = json.layers.map((layer, i) => { if (typeof layer === "string") { - if (AllKnownLayers.sharedLayers[layer] !== undefined) { - return AllKnownLayers.sharedLayers[layer]; + if (AllKnownLayers.sharedLayersJson[layer] !== undefined) { + if(json.overrideAll !== undefined){ + let lyr = JSON.parse(JSON.stringify( AllKnownLayers.sharedLayersJson[layer])); + return new LayerConfig(Utils.Merge(json.overrideAll, lyr),`${this.id}+overrideAll.layers[${i}]`, official); + }else{ + return AllKnownLayers.sharedLayers[layer] + } } else { throw "Unkown fixed layer " + layer; } @@ -109,12 +114,17 @@ export default class LayoutConfig { } // @ts-ignore layer = Utils.Merge(layer.override, JSON.parse(JSON.stringify(shared))); // We make a deep copy of the shared layer, in order to protect it from changes + + } - + if(json.overrideAll !== undefined){ + layer = Utils.Merge(json.overrideAll, layer); + } + // @ts-ignore return new LayerConfig(layer, `${this.id}.layers[${i}]`, official) }); - + // ALl the layers are constructed, let them share tags in now! const roaming: { r, source: LayerConfig }[] = [] for (const layer of this.layers) { @@ -140,10 +150,11 @@ export default class LayoutConfig { ); } - this.clustering = { + const defaultClustering = { maxZoom: 16, - minNeededElements: 250 + minNeededElements: 500 }; + this.clustering = defaultClustering; if (json.clustering) { this.clustering = { maxZoom: json.clustering.maxZoom ?? 18, diff --git a/Customizations/JSON/LayoutConfigJson.ts b/Customizations/JSON/LayoutConfigJson.ts index e70677e..3543eff 100644 --- a/Customizations/JSON/LayoutConfigJson.ts +++ b/Customizations/JSON/LayoutConfigJson.ts @@ -114,6 +114,11 @@ export interface LayoutConfigJson { */ roamingRenderings?: (TagRenderingConfigJson | string)[], + /** + * An override applied on all layers of the theme + */ + overrideAll?: any; + /** * The id of the default background. BY default: vanilla OSM */ @@ -161,6 +166,7 @@ export interface LayoutConfigJson { /** * If defined, data will be clustered. + * Defaults to {maxZoom: 16, minNeeded: 500} */ clustering?: { /**