Add overrie capabilities

This commit is contained in:
pietervdvn 2021-01-06 02:52:38 +01:00
parent 66018cb421
commit 93a16944a3
7 changed files with 113 additions and 41 deletions

View file

@ -4,6 +4,7 @@ import LayerConfig from "./LayerConfig";
import {LayoutConfigJson} from "./LayoutConfigJson";
import SharedLayers from "../SharedLayers";
import SharedTagRenderings from "../SharedTagRenderings";
import {Utils} from "../../Utils";
export default class LayoutConfig {
public readonly id: string;
@ -86,6 +87,21 @@ export default class LayoutConfig {
throw "Unkown fixed layer " + layer;
}
}
// @ts-ignore
if (layer.builtin !== undefined) {
// @ts-ignore
const name = layer.builtin;
console.warn("Overwriting!")
const shared = SharedLayers.sharedLayersJson[name];
if (shared === undefined) {
throw "Unkown fixed layer " + name;
}
console.log("PREMERGE", layer, shared)
// @ts-ignore
layer = Utils.Merge(layer.override, shared);
}
// @ts-ignore
return new LayerConfig(layer, this.roamingRenderings, `${this.id}.layers[${i}]`);
});

View file

@ -120,8 +120,11 @@ export interface LayoutConfigJson {
*
* *layers can also remove 'leftover'-features if the leftovers overlap with a feature in the layer itself
*
* Note that builtin layers can be reused. Either put in the name of the layer to reuse, or use {builtin: "layername", override: ...}
* The 'override'-object will be copied over the original values of the layer, which allows to change certain aspects of the layer
*
*/
layers: (LayerConfigJson | string)[],
layers: (LayerConfigJson | string | {builtin: string, override: any})[],
/**
* If defined, data will be clustered.

View file

@ -1,4 +1,3 @@
import * as drinkingWater from "../assets/layers/drinking_water/drinking_water.json";
import * as ghostbikes from "../assets/layers/ghost_bike/ghost_bike.json"
import * as viewpoint from "../assets/layers/viewpoint/viewpoint.json"
@ -21,40 +20,52 @@ import * as toilets from "../assets/layers/toilets/toilets.json"
import * as bookcases from "../assets/layers/public_bookcases/public_bookcases.json"
import * as tree_nodes from "../assets/layers/trees/tree_nodes.json"
import LayerConfig from "./JSON/LayerConfig";
import {LayerConfigJson} from "./JSON/LayerConfigJson";
export default class SharedLayers {
public static sharedLayers: Map<string, LayerConfig> = SharedLayers.getSharedLayers();
private static getSharedLayers(){
const sharedLayersList = [
new LayerConfig(drinkingWater,[], "shared_layers"),
new LayerConfig(ghostbikes,[], "shared_layers"),
new LayerConfig(viewpoint,[], "shared_layers"),
new LayerConfig(bike_parking,[], "shared_layers"),
new LayerConfig(bike_repair_station,[], "shared_layers"),
new LayerConfig(bike_monitoring_station,[], "shared_layers"),
new LayerConfig(birdhides,[], "shared_layers"),
new LayerConfig(nature_reserve,[], "shared_layers"),
new LayerConfig(bike_cafes,[], "shared_layers"),
new LayerConfig(bicycle_library, [], "bike_library"),
new LayerConfig(cycling_themed_objects,[], "shared_layers"),
new LayerConfig(bike_shops,[], "shared_layers"),
new LayerConfig(bike_cleaning,[], "shared_layers"),
new LayerConfig(maps,[], "shared_layers"),
new LayerConfig(direction,[], "shared_layers"),
new LayerConfig(information_boards,[], "shared_layers"),
new LayerConfig(toilets,[], "shared_layers"),
new LayerConfig(bookcases,[], "shared_layers"),
new LayerConfig(surveillance_camera,[], "shared_layers"),
new LayerConfig(tree_nodes,[], "shared_layers")
private static sharedLayersListRaw : LayerConfigJson[] = [
drinkingWater,
ghostbikes,
viewpoint,
bike_parking,
bike_repair_station,
bike_monitoring_station,
birdhides,
nature_reserve,
bike_cafes,
bicycle_library,
cycling_themed_objects,
bike_shops,
bike_cleaning,
maps,
direction,
information_boards,
toilets,
bookcases,
surveillance_camera,
tree_nodes
];
// Must be below the list...
public static sharedLayers: Map<string, LayerConfig> = SharedLayers.getSharedLayers();
public static sharedLayersJson: Map<string, any> = SharedLayers.getSharedLayersJson();
private static getSharedLayers(): Map<string, LayerConfig> {
const sharedLayers = new Map<string, LayerConfig>();
for (const layer of sharedLayersList) {
for (const layer of SharedLayers.sharedLayersListRaw) {
const parsed = new LayerConfig(layer, [], "shared_layers")
sharedLayers.set(layer.id, parsed);
sharedLayers[layer.id] = parsed;
}
return sharedLayers;
}
private static getSharedLayersJson(): Map<string, any> {
const sharedLayers = new Map<string, any>();
for (const layer of SharedLayers.sharedLayersListRaw) {
sharedLayers.set(layer.id, layer);
sharedLayers[layer.id] = layer;
}

View file

@ -38,7 +38,6 @@ export default class UpdateFromOverpass implements FeatureSource{
location: UIEventSource<Loc>,
layoutToUse: UIEventSource<LayoutConfig>,
leafletMap: UIEventSource<L.Map>) {
console.log("Crating overpass updater")
this._location = location;
this._layoutToUse = layoutToUse;
this._leafletMap = leafletMap;

View file

@ -175,6 +175,45 @@ export class Utils {
console.error("Key ", objectKey, "might be not supported (in context",context,")")
}
}
}
static Merge(source: any, target: any){
target = JSON.parse(JSON.stringify(target));
source = JSON.parse(JSON.stringify(source));
for (const key in source) {
const sourceV = source[key];
const targetV = target[key]
if(typeof sourceV === "object"){
if(targetV === undefined){
target[key] = sourceV;
}else{
Utils.Merge(sourceV, targetV);
}
}else{
target[key] = sourceV;
}
}
return target;
}
static ToMuchTags(source: any, toCheck: any, context: string){
for (const key in toCheck) {
const toCheckV = toCheck[key];
const sourceV = source[key];
if(sourceV === undefined){
console.error("Probably a wrong tag in ", context, ": ", key, "might be wrong")
}
if(typeof toCheckV === "object"){
if(typeof sourceV !== "object"){
console.error("Probably a wrong value in ", context, ": ", key, "is a fixed value in the source")
}else{
Utils.ToMuchTags(sourceV, toCheckV, context+"."+key);
}
}
}
}

View file

@ -25,6 +25,10 @@
"startZoom": 16,
"widenFactor": 0.05,
"socialImage": "./assets/themes/cyclofix/logo.svg",
"layers": ["bike_cafes", "bike_shops", "bicycle_library","bike_repair_station", "drinking_water", "bike_themed_object","bike_cleaning","bike_parking"],
"layers": ["bike_cafes", "bike_shops", {"builtin": "bicycle_library",
"override": {
"minzoom": 13
}
},"bike_repair_station", "drinking_water", "bike_themed_object","bike_cleaning","bike_parking"],
"roamingRenderings": []
}