diff --git a/Customizations/JSON/LayoutConfig.ts b/Customizations/JSON/LayoutConfig.ts index 85f366c..23a2264 100644 --- a/Customizations/JSON/LayoutConfig.ts +++ b/Customizations/JSON/LayoutConfig.ts @@ -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; @@ -24,11 +25,11 @@ export default class LayoutConfig { public readonly roamingRenderings: TagRenderingConfig[]; public readonly defaultBackgroundId?: string; public readonly layers: LayerConfig[]; - public readonly clustering?: { + public readonly clustering?: { maxZoom: number, minNeededElements: number }; - + public readonly hideFromOverview: boolean; public readonly enableUserBadge: boolean; public readonly enableShareScreen: boolean; @@ -79,13 +80,28 @@ export default class LayoutConfig { ); this.defaultBackgroundId = json.defaultBackgroundId; this.layers = json.layers.map((layer, i) => { - if (typeof layer === "string"){ + if (typeof layer === "string") { if (SharedLayers.sharedLayers[layer] !== undefined) { return SharedLayers.sharedLayers[layer]; } else { 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}]`); }); @@ -94,14 +110,14 @@ export default class LayoutConfig { maxZoom: 16, minNeededElements: 250 }; - if(json.clustering){ + if (json.clustering) { this.clustering = { - maxZoom : json.clustering.maxZoom ?? 18, + maxZoom: json.clustering.maxZoom ?? 18, minNeededElements: json.clustering.minNeededElements ?? 1 } for (const layer of this.layers) { - if(layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY){ - console.error("WARNING: In order to allow clustering, every layer must be set to CENTER_ONLY. Layer", layer.id,"does not respect this for layout",this.id); + if (layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY) { + console.error("WARNING: In order to allow clustering, every layer must be set to CENTER_ONLY. Layer", layer.id, "does not respect this for layout", this.id); } } } diff --git a/Customizations/JSON/LayoutConfigJson.ts b/Customizations/JSON/LayoutConfigJson.ts index fd58ebb..9f56ac4 100644 --- a/Customizations/JSON/LayoutConfigJson.ts +++ b/Customizations/JSON/LayoutConfigJson.ts @@ -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. diff --git a/Customizations/JSON/TagRenderingConfig.ts b/Customizations/JSON/TagRenderingConfig.ts index d18b282..add0f72 100644 --- a/Customizations/JSON/TagRenderingConfig.ts +++ b/Customizations/JSON/TagRenderingConfig.ts @@ -46,7 +46,7 @@ export default class TagRenderingConfig { this.multiAnswer = false; return; } - + this.render = Translations.T(json.render); this.question = Translations.T(json.question); this.condition = FromJSON.Tag(json.condition ?? {"and": []}, `${context}.condition`); diff --git a/Customizations/SharedLayers.ts b/Customizations/SharedLayers.ts index 379ee94..6aed204 100644 --- a/Customizations/SharedLayers.ts +++ b/Customizations/SharedLayers.ts @@ -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,45 +20,57 @@ 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 { - - - + + 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 = SharedLayers.getSharedLayers(); + public static sharedLayersJson: Map = SharedLayers.getSharedLayersJson(); - 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 getSharedLayers(): Map { const sharedLayers = new Map(); - 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 { + const sharedLayers = new Map(); + for (const layer of SharedLayers.sharedLayersListRaw) { sharedLayers.set(layer.id, layer); sharedLayers[layer.id] = layer; } return sharedLayers; } - - + + } diff --git a/Logic/Actors/UpdateFromOverpass.ts b/Logic/Actors/UpdateFromOverpass.ts index 63067b5..ab4e95b 100644 --- a/Logic/Actors/UpdateFromOverpass.ts +++ b/Logic/Actors/UpdateFromOverpass.ts @@ -38,7 +38,6 @@ export default class UpdateFromOverpass implements FeatureSource{ location: UIEventSource, layoutToUse: UIEventSource, leafletMap: UIEventSource) { - console.log("Crating overpass updater") this._location = location; this._layoutToUse = layoutToUse; this._leafletMap = leafletMap; diff --git a/Utils.ts b/Utils.ts index 177d528..d9d3940 100644 --- a/Utils.ts +++ b/Utils.ts @@ -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); + } + } + } } diff --git a/assets/themes/cyclofix/cyclofix.json b/assets/themes/cyclofix/cyclofix.json index 1da6ad4..c90321a 100644 --- a/assets/themes/cyclofix/cyclofix.json +++ b/assets/themes/cyclofix/cyclofix.json @@ -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": [] } \ No newline at end of file