Create currency metatagger

This commit is contained in:
Robin van der Linde 2023-07-17 20:25:19 +02:00
parent 7eeac66471
commit 1858cdac95
Signed by untrusted user: Robin-van-der-Linde
GPG key ID: 53956B3252478F0D
5 changed files with 125 additions and 66 deletions

View file

@ -14,6 +14,7 @@ import { OsmTags } from "../Models/OsmFeature"
import { UIEventSource } from "./UIEventSource"
import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"
import OsmObjectDownloader from "./Osm/OsmObjectDownloader"
import countryToCurrency from "country-to-currency"
/**
* All elements that are needed to perform metatagging
@ -583,6 +584,49 @@ export default class SimpleMetaTaggers {
}
)
private static currency = new InlineMetaTagger(
{
keys: ["_currency"],
doc: "Adds the currency valid for the object, based on country or explicit tagging. Can be a single currency or a semicolon-separated list of currencies. Empty if no currency is found.",
isLazy: true,
},
(feature) => {
Utils.AddLazyProperty(feature.properties, "_currency", () => {
// Initialize a list of currencies
const currencies = {}
// Check if there are any currency:XXX tags, add them to the map
for (const key in feature.properties) {
if (key.startsWith("currency:")) {
if (feature.properties[key] === "yes") {
currencies[key.slice(9)] = true
} else {
currencies[key.slice(9)] = false
}
}
}
// Determine the default currency for the country
const defaultCurrency = countryToCurrency[feature.properties._country.toUpperCase()]
// If the default currency is not in the list, add it
if (defaultCurrency && !currencies[defaultCurrency]) {
currencies[defaultCurrency] = true
}
console.log("currencyTags", currencies, defaultCurrency)
if (currencies) {
return Object.keys(currencies)
.filter((key) => currencies[key])
.join(";")
}
return ""
})
return true
}
)
public static metatags: SimpleMetaTagger[] = [
SimpleMetaTaggers.latlon,
SimpleMetaTaggers.layerInfo,
@ -601,6 +645,7 @@ export default class SimpleMetaTaggers {
SimpleMetaTaggers.levels,
SimpleMetaTaggers.referencingWays,
SimpleMetaTaggers.timeSinceLastEdit,
SimpleMetaTaggers.currency,
]
/**