Refactoring: move the units into the layers instead of the themes

This commit is contained in:
Pieter Vander Vennet 2021-09-13 01:21:47 +02:00
parent 3492b5d403
commit 206aff2c9a
16 changed files with 259 additions and 300 deletions

View file

@ -2,6 +2,7 @@ import {AndOrTagConfigJson} from "./TagConfigJson";
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
import FilterConfigJson from "./FilterConfigJson";
import {DeleteConfigJson} from "./DeleteConfigJson";
import UnitConfigJson from "./UnitConfigJson";
/**
* Configuration for a single layer
@ -317,4 +318,64 @@ export interface LayerConfigJson {
*/
allowSplit?: boolean
/**
* In some cases, a value is represented in a certain unit (such as meters for heigt/distance/..., km/h for speed, ...)
*
* Sometimes, multiple denominations are possible (e.g. km/h vs mile/h; megawatt vs kilowatt vs gigawatt for power generators, ...)
*
* This brings in some troubles, as there are multiple ways to write it (no denomitation, 'm' vs 'meter' 'metre', ...)
*
* Not only do we want to write consistent data to OSM, we also want to present this consistently to the user.
* This is handled by defining units.
*
* # Rendering
*
* To render a value with long (human) denomination, use {canonical(key)}
*
* # Usage
*
* First of all, you define which keys have units applied, for example:
*
* ```
* units: [
* appliesTo: ["maxspeed", "maxspeed:hgv", "maxspeed:bus"]
* applicableUnits: [
* ...
* ]
* ]
* ```
*
* ApplicableUnits defines which is the canonical extension, how it is presented to the user, ...:
*
* ```
* applicableUnits: [
* {
* canonicalDenomination: "km/h",
* alternativeDenomination: ["km/u", "kmh", "kph"]
* default: true,
* human: {
* en: "kilometer/hour",
* nl: "kilometer/uur"
* },
* humanShort: {
* en: "km/h",
* nl: "km/u"
* }
* },
* {
* canoncialDenomination: "mph",
* ... similar for miles an hour ...
* }
* ]
* ```
*
*
* If this is defined, then every key which the denominations apply to (`maxspeed`, `maxspeed:hgv` and `maxspeed:bus`) will be rewritten at the metatagging stage:
* every value will be parsed and the canonical extension will be added add presented to the other parts of the code.
*
* Also, if a freeform text field is used, an extra dropdown with applicable denominations will be given
*
*/
units?: UnitConfigJson[]
}

View file

@ -1,6 +1,6 @@
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
import UnitConfigJson from "./UnitConfigJson";
import {LayerConfigJson} from "./LayerConfigJson";
import UnitConfigJson from "./UnitConfigJson";
/**
* Defines the entire theme.
@ -217,83 +217,6 @@ export interface LayoutConfigJson {
*/
layers: (LayerConfigJson | string | { builtin: string | string[], override: any })[],
/**
* In some cases, a value is represented in a certain unit (such as meters for heigt/distance/..., km/h for speed, ...)
*
* Sometimes, multiple denominations are possible (e.g. km/h vs mile/h; megawatt vs kilowatt vs gigawatt for power generators, ...)
*
* This brings in some troubles, as there are multiple ways to write it (no denomitation, 'm' vs 'meter' 'metre', ...)
*
* Not only do we want to write consistent data to OSM, we also want to present this consistently to the user.
* This is handled by defining units.
*
* # Rendering
*
* To render a value with long (human) denomination, use {canonical(key)}
*
* # Usage
*
* First of all, you define which keys have units applied, for example:
*
* ```
* units: [
* appliesTo: ["maxspeed", "maxspeed:hgv", "maxspeed:bus"]
* applicableUnits: [
* ...
* ]
* ]
* ```
*
* ApplicableUnits defines which is the canonical extension, how it is presented to the user, ...:
*
* ```
* applicableUnits: [
* {
* canonicalDenomination: "km/h",
* alternativeDenomination: ["km/u", "kmh", "kph"]
* default: true,
* human: {
* en: "kilometer/hour",
* nl: "kilometer/uur"
* },
* humanShort: {
* en: "km/h",
* nl: "km/u"
* }
* },
* {
* canoncialDenomination: "mph",
* ... similar for miles an hour ...
* }
* ]
* ```
*
*
* If this is defined, then every key which the denominations apply to (`maxspeed`, `maxspeed:hgv` and `maxspeed:bus`) will be rewritten at the metatagging stage:
* every value will be parsed and the canonical extension will be added add presented to the other parts of the code.
*
* Also, if a freeform text field is used, an extra dropdown with applicable denominations will be given
*
*/
units?: {
/**
* Every key from this list will be normalized
*/
appliesToKey: string[],
/**
* The possible denominations
*/
applicableUnits: UnitConfigJson[]
/**
* If set, invalid values will be erased in the MC application (but not in OSM of course!)
* Be careful with setting this
*/
eraseInvalidValues?: boolean;
}[]
/**
* If defined, data will be clustered.
* Defaults to {maxZoom: 16, minNeeded: 500}

View file

@ -1,5 +1,23 @@
export default interface UnitConfigJson {
/**
* Every key from this list will be normalized
*/
appliesToKey: string[],
/**
* If set, invalid values will be erased in the MC application (but not in OSM of course!)
* Be careful with setting this
*/
eraseInvalidValues?: boolean;
/**
* The possible denominations
*/
applicableUnits:ApplicableUnitJson[]
}
export interface ApplicableUnitJson
{
/**
* The canonical value which will be added to the text.
* e.g. "m" for meters
@ -32,5 +50,4 @@ export default interface UnitConfigJson {
* If none is set, the first unit will be considered the default interpretation of a value without a unit
*/
default?: boolean
}