forked from MapComplete/MapComplete
UI: center labels if they don't have a marker
This commit is contained in:
parent
6f59e46bef
commit
afbb39b9ea
1 changed files with 13 additions and 8 deletions
|
@ -199,11 +199,14 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
anchorH = -iconH / 2
|
anchorH = -iconH / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
const icon = new SvelteUIElement(DynamicMarker, {
|
const icon =
|
||||||
marker: this.marker,
|
this.marker?.length > 0
|
||||||
rotation: this.rotation,
|
? new SvelteUIElement(DynamicMarker, {
|
||||||
tags,
|
marker: this.marker,
|
||||||
}).SetClass("w-full h-full")
|
rotation: this.rotation,
|
||||||
|
tags,
|
||||||
|
}).SetClass("w-full h-full")
|
||||||
|
: undefined
|
||||||
let badges = undefined
|
let badges = undefined
|
||||||
if (options?.includeBadges ?? true) {
|
if (options?.includeBadges ?? true) {
|
||||||
badges = this.GetBadges(tags, options?.metatags)
|
badges = this.GetBadges(tags, options?.metatags)
|
||||||
|
@ -223,13 +226,13 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
const css = this.cssDef?.GetRenderValue(tags.data)?.txt
|
const css = this.cssDef?.GetRenderValue(tags.data)?.txt
|
||||||
const cssClasses = this.cssClasses?.GetRenderValue(tags.data)?.txt
|
const cssClasses = this.cssClasses?.GetRenderValue(tags.data)?.txt
|
||||||
|
|
||||||
let label = this.GetLabel(tags)
|
let label = this.GetLabel(tags, icon === undefined)
|
||||||
|
|
||||||
let htmlEl: BaseUIElement
|
let htmlEl: BaseUIElement
|
||||||
if (icon === undefined && label === undefined) {
|
if (icon === undefined && label === undefined) {
|
||||||
htmlEl = undefined
|
htmlEl = undefined
|
||||||
} else if (icon === undefined) {
|
} else if (icon === undefined) {
|
||||||
htmlEl = new Combine([label])
|
htmlEl = label
|
||||||
} else if (label === undefined) {
|
} else if (label === undefined) {
|
||||||
htmlEl = new Combine([iconAndBadges])
|
htmlEl = new Combine([iconAndBadges])
|
||||||
} else {
|
} else {
|
||||||
|
@ -308,7 +311,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
).SetClass("absolute bottom-0 right-1/3 h-1/2 w-0")
|
).SetClass("absolute bottom-0 right-1/3 h-1/2 w-0")
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetLabel(tags: Store<Record<string, string>>): BaseUIElement {
|
private GetLabel(tags: Store<Record<string, string>>, labelOnly: boolean): BaseUIElement {
|
||||||
if (this.label === undefined) {
|
if (this.label === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -324,6 +327,8 @@ export default class PointRenderingConfig extends WithContextLoader {
|
||||||
?.SetClass(cssClassesLabel)
|
?.SetClass(cssClassesLabel)
|
||||||
if (cssLabel) {
|
if (cssLabel) {
|
||||||
label.SetStyle(cssLabel)
|
label.SetStyle(cssLabel)
|
||||||
|
} else if (labelOnly) {
|
||||||
|
return label.SetStyle("transform: translate(-50%, -50%);")
|
||||||
}
|
}
|
||||||
return new Combine([label]).SetClass("flex flex-col items-center")
|
return new Combine([label]).SetClass("flex flex-col items-center")
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue