forked from MapComplete/MapComplete
Fix: unit rewriting metatagger now only uses units as defined in the layer itself
This commit is contained in:
parent
f706fa7b5e
commit
0cf3d07100
2 changed files with 9 additions and 12 deletions
src
|
@ -11,6 +11,8 @@ import { UIEventSource } from "./UIEventSource"
|
|||
import ThemeConfig from "../Models/ThemeConfig/ThemeConfig"
|
||||
import OsmObjectDownloader from "./Osm/OsmObjectDownloader"
|
||||
import countryToCurrency from "country-to-currency"
|
||||
import { Unit } from "../Models/Unit"
|
||||
import { Denomination } from "../Models/Denomination"
|
||||
|
||||
/**
|
||||
* All elements that are needed to perform metatagging
|
||||
|
@ -476,10 +478,8 @@ export default class SimpleMetaTaggers {
|
|||
doc: "If 'units' is defined in the layoutConfig, then this metatagger will rewrite the specified keys to have the canonical form (e.g. `1meter` will be rewritten to `1m`; `1` will be rewritten to `1m` as well)",
|
||||
keys: ["Theme-defined keys"],
|
||||
},
|
||||
(feature, _, __, state) => {
|
||||
const units = Utils.NoNull(
|
||||
[].concat(...(state?.theme?.layers?.map((layer) => layer.units) ?? []))
|
||||
)
|
||||
(feature, layer, __, state) => {
|
||||
const units: Unit[] = layer.units
|
||||
if (units.length == 0) {
|
||||
return
|
||||
}
|
||||
|
@ -497,7 +497,7 @@ export default class SimpleMetaTaggers {
|
|||
continue
|
||||
}
|
||||
const value = feature.properties[key]
|
||||
const denom = unit.findDenomination(value, () => feature.properties["_country"])
|
||||
const denom: [string, Denomination] = unit.findDenomination(value, () => feature.properties["_country"])
|
||||
if (denom === undefined) {
|
||||
// no valid value found
|
||||
break
|
||||
|
@ -515,7 +515,7 @@ export default class SimpleMetaTaggers {
|
|||
if (canonical === value) {
|
||||
break
|
||||
}
|
||||
console.log("Rewritten ", key, ` from '${value}' into '${canonical}'`)
|
||||
console.log("Rewritten ", key, ` from '${value}' into '${canonical}' due to denomination`, denomination)
|
||||
if (canonical === undefined && !unit.eraseInvalid) {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import BaseUIElement from "../UI/BaseUIElement"
|
|||
import { Denomination } from "./Denomination"
|
||||
import UnitConfigJson from "./ThemeConfig/Json/UnitConfigJson"
|
||||
import unit from "../../assets/layers/unit/unit.json"
|
||||
import { QuestionableTagRenderingConfigJson } from "./ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import TagRenderingConfig from "./ThemeConfig/TagRenderingConfig"
|
||||
import Validators, { ValidatorType } from "../UI/InputElement/Validators"
|
||||
import { Validator } from "../UI/InputElement/Validator"
|
||||
|
@ -14,7 +13,6 @@ export class Unit {
|
|||
public readonly denominationsSorted: Denomination[]
|
||||
public readonly eraseInvalid: boolean
|
||||
public readonly quantity: string
|
||||
private readonly _validator: Validator
|
||||
public readonly inverted: boolean
|
||||
|
||||
constructor(
|
||||
|
@ -26,7 +24,6 @@ export class Unit {
|
|||
inverted: boolean = false
|
||||
) {
|
||||
this.quantity = quantity
|
||||
this._validator = validator
|
||||
if (
|
||||
!inverted &&
|
||||
["string", "text", "key", "icon", "translation", "fediverse", "id"].indexOf(
|
||||
|
@ -97,7 +94,7 @@ export class Unit {
|
|||
tagRenderings: TagRenderingConfig[],
|
||||
ctx: string
|
||||
): Unit[] {
|
||||
let types: Record<string, ValidatorType> = {}
|
||||
const types: Record<string, ValidatorType> = {}
|
||||
for (const tagRendering of tagRenderings) {
|
||||
if (tagRendering.freeform?.type) {
|
||||
types[tagRendering.freeform.key] = tagRendering.freeform.type
|
||||
|
@ -185,7 +182,7 @@ export class Unit {
|
|||
): Unit[] {
|
||||
const appliesTo = json.appliesToKey
|
||||
for (let i = 0; i < (appliesTo ?? []).length; i++) {
|
||||
let key = appliesTo[i]
|
||||
const key = appliesTo[i]
|
||||
if (key.trim() !== key) {
|
||||
throw `${ctx}.appliesToKey[${i}] is invalid: it starts or ends with whitespace`
|
||||
}
|
||||
|
@ -265,7 +262,7 @@ export class Unit {
|
|||
const loaded = this.getFromLibrary(toLoad.quantity, ctx)
|
||||
const quantity = toLoad.quantity
|
||||
|
||||
function fetchDenom(d: string): Denomination {
|
||||
const fetchDenom = (d: string): Denomination => {
|
||||
const found = loaded.denominations.find(
|
||||
(denom) => denom.canonical.toLowerCase() === d
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue