Add more documentation and checks to the models
This commit is contained in:
parent
706c5e3d53
commit
47011370dd
4 changed files with 22 additions and 4 deletions
|
@ -84,7 +84,9 @@ export interface LayerConfigJson {
|
|||
|
||||
/**
|
||||
* This tag rendering should either be 'yes' or 'no'. If 'no' is returned, then the feature will be hidden from view.
|
||||
* This is useful to hide certain features from view. Important: hiding features does not work dynamically, but is only calculated when the data is first renders.
|
||||
* This is useful to hide certain features from view.
|
||||
*
|
||||
* Important: hiding features does not work dynamically, but is only calculated when the data is first renders.
|
||||
* This implies that it is not possible to hide a feature after a tagging change
|
||||
*
|
||||
* The default value is 'yes'
|
||||
|
|
|
@ -79,6 +79,10 @@ export interface TagRenderingConfigJson {
|
|||
/**
|
||||
* If this condition is met, then the text under `then` will be shown.
|
||||
* If no value matches, and the user selects this mapping as an option, then these tags will be uploaded to OSM.
|
||||
*
|
||||
* For example: {'if': 'diet:vegetarion=yes', 'then':'A vegetarian option is offered here'}
|
||||
*
|
||||
* This can be an substituting-tag as well, e.g. {'if': 'addr:street:={_calculated_nearby_streetname}', 'then': '{_calculated_nearby_streetname}'}
|
||||
*/
|
||||
if: AndOrTagConfigJson | string,
|
||||
/**
|
||||
|
|
|
@ -104,6 +104,10 @@ export default class LayerConfig {
|
|||
throw context + "Use 'geoJson' instead of 'geoJsonSource'";
|
||||
}
|
||||
|
||||
if (json.source["geojson"] !== undefined) {
|
||||
throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)";
|
||||
}
|
||||
|
||||
this.source = new SourceConfig(
|
||||
{
|
||||
osmTags: osmTags,
|
||||
|
@ -133,6 +137,14 @@ export default class LayerConfig {
|
|||
const key = kv.substring(0, index);
|
||||
const code = kv.substring(index + 1);
|
||||
|
||||
try{
|
||||
|
||||
new Function("feat", "return " + code + ";");
|
||||
}catch(e){
|
||||
throw `Invalid function definition: code ${code} is invalid:${e} (at ${context})`
|
||||
}
|
||||
|
||||
|
||||
this.calculatedTags.push([key, code]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ export default class LayoutConfig {
|
|||
public readonly cacheTimeout?: number;
|
||||
public readonly overpassUrl: string;
|
||||
public readonly overpassTimeout: number;
|
||||
private readonly _official: boolean;
|
||||
public readonly official: boolean;
|
||||
|
||||
constructor(json: LayoutConfigJson, official = true, context?: string) {
|
||||
this._official = official;
|
||||
this.official = official;
|
||||
this.id = json.id;
|
||||
context = (context ?? "") + "." + this.id;
|
||||
this.maintainer = json.maintainer;
|
||||
|
@ -221,7 +221,7 @@ export default class LayoutConfig {
|
|||
}
|
||||
|
||||
public CustomCodeSnippets(): string[] {
|
||||
if (this._official) {
|
||||
if (this.official) {
|
||||
return [];
|
||||
}
|
||||
const msg = "<br/><b>This layout uses <span class='alert'>custom javascript</span>, loaded for the wide internet. The code is printed below, please report suspicious code on the issue tracker of MapComplete:</b><br/>"
|
||||
|
|
Loading…
Reference in a new issue