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 {LayoutConfigJson} from "./LayoutConfigJson";
import SharedLayers from "../SharedLayers"; import SharedLayers from "../SharedLayers";
import SharedTagRenderings from "../SharedTagRenderings"; import SharedTagRenderings from "../SharedTagRenderings";
import {Utils} from "../../Utils";
export default class LayoutConfig { export default class LayoutConfig {
public readonly id: string; public readonly id: string;
@ -79,13 +80,28 @@ 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 (SharedLayers.sharedLayers[layer] !== undefined) { if (SharedLayers.sharedLayers[layer] !== undefined) {
return SharedLayers.sharedLayers[layer]; return SharedLayers.sharedLayers[layer];
} else { } else {
throw "Unkown fixed layer " + layer; 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}]`); return new LayerConfig(layer, this.roamingRenderings, `${this.id}.layers[${i}]`);
}); });
@ -94,14 +110,14 @@ export default class LayoutConfig {
maxZoom: 16, maxZoom: 16,
minNeededElements: 250 minNeededElements: 250
}; };
if(json.clustering){ if (json.clustering) {
this.clustering = { this.clustering = {
maxZoom : json.clustering.maxZoom ?? 18, maxZoom: json.clustering.maxZoom ?? 18,
minNeededElements: json.clustering.minNeededElements ?? 1 minNeededElements: json.clustering.minNeededElements ?? 1
} }
for (const layer of this.layers) { for (const layer of this.layers) {
if(layer.wayHandling !== LayerConfig.WAYHANDLING_CENTER_ONLY){ 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); 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);
} }
} }
} }

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 * *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. * 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 drinkingWater from "../assets/layers/drinking_water/drinking_water.json";
import * as ghostbikes from "../assets/layers/ghost_bike/ghost_bike.json" import * as ghostbikes from "../assets/layers/ghost_bike/ghost_bike.json"
import * as viewpoint from "../assets/layers/viewpoint/viewpoint.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 bookcases from "../assets/layers/public_bookcases/public_bookcases.json"
import * as tree_nodes from "../assets/layers/trees/tree_nodes.json" import * as tree_nodes from "../assets/layers/trees/tree_nodes.json"
import LayerConfig from "./JSON/LayerConfig"; import LayerConfig from "./JSON/LayerConfig";
import {LayerConfigJson} from "./JSON/LayerConfigJson";
export default class SharedLayers { export default class SharedLayers {
private static sharedLayersListRaw : LayerConfigJson[] = [
drinkingWater,
public static sharedLayers: Map<string, LayerConfig> = SharedLayers.getSharedLayers(); ghostbikes,
viewpoint,
private static getSharedLayers(){ bike_parking,
const sharedLayersList = [ bike_repair_station,
new LayerConfig(drinkingWater,[], "shared_layers"), bike_monitoring_station,
new LayerConfig(ghostbikes,[], "shared_layers"), birdhides,
new LayerConfig(viewpoint,[], "shared_layers"), nature_reserve,
new LayerConfig(bike_parking,[], "shared_layers"), bike_cafes,
new LayerConfig(bike_repair_station,[], "shared_layers"), bicycle_library,
new LayerConfig(bike_monitoring_station,[], "shared_layers"), cycling_themed_objects,
new LayerConfig(birdhides,[], "shared_layers"), bike_shops,
new LayerConfig(nature_reserve,[], "shared_layers"), bike_cleaning,
new LayerConfig(bike_cafes,[], "shared_layers"), maps,
new LayerConfig(bicycle_library, [], "bike_library"), direction,
new LayerConfig(cycling_themed_objects,[], "shared_layers"), information_boards,
new LayerConfig(bike_shops,[], "shared_layers"), toilets,
new LayerConfig(bike_cleaning,[], "shared_layers"), bookcases,
new LayerConfig(maps,[], "shared_layers"), surveillance_camera,
new LayerConfig(direction,[], "shared_layers"), tree_nodes
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")
]; ];
// 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>(); 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.set(layer.id, layer);
sharedLayers[layer.id] = layer; sharedLayers[layer.id] = layer;
} }

View file

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

View file

@ -175,6 +175,45 @@ export class Utils {
console.error("Key ", objectKey, "might be not supported (in context",context,")") 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, "startZoom": 16,
"widenFactor": 0.05, "widenFactor": 0.05,
"socialImage": "./assets/themes/cyclofix/logo.svg", "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": [] "roamingRenderings": []
} }