Use canonical rendering in windpowermap

This commit is contained in:
pietervdvn 2021-07-13 18:52:02 +02:00
parent f5cc180eea
commit 42d0071b26
5 changed files with 17 additions and 5 deletions

View file

@ -3,6 +3,7 @@ import UnitConfigJson from "./UnitConfigJson";
import Translations from "../../UI/i18n/Translations";
import BaseUIElement from "../../UI/BaseUIElement";
import Combine from "../../UI/Base/Combine";
import {FixedUiElement} from "../../UI/Base/FixedUiElement";
export class Unit {
public readonly appliesToKeys: Set<string>;
@ -81,7 +82,10 @@ export class Unit {
return undefined;
}
const [stripped, denom] = this.findDenomination(value)
const human = denom.human
const human = denom?.human
if(human === undefined){
return new FixedUiElement(stripped ?? value);
}
const elems = denom.prefix ? [human, stripped] : [stripped, human];
return new Combine(elems)

View file

@ -225,6 +225,10 @@ export interface LayoutConfigJson {
*
* 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
*

View file

@ -84,6 +84,7 @@ export default class SimpleMetaTagger {
},
(feature => {
const units = State.state.layoutToUse.data.units ?? [];
let rewritten = false;
for (const key in feature.properties) {
if (!feature.properties.hasOwnProperty(key)) {
continue;
@ -104,10 +105,14 @@ export default class SimpleMetaTagger {
}
feature.properties[key] = canonical;
rewritten = true;
break;
}
}
if(rewritten){
State.state.allElements.getEventSourceById(feature.id).ping();
}
})
)

View file

@ -369,7 +369,6 @@ export default class SpecialVisualizations {
if (unit === undefined) {
return value;
}
return unit.asHumanLongValue(value);
},

View file

@ -56,7 +56,7 @@
"tagRenderings": [
{
"render": {
"en": "The power output of this wind turbine is {generator:output:electricity}."
"en": "The power output of this wind turbine is {canonical(generator:output:electricity)}."
},
"question": {
"en": "What is the power output of this wind turbine? (e.g. 2.3 MW)"
@ -79,7 +79,7 @@
},
{
"render": {
"en": "The total height (including rotor radius) of this wind turbine is {height} metres."
"en": "The total height (including rotor radius) of this wind turbine is {canonical(height)}."
},
"question": {
"en": "What is the total height of this wind turbine (including rotor radius), in metres?"
@ -91,7 +91,7 @@
},
{
"render": {
"en": "The rotor diameter of this wind turbine is {rotor:diameter} metres."
"en": "The rotor diameter of this wind turbine is {canonical(rotor:diameter)}."
},
"question": {
"en": "What is the rotor diameter of this wind turbine, in metres?"