forked from MapComplete/MapComplete
Docs: improve tag output
This commit is contained in:
parent
1fea2b56be
commit
818f3e9017
5 changed files with 54 additions and 27 deletions
|
@ -72,11 +72,17 @@ export class And extends TagsFilter {
|
||||||
return allChoices
|
return allChoices
|
||||||
}
|
}
|
||||||
|
|
||||||
asHumanString(linkToWiki: boolean, shorten: boolean, properties) {
|
asHumanString(linkToWiki: boolean, shorten: boolean, properties: Record<string, string>) {
|
||||||
return this.and
|
return this.and
|
||||||
.map((t) => t.asHumanString(linkToWiki, shorten, properties))
|
.map((t) => {
|
||||||
|
let e = t.asHumanString(linkToWiki, shorten, properties)
|
||||||
|
if (t["or"]) {
|
||||||
|
e = "(" + e + ")"
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
})
|
||||||
.filter((x) => x !== "")
|
.filter((x) => x !== "")
|
||||||
.join(" &")
|
.join(" & ")
|
||||||
}
|
}
|
||||||
|
|
||||||
isUsableAsAnswer(): boolean {
|
isUsableAsAnswer(): boolean {
|
||||||
|
|
|
@ -49,8 +49,16 @@ export class Or extends TagsFilter {
|
||||||
return choices
|
return choices
|
||||||
}
|
}
|
||||||
|
|
||||||
asHumanString(linkToWiki: boolean, shorten: boolean, properties) {
|
asHumanString(linkToWiki: boolean, shorten: boolean, properties: Record<string, string>) {
|
||||||
return this.or.map((t) => t.asHumanString(linkToWiki, shorten, properties)).join(" |")
|
return this.or
|
||||||
|
.map((t) => {
|
||||||
|
let e = t.asHumanString(linkToWiki, shorten, properties)
|
||||||
|
if (t["and"]) {
|
||||||
|
e = "(" + e + ")"
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
})
|
||||||
|
.join(" | ")
|
||||||
}
|
}
|
||||||
|
|
||||||
isUsableAsAnswer(): boolean {
|
isUsableAsAnswer(): boolean {
|
||||||
|
|
|
@ -86,6 +86,11 @@ export class Tag extends TagsFilter {
|
||||||
v = Utils.EllipsesAfter(v, 25)
|
v = Utils.EllipsesAfter(v, 25)
|
||||||
}
|
}
|
||||||
if ((v === "" || v === undefined) && currentProperties !== undefined) {
|
if ((v === "" || v === undefined) && currentProperties !== undefined) {
|
||||||
|
if (!currentProperties || Object.keys(currentProperties).length === 0) {
|
||||||
|
// We are probably generating documentation
|
||||||
|
return this.key + "="
|
||||||
|
}
|
||||||
|
|
||||||
// This tag will be removed if in the properties, so we indicate this with special rendering
|
// This tag will be removed if in the properties, so we indicate this with special rendering
|
||||||
if ((currentProperties[this.key] ?? "") === "") {
|
if ((currentProperties[this.key] ?? "") === "") {
|
||||||
// This tag is not present in the current properties, so this tag doesn't change anything
|
// This tag is not present in the current properties, so this tag doesn't change anything
|
||||||
|
|
|
@ -22,7 +22,6 @@ import { Utils } from "../../Utils"
|
||||||
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
|
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
|
||||||
import Table from "../../UI/Base/Table"
|
import Table from "../../UI/Base/Table"
|
||||||
import FilterConfigJson from "./Json/FilterConfigJson"
|
import FilterConfigJson from "./Json/FilterConfigJson"
|
||||||
import { And } from "../../Logic/Tags/And"
|
|
||||||
import { Overpass } from "../../Logic/Osm/Overpass"
|
import { Overpass } from "../../Logic/Osm/Overpass"
|
||||||
import { FixedUiElement } from "../../UI/Base/FixedUiElement"
|
import { FixedUiElement } from "../../UI/Base/FixedUiElement"
|
||||||
import Svg from "../../Svg"
|
import Svg from "../../Svg"
|
||||||
|
@ -458,11 +457,6 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let neededTags: TagsFilter[] = Utils.NoNull([this.source?.osmTags])
|
|
||||||
if (this.source?.osmTags["and"] !== undefined) {
|
|
||||||
neededTags = this.source.osmTags["and"]
|
|
||||||
}
|
|
||||||
|
|
||||||
const tableRows = Utils.NoNull(
|
const tableRows = Utils.NoNull(
|
||||||
this.tagRenderings
|
this.tagRenderings
|
||||||
.map((tr) => tr.FreeformValues())
|
.map((tr) => tr.FreeformValues())
|
||||||
|
@ -523,7 +517,7 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
try {
|
try {
|
||||||
overpassLink = new Link(
|
overpassLink = new Link(
|
||||||
"Execute on overpass",
|
"Execute on overpass",
|
||||||
Overpass.AsOverpassTurboLink(<TagsFilter>new And(neededTags).optimize())
|
Overpass.AsOverpassTurboLink(<TagsFilter>this.source.osmTags.optimize())
|
||||||
.replaceAll("(", "%28")
|
.replaceAll("(", "%28")
|
||||||
.replaceAll(")", "%29")
|
.replaceAll(")", "%29")
|
||||||
)
|
)
|
||||||
|
@ -540,12 +534,30 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
|
|
||||||
const tagsDescription = []
|
const tagsDescription = []
|
||||||
if (this.source !== null) {
|
if (this.source !== null) {
|
||||||
tagsDescription.push(
|
tagsDescription.push(new Title("Basic tags for this layer", 2))
|
||||||
new Title("Basic tags for this layer", 2),
|
|
||||||
"Elements must have the all of following tags to be shown on this layer:",
|
const neededTags = <TagsFilter>this.source.osmTags.optimize()
|
||||||
new List(neededTags.map((t) => t.asHumanString(true, false, {}))),
|
if (neededTags["and"]) {
|
||||||
overpassLink
|
const parts = neededTags["and"]
|
||||||
)
|
tagsDescription.push(
|
||||||
|
"Elements must match **all** of the following expressions:",
|
||||||
|
parts.map((p, i) => i + ". " + p.asHumanString(true, false, {})).join("\n")
|
||||||
|
)
|
||||||
|
} else if (neededTags["or"]) {
|
||||||
|
const parts = neededTags["or"]
|
||||||
|
tagsDescription.push(
|
||||||
|
"Elements must match **any** of the following expressions:",
|
||||||
|
parts.map((p) => " - " + p.asHumanString(true, false, {})).join("\n")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
tagsDescription.push(
|
||||||
|
"Elements must match the expression **" +
|
||||||
|
neededTags.asHumanString(true, false, {}) +
|
||||||
|
"**"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
tagsDescription.push(overpassLink)
|
||||||
} else {
|
} else {
|
||||||
tagsDescription.push("This is a special layer - data is not sourced from OpenStreetMap")
|
tagsDescription.push("This is a special layer - data is not sourced from OpenStreetMap")
|
||||||
}
|
}
|
||||||
|
|
|
@ -746,17 +746,11 @@ export default class TagRenderingConfig {
|
||||||
new Combine([
|
new Combine([
|
||||||
new FixedUiElement(m.then.txt).SetClass("font-bold"),
|
new FixedUiElement(m.then.txt).SetClass("font-bold"),
|
||||||
" corresponds with ",
|
" corresponds with ",
|
||||||
new FixedUiElement(m.if.asHumanString(false, false, {})).SetClass(
|
m.if.asHumanString(true, false, {}),
|
||||||
"code"
|
|
||||||
),
|
|
||||||
]),
|
]),
|
||||||
]
|
]
|
||||||
if (m.hideInAnswer === true) {
|
if (m.hideInAnswer === true) {
|
||||||
msgs.push(
|
msgs.push("_This option cannot be chosen as answer_")
|
||||||
new FixedUiElement(
|
|
||||||
"This option cannot be chosen as answer"
|
|
||||||
).SetClass("italic")
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (m.ifnot !== undefined) {
|
if (m.ifnot !== undefined) {
|
||||||
msgs.push(
|
msgs.push(
|
||||||
|
@ -774,7 +768,9 @@ export default class TagRenderingConfig {
|
||||||
if (this.condition !== undefined && !this.condition?.matchesProperties({})) {
|
if (this.condition !== undefined && !this.condition?.matchesProperties({})) {
|
||||||
condition = new Combine([
|
condition = new Combine([
|
||||||
"This tagrendering is only visible in the popup if the following condition is met:",
|
"This tagrendering is only visible in the popup if the following condition is met:",
|
||||||
new FixedUiElement(this.condition.asHumanString(false, false, {})).SetClass("code"),
|
new FixedUiElement(
|
||||||
|
(<TagsFilter>this.condition.optimize()).asHumanString(true, false, {})
|
||||||
|
).SetClass("code"),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue