diff --git a/Customizations/JSON/Denomination.ts b/Customizations/JSON/Denomination.ts index 9ecdf4c53..dc65e4142 100644 --- a/Customizations/JSON/Denomination.ts +++ b/Customizations/JSON/Denomination.ts @@ -6,54 +6,57 @@ import Combine from "../../UI/Base/Combine"; export class Unit { public readonly appliesToKeys: Set; - public readonly denominations : Denomination[]; + public readonly denominations: Denomination[]; public readonly defaultDenom: Denomination; - constructor(appliesToKeys: string[], applicableUnits: Denomination[]) { - this.appliesToKeys = new Set( appliesToKeys); + public readonly eraseInvalid : boolean; + + constructor(appliesToKeys: string[], applicableUnits: Denomination[], eraseInvalid: boolean) { + this.appliesToKeys = new Set(appliesToKeys); this.denominations = applicableUnits; -this.defaultDenom = applicableUnits.filter(denom => denom.default)[0] + this.defaultDenom = applicableUnits.filter(denom => denom.default)[0] + this.eraseInvalid = eraseInvalid } - isApplicableToKey(key: string | undefined) : boolean { - if(key === undefined){ + isApplicableToKey(key: string | undefined): boolean { + if (key === undefined) { return false; } - + return this.appliesToKeys.has(key); } /** * Finds which denomination is applicable and gives the stripped value back */ - findDenomination(valueWithDenom: string) : [string, Denomination] { + findDenomination(valueWithDenom: string): [string, Denomination] { for (const denomination of this.denominations) { - const bare = denomination.StrippedValue(valueWithDenom) - if(bare !== null){ + const bare = denomination.StrippedValue(valueWithDenom) + if (bare !== null) { return [bare, denomination] } - } + } return [undefined, undefined] } asHumanLongValue(value: string): BaseUIElement { - if(value === undefined){ + if (value === undefined) { return undefined; } const [stripped, denom] = this.findDenomination(value) const human = denom.human - - const elems = denom.prefix ? [human, stripped] : [stripped , human]; + + const elems = denom.prefix ? [human, stripped] : [stripped, human]; return new Combine(elems) - + } } export class Denomination { - private readonly _human: Translation; - private readonly alternativeDenominations: string []; public readonly canonical: string; readonly default: boolean; readonly prefix: boolean; + private readonly _human: Translation; + private readonly alternativeDenominations: string []; constructor(json: UnitConfigJson, context: string) { context = `${context}.unit(${json.canonicalDenomination})` @@ -77,13 +80,13 @@ export class Denomination { this.prefix = json.prefix ?? false; } - - get human() : Translation { + + get human(): Translation { return this._human.Clone() } public canonicalValue(value: string, actAsDefault?: boolean) { - if(value === undefined){ + if (value === undefined) { return undefined; } const stripped = this.StrippedValue(value, actAsDefault) @@ -102,10 +105,10 @@ export class Denomination { */ public StrippedValue(value: string, actAsDefault?: boolean): string { - if(value === undefined){ + if (value === undefined) { return undefined; } - + if (this.prefix) { if (value.startsWith(this.canonical)) { return value.substring(this.canonical.length).trim(); diff --git a/Customizations/JSON/LayoutConfig.ts b/Customizations/JSON/LayoutConfig.ts index 77487a663..f98d6dde7 100644 --- a/Customizations/JSON/LayoutConfig.ts +++ b/Customizations/JSON/LayoutConfig.ts @@ -99,7 +99,7 @@ export default class LayoutConfig { if (AllKnownLayers.sharedLayersJson[layer] !== undefined) { if (json.overrideAll !== undefined) { let lyr = JSON.parse(JSON.stringify(AllKnownLayers.sharedLayersJson[layer])); - return new LayerConfig(Utils.Merge(json.overrideAll, lyr), this.units,`${this.id}+overrideAll.layers[${i}]`, official); + return new LayerConfig(Utils.Merge(json.overrideAll, lyr), this.units, `${this.id}+overrideAll.layers[${i}]`, official); } else { return AllKnownLayers.sharedLayers[layer] } @@ -190,7 +190,7 @@ export default class LayoutConfig { } - private static ExtractUnits(json: LayoutConfigJson, context: string) : Unit[]{ + private static ExtractUnits(json: LayoutConfigJson, context: string): Unit[] { const result: Unit[] = [] if ((json.units ?? []).length !== 0) { for (let i1 = 0; i1 < json.units.length; i1++) { @@ -220,7 +220,7 @@ export default class LayoutConfig { throw `Multiple units are set as default: they have canonical values of ${defaultSet.map(u => u.canonicalDenomination).join(", ")}` } const applicable = unit.applicableUnits.map((u, i) => new Denomination(u, `${context}.units[${i}]`)) - result.push(new Unit( appliesTo, applicable)); + result.push(new Unit(appliesTo, applicable, unit.eraseInvalidValues ?? false)); } const seenKeys = new Set() diff --git a/Customizations/JSON/LayoutConfigJson.ts b/Customizations/JSON/LayoutConfigJson.ts index 4fe7cb7e1..6d079dc94 100644 --- a/Customizations/JSON/LayoutConfigJson.ts +++ b/Customizations/JSON/LayoutConfigJson.ts @@ -249,7 +249,15 @@ export interface LayoutConfigJson { */ 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; }[] /** diff --git a/Logic/FeatureSource/FeaturePipeline.ts b/Logic/FeatureSource/FeaturePipeline.ts index 2235c87bf..340710503 100644 --- a/Logic/FeatureSource/FeaturePipeline.ts +++ b/Logic/FeatureSource/FeaturePipeline.ts @@ -77,16 +77,14 @@ export default class FeaturePipeline implements FeatureSource { ]); merged.features.syncWith(allLoadedFeatures) - - const source = - new WayHandlingApplyingFeatureSource(flayers, - new FilteringFeatureSource( - flayers, - locationControl, - selectedElement, - merged - )); - this.features = source.features; + + this.features = new WayHandlingApplyingFeatureSource(flayers, + new FilteringFeatureSource( + flayers, + locationControl, + selectedElement, + merged + )).features; } } \ No newline at end of file diff --git a/Logic/SimpleMetaTagger.ts b/Logic/SimpleMetaTagger.ts index 6d9491aed..afb0cea47 100644 --- a/Logic/SimpleMetaTagger.ts +++ b/Logic/SimpleMetaTagger.ts @@ -94,9 +94,14 @@ export default class SimpleMetaTagger { } const value = feature.properties[key] const [, denomination] = unit.findDenomination(value) - const canonical = denomination.canonicalValue(value) + let canonical = denomination.canonicalValue(value) ?? undefined; console.log("Rewritten ", key, " from", value, "into", canonical) + if(canonical === undefined && !unit.eraseInvalid) { + break; + } + feature.properties[key] = canonical; + break; } }