Add override-all option to layers

This commit is contained in:
pietervdvn 2021-04-23 16:50:07 +02:00
parent a4f8559108
commit 1a1477ca43
3 changed files with 23 additions and 8 deletions

View file

@ -1,5 +1,4 @@
import LayerConfig from "./JSON/LayerConfig"; import LayerConfig from "./JSON/LayerConfig";
import {LayerConfigJson} from "./JSON/LayerConfigJson";
import * as known_layers from "../assets/generated/known_layers_and_themes.json" import * as known_layers from "../assets/generated/known_layers_and_themes.json"
import {Utils} from "../Utils"; import {Utils} from "../Utils";
@ -9,7 +8,6 @@ export default class AllKnownLayers {
// Must be below the list... // Must be below the list...
public static sharedLayers: Map<string, LayerConfig> = AllKnownLayers.getSharedLayers(); public static sharedLayers: Map<string, LayerConfig> = AllKnownLayers.getSharedLayers();
public static sharedLayersJson: Map<string, any> = AllKnownLayers.getSharedLayersJson(); public static sharedLayersJson: Map<string, any> = AllKnownLayers.getSharedLayersJson();
private static sharedLayersListRaw: LayerConfigJson[] = known_layers.layers;
private static getSharedLayers(): Map<string, LayerConfig> { private static getSharedLayers(): Map<string, LayerConfig> {
const sharedLayers = new Map<string, LayerConfig>(); const sharedLayers = new Map<string, LayerConfig>();

View file

@ -93,8 +93,13 @@ export default class LayoutConfig {
this.defaultBackgroundId = json.defaultBackgroundId; this.defaultBackgroundId = json.defaultBackgroundId;
this.layers = json.layers.map((layer, i) => { this.layers = json.layers.map((layer, i) => {
if (typeof layer === "string") { if (typeof layer === "string") {
if (AllKnownLayers.sharedLayers[layer] !== undefined) { if (AllKnownLayers.sharedLayersJson[layer] !== undefined) {
return AllKnownLayers.sharedLayers[layer]; 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 { } else {
throw "Unkown fixed layer " + layer; throw "Unkown fixed layer " + layer;
} }
@ -109,12 +114,17 @@ export default class LayoutConfig {
} }
// @ts-ignore // @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 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 // @ts-ignore
return new LayerConfig(layer, `${this.id}.layers[${i}]`, official) return new LayerConfig(layer, `${this.id}.layers[${i}]`, official)
}); });
// ALl the layers are constructed, let them share tags in now! // ALl the layers are constructed, let them share tags in now!
const roaming: { r, source: LayerConfig }[] = [] const roaming: { r, source: LayerConfig }[] = []
for (const layer of this.layers) { for (const layer of this.layers) {
@ -140,10 +150,11 @@ export default class LayoutConfig {
); );
} }
this.clustering = { const defaultClustering = {
maxZoom: 16, maxZoom: 16,
minNeededElements: 250 minNeededElements: 500
}; };
this.clustering = defaultClustering;
if (json.clustering) { if (json.clustering) {
this.clustering = { this.clustering = {
maxZoom: json.clustering.maxZoom ?? 18, maxZoom: json.clustering.maxZoom ?? 18,

View file

@ -114,6 +114,11 @@ export interface LayoutConfigJson {
*/ */
roamingRenderings?: (TagRenderingConfigJson | string)[], roamingRenderings?: (TagRenderingConfigJson | string)[],
/**
* An override applied on all layers of the theme
*/
overrideAll?: any;
/** /**
* The id of the default background. BY default: vanilla OSM * The id of the default background. BY default: vanilla OSM
*/ */
@ -161,6 +166,7 @@ export interface LayoutConfigJson {
/** /**
* If defined, data will be clustered. * If defined, data will be clustered.
* Defaults to {maxZoom: 16, minNeeded: 500}
*/ */
clustering?: { clustering?: {
/** /**