forked from MapComplete/MapComplete
Feature: support 'repeat_on', fix #1588
This commit is contained in:
parent
ea19cca387
commit
53918f2044
5 changed files with 317 additions and 268 deletions
|
@ -339,21 +339,37 @@ export default class SimpleMetaTaggers {
|
|||
)
|
||||
private static levels = new InlineMetaTagger(
|
||||
{
|
||||
doc: "Extract the 'level'-tag into a normalized, ';'-separated value",
|
||||
doc: "Extract the 'level'-tag into a normalized, ';'-separated value called '_level' (which also includes 'repeat_on'). The `level` tag (without underscore) will be normalized with only the value of `level`.",
|
||||
keys: ["_level"],
|
||||
},
|
||||
(feature) => {
|
||||
if (feature.properties["level"] === undefined) {
|
||||
return false
|
||||
let somethingChanged = false
|
||||
if (feature.properties["level"] !== undefined) {
|
||||
const l = feature.properties["level"]
|
||||
const newValue = TagUtils.LevelsParser(l).join(";")
|
||||
if (l !== newValue) {
|
||||
feature.properties["level"] = newValue
|
||||
somethingChanged = true
|
||||
}
|
||||
}
|
||||
|
||||
const l = feature.properties["level"]
|
||||
const newValue = TagUtils.LevelsParser(l).join(";")
|
||||
if (l === newValue) {
|
||||
return false
|
||||
if (feature.properties["repeat_on"] !== undefined) {
|
||||
const l = feature.properties["repeat_on"]
|
||||
const newValue = TagUtils.LevelsParser(l).join(";")
|
||||
if (l !== newValue) {
|
||||
feature.properties["repeat_on"] = newValue
|
||||
somethingChanged = true
|
||||
}
|
||||
}
|
||||
feature.properties["level"] = newValue
|
||||
return true
|
||||
|
||||
const combined = TagUtils.LevelsParser(
|
||||
(feature.properties.repeat_on ?? "") + ";" + (feature.properties.level ?? "")
|
||||
).join(";")
|
||||
if (feature.properties["_level"] !== combined) {
|
||||
feature.properties["_level"] = combined
|
||||
somethingChanged = true
|
||||
}
|
||||
return somethingChanged
|
||||
}
|
||||
)
|
||||
private static canonicalize = new InlineMetaTagger(
|
||||
|
|
|
@ -66,11 +66,11 @@ export default class LayerState {
|
|||
}
|
||||
const t = Translations.t.general.levelSelection
|
||||
const conditionsOrred = [
|
||||
new Tag("level", "" + level),
|
||||
new RegexTag("level", new RegExp("(.*;)?" + level + "(;.*)?")),
|
||||
new Tag("_level", "" + level),
|
||||
new RegexTag("_level", new RegExp("(.*;)?" + level + "(;.*)?")),
|
||||
]
|
||||
if (level === "0") {
|
||||
conditionsOrred.push(new Tag("level", "")) // No level tag is the same as level '0'
|
||||
conditionsOrred.push(new Tag("_level", "")) // No level tag is the same as level '0'
|
||||
}
|
||||
console.log("Setting levels filter to", conditionsOrred)
|
||||
this.globalFilters.data.push({
|
||||
|
|
|
@ -483,13 +483,22 @@ export class TagUtils {
|
|||
* TagUtils.LevelsParser("-1") // => ["-1"]
|
||||
* TagUtils.LevelsParser("0;-1") // => ["0", "-1"]
|
||||
* TagUtils.LevelsParser(undefined) // => []
|
||||
* TagUtils.LevelsParser("") // => []
|
||||
* TagUtils.LevelsParser(";") // => []
|
||||
*
|
||||
*/
|
||||
public static LevelsParser(level: string): string[] {
|
||||
if (level === undefined || level === null) {
|
||||
return []
|
||||
}
|
||||
let spec = Utils.NoNull([level])
|
||||
spec = [].concat(...spec.map((s) => s?.split(";")))
|
||||
spec = [].concat(
|
||||
...spec.map((s) => {
|
||||
s = s.trim()
|
||||
if (s === "") {
|
||||
return undefined
|
||||
}
|
||||
if (s.indexOf("-") < 0 || s.startsWith("-")) {
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue