Natuurpunt tweaks

This commit is contained in:
Pieter Vander Vennet 2022-01-31 14:34:06 +01:00
parent 618f61d3e8
commit 5a9f26081c
55 changed files with 1516 additions and 1368 deletions

View file

@ -10,10 +10,12 @@ export interface DesugaringContext {
export abstract class Conversion<TIn, TOut> {
public readonly modifiedAttributes: string[];
protected readonly doc: string;
constructor(doc: string, modifiedAttributes: string[] = []) {
public readonly name: string
constructor(doc: string, modifiedAttributes: string[] = [], name?: string) {
this.modifiedAttributes = modifiedAttributes;
this.doc = doc + "\n\nModified attributes are\n" + modifiedAttributes.join(", ");
this.name = name ?? this.constructor.name
}
public static strict<T>(fixed: { errors: string[], warnings: string[], result?: T }): T {
@ -83,7 +85,8 @@ export class OnEveryConcat<X, T> extends DesugaringStep<T> {
private readonly step: Conversion<X, X[]>;
constructor(key: string, step: Conversion<X, X[]>) {
super(`Applies ${step.constructor.name} onto every object of the list \`${key}\`. The results are concatenated and used as new list`, [key]);
super(`Applies ${step.constructor.name} onto every object of the list \`${key}\`. The results are concatenated and used as new list`, [key],
"OnEveryConcat("+step.name+")");
this.step = step;
this.key = key;
}
@ -128,7 +131,7 @@ export class Fuse<T> extends DesugaringStep<T> {
const warnings = []
for (let i = 0; i < this.steps.length; i++) {
const step = this.steps[i];
let r = step.convert(state, json, context + "(fusion " + this.constructor.name + "." + i + ")")
let r = step.convert(state, json, "While running step " +step.name + ": " + context)
errors.push(...r.errors)
warnings.push(...r.warnings)
json = r.result

View file

@ -43,7 +43,7 @@ class SubstituteLayer extends Conversion<(string | LayerConfigJson), LayerConfig
for (const name of names) {
const found = Utils.Clone(state.sharedLayers.get(name))
if (found === undefined) {
errors.push(context + ": The layer with name " + json + " was not found as a builtin layer")
errors.push(context + ": The layer with name " + JSON.stringify(json) + " was not found as a builtin layer. Known builtin layers are "+Array.from(state.sharedLayers.keys()).join(",")+"\n For more information, see https://github.com/pietervdvn/MapComplete/blob/develop/Docs/BuiltinLayers.md" )
continue
}
if (json["override"]["tagRenderings"] !== undefined && (found["tagRenderings"] ?? []).length > 0) {
@ -81,6 +81,7 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> {
const errors = []
const warnings = []
json.layers = [...json.layers]
const alreadyLoaded = new Set(json.layers.map(l => l["id"]))
if (json.id === "personal") {
json.layers = []
@ -105,6 +106,10 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> {
if (v === undefined) {
errors.push("Default layer " + layerName + " not found")
}
if(alreadyLoaded.has(v.id)){
warnings.push("Layout "+context+" already has a layer with name "+v.id+"; skipping inclusion of this builtin layer")
continue
}
json.layers.push(v)
}
@ -131,44 +136,45 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
json.layers = [...json.layers]
const creator = new CreateNoteImportLayer()
for (let i1 = 0; i1 < allLayers.length; i1++) {
const layer = allLayers[i1];
if (Constants.priviliged_layers.indexOf(layer.id) >= 0) {
// Priviliged layers are skipped
continue
}
if (layer.source["geoJson"] !== undefined) {
// Layer which don't get their data from OSM are skipped
continue
}
if (layer.title === undefined || layer.name === undefined) {
// Anonymous layers and layers without popup are skipped
continue
}
if (layer.presets === undefined || layer.presets.length == 0) {
// A preset is needed to be able to generate a new point
continue;
}
try {
const importLayerResult = creator.convert(state, layer, context + ".(noteimportlayer)[" + i1 + "]")
errors.push(...importLayerResult.errors)
warnings.push(...importLayerResult.warnings)
if (importLayerResult.result !== undefined) {
warnings.push("Added an import layer to theme " + json.id + ", namely " + importLayerResult.result.id)
json.layers.push(importLayerResult.result)
if(json.enableNoteImports ?? true) {
const creator = new CreateNoteImportLayer()
for (let i1 = 0; i1 < allLayers.length; i1++) {
const layer = allLayers[i1];
if (Constants.priviliged_layers.indexOf(layer.id) >= 0) {
// Priviliged layers are skipped
continue
}
if (layer.source["geoJson"] !== undefined) {
// Layer which don't get their data from OSM are skipped
continue
}
if (layer.title === undefined || layer.name === undefined) {
// Anonymous layers and layers without popup are skipped
continue
}
if (layer.presets === undefined || layer.presets.length == 0) {
// A preset is needed to be able to generate a new point
continue;
}
try {
const importLayerResult = creator.convert(state, layer, context + ".(noteimportlayer)[" + i1 + "]")
errors.push(...importLayerResult.errors)
warnings.push(...importLayerResult.warnings)
if (importLayerResult.result !== undefined) {
warnings.push("Added an import layer to theme " + json.id + ", namely " + importLayerResult.result.id)
json.layers.push(importLayerResult.result)
}
} catch (e) {
errors.push("Could not generate an import-layer for " + layer.id + " due to " + e)
}
} catch (e) {
errors.push("Could not generate an import-layer for " + layer.id + " due to " + e)
}
}
return {
errors,
warnings,

View file

@ -249,6 +249,7 @@ export interface LayoutConfigJson {
enableDownload?: boolean;
enablePdfDownload?: boolean;
enableIframePopout?: true | boolean;
enableNoteImports?: true | boolean;
/**
* Set one or more overpass URLs to use for this theme..

View file

@ -73,6 +73,7 @@ export default class LayoutConfig {
} else {
this.language = json.language;
}
this.language = json.mustHaveLanguage ?? this.language
{
if (this.language.length == 0) {
throw `No languages defined. Define at least one language. (${context}.languages)`