Use canonical rendering in windpowermap

This commit is contained in:
Pieter Vander Vennet 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 Translations from "../../UI/i18n/Translations";
import BaseUIElement from "../../UI/BaseUIElement"; import BaseUIElement from "../../UI/BaseUIElement";
import Combine from "../../UI/Base/Combine"; import Combine from "../../UI/Base/Combine";
import {FixedUiElement} from "../../UI/Base/FixedUiElement";
export class Unit { export class Unit {
public readonly appliesToKeys: Set<string>; public readonly appliesToKeys: Set<string>;
@ -81,7 +82,10 @@ export class Unit {
return undefined; return undefined;
} }
const [stripped, denom] = this.findDenomination(value) 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]; const elems = denom.prefix ? [human, stripped] : [stripped, human];
return new Combine(elems) return new Combine(elems)

View file

@ -226,6 +226,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. * 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. * This is handled by defining units.
* *
* # Rendering
*
* To render a value with long (human) denomination, use {canonical(key)}
*
* # Usage * # Usage
* *
* First of all, you define which keys have units applied, for example: * First of all, you define which keys have units applied, for example:

View file

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

View file

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

View file

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