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
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue