Remove legacy: the minOverlapPercentage can now be built with a calculated tag and isShown

This commit is contained in:
Pieter Vander Vennet 2021-03-26 03:24:58 +01:00
parent 53e70b9a9c
commit ad406b5550
14 changed files with 237 additions and 252 deletions

View file

@ -24,7 +24,7 @@ export default class LayerConfig {
static WAYHANDLING_DEFAULT = 0;
static WAYHANDLING_CENTER_ONLY = 1;
static WAYHANDLING_CENTER_AND_WAY = 2;
id: string;
name: Translation
description: Translation;
@ -45,7 +45,6 @@ export default class LayerConfig {
width: TagRenderingConfig;
dashArray: TagRenderingConfig;
wayHandling: number;
hideUnderlayingFeaturesMinPercentage?: number;
presets: {
title: Translation,
@ -98,8 +97,13 @@ export default class LayerConfig {
console.warn(`Unofficial theme ${this.id} with custom javascript! This is a security risk`)
}
this.calculatedTags = [];
for (const key in json.calculatedTags) {
this.calculatedTags.push([key, json.calculatedTags[key]])
for (const kv of json.calculatedTags) {
const index = kv.indexOf("=")
const key = kv.substring(0, index);
const code = kv.substring(index + 1);
this.calculatedTags.push([key, code])
}
}
@ -108,7 +112,6 @@ export default class LayerConfig {
this.minzoom = json.minzoom ?? 0;
this.maxzoom = json.maxzoom ?? 1000;
this.wayHandling = json.wayHandling ?? 0;
this.hideUnderlayingFeaturesMinPercentage = json.hideUnderlayingFeaturesMinPercentage ?? 0;
this.presets = (json.presets ?? []).map((pr, i) =>
({
title: Translations.T(pr.title, `${context}.presets[${i}].title`),
@ -215,6 +218,9 @@ export default class LayerConfig {
this.dashArray = tr("dashArray", "");
if(json["showIf"] !== undefined){
throw "Invalid key on layerconfig "+this.id+": showIf. Did you mean 'isShown' instead?";
}
}
public CustomCodeSnippets(): string[] {

View file

@ -43,9 +43,17 @@ export interface LayerConfigJson {
source: {osmTags: AndOrTagConfigJson | string} | {geoJsonSource: string} | {overpassScript: string}
/**
* A dictionary of 'key': 'js-expression'. These js-expressions will be calculated for every feature, giving extra tags to work with in the rest of the pipieline
*
* A list of extra tags to calculate, specified as "keyToAssignTo=javascript-expression".
* There are a few extra functions available. Refer to <a>Docs/CalculatedTags.md</a> for more information
* The functions will be run in order, e.g.
* [
* "_max_overlap_m2=Math.max(...feat.overlapsWith("someOtherLayer").map(o => o.overlap))
* "_max_overlap_ratio=Number(feat._max_overlap_m2)/feat.area
* ]
*
*/
calculatedTags? : any;
calculatedTags? : string[];
/**
* If set, this layer will not query overpass; but it'll still match the tags above which are by chance returned by other layers.
@ -145,14 +153,6 @@ export interface LayerConfigJson {
*/
wayHandling?: number;
/**
* Consider that we want to show 'Nature Reserves' and 'Forests'. Now, ofter, there are pieces of forest mapped _in_ the nature reserve.
* Now, showing those pieces of forest overlapping with the nature reserve truly clutters the map and is very user-unfriendly.
*
* The features are placed layer by layer. If a feature below a feature on this layer overlaps for more then 'x'-percent, the underlying feature is hidden.
*/
hideUnderlayingFeaturesMinPercentage?:number;
/**
* If set, this layer will pass all the features it receives onto the next layer.
* This is ideal for decoration, e.g. directionss on cameras