From 42d0071b26b3b619cf6561a5f1003b61176b3f6b Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 13 Jul 2021 18:52:02 +0200 Subject: [PATCH] Use canonical rendering in windpowermap --- Customizations/JSON/Denomination.ts | 6 +++++- Customizations/JSON/LayoutConfigJson.ts | 4 ++++ Logic/SimpleMetaTagger.ts | 5 +++++ UI/SpecialVisualizations.ts | 1 - assets/themes/openwindpowermap/openwindpowermap.json | 6 +++--- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Customizations/JSON/Denomination.ts b/Customizations/JSON/Denomination.ts index 8331d8adc..2b9779f94 100644 --- a/Customizations/JSON/Denomination.ts +++ b/Customizations/JSON/Denomination.ts @@ -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; @@ -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) diff --git a/Customizations/JSON/LayoutConfigJson.ts b/Customizations/JSON/LayoutConfigJson.ts index 8ced24bd7..374de70e0 100644 --- a/Customizations/JSON/LayoutConfigJson.ts +++ b/Customizations/JSON/LayoutConfigJson.ts @@ -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 * diff --git a/Logic/SimpleMetaTagger.ts b/Logic/SimpleMetaTagger.ts index 4453c2b4f..a704e2259 100644 --- a/Logic/SimpleMetaTagger.ts +++ b/Logic/SimpleMetaTagger.ts @@ -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(); + } }) ) diff --git a/UI/SpecialVisualizations.ts b/UI/SpecialVisualizations.ts index 2bbcbbb34..309060b36 100644 --- a/UI/SpecialVisualizations.ts +++ b/UI/SpecialVisualizations.ts @@ -369,7 +369,6 @@ export default class SpecialVisualizations { if (unit === undefined) { return value; } - return unit.asHumanLongValue(value); }, diff --git a/assets/themes/openwindpowermap/openwindpowermap.json b/assets/themes/openwindpowermap/openwindpowermap.json index 28201b9e5..b1e4ecaa7 100644 --- a/assets/themes/openwindpowermap/openwindpowermap.json +++ b/assets/themes/openwindpowermap/openwindpowermap.json @@ -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?"