forked from MapComplete/MapComplete
Refactoring of labels, better exposure
This commit is contained in:
parent
04b83311f7
commit
12b92d286b
4 changed files with 23 additions and 36 deletions
|
@ -19,6 +19,7 @@ import SourceConfig from "./SourceConfig";
|
|||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import SubstitutingTag from "../../Logic/Tags/SubstitutingTag";
|
||||
|
||||
export default class LayerConfig {
|
||||
|
||||
|
||||
|
@ -41,6 +42,7 @@ export default class LayerConfig {
|
|||
icon: TagRenderingConfig;
|
||||
iconOverlays: { if: TagsFilter, then: TagRenderingConfig, badge: boolean }[]
|
||||
iconSize: TagRenderingConfig;
|
||||
label: TagRenderingConfig;
|
||||
rotation: TagRenderingConfig;
|
||||
color: TagRenderingConfig;
|
||||
width: TagRenderingConfig;
|
||||
|
@ -213,6 +215,7 @@ export default class LayerConfig {
|
|||
}
|
||||
this.isShown = tr("isShown", "yes");
|
||||
this.iconSize = tr("iconSize", "40,40,center");
|
||||
this.label = tr("label", "")
|
||||
this.color = tr("color", "#0000ff");
|
||||
this.width = tr("width", "7");
|
||||
this.rotation = tr("rotation", "0");
|
||||
|
@ -224,30 +227,6 @@ export default class LayerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the parts of the icon, at ";" but makes sure that everything between "<html>" and "</html>" stays together
|
||||
* @param template
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
private static SplitParts(template: string): string[] {
|
||||
const htmlParts = template.split("<html>");
|
||||
const parts = []
|
||||
for (const htmlPart of htmlParts) {
|
||||
if (htmlPart.indexOf("</html>") >= 0) {
|
||||
const subparts = htmlPart.split("</html>");
|
||||
if (subparts.length != 2) {
|
||||
throw "Invalid rendering with embedded html: " + htmlPart;
|
||||
}
|
||||
parts.push("html:" + subparts[0]);
|
||||
parts.push(...subparts[1].split(";"))
|
||||
} else {
|
||||
parts.push(...htmlPart.split(";"))
|
||||
}
|
||||
}
|
||||
return parts.filter(prt => prt != "");
|
||||
}
|
||||
|
||||
public CustomCodeSnippets(): string[] {
|
||||
if (this.calculatedTags === undefined) {
|
||||
return []
|
||||
|
@ -396,13 +375,11 @@ export default class LayerConfig {
|
|||
const rotation = render(self.rotation, "0deg");
|
||||
|
||||
let htmlParts: UIElement[] = [];
|
||||
let sourceParts = LayerConfig.SplitParts(iconUrl);
|
||||
|
||||
let sourceParts = iconUrl.split(";").filter(prt => prt != "");
|
||||
for (const sourcePart of sourceParts) {
|
||||
htmlParts.push(genHtmlFromString(sourcePart))
|
||||
}
|
||||
|
||||
|
||||
let badges = [];
|
||||
for (const iconOverlay of self.iconOverlays) {
|
||||
if (!iconOverlay.if.matchesProperties(tgs)) {
|
||||
|
@ -410,7 +387,7 @@ export default class LayerConfig {
|
|||
}
|
||||
if (iconOverlay.badge) {
|
||||
const badgeParts: UIElement[] = [];
|
||||
const partDefs = LayerConfig.SplitParts(iconOverlay.then.GetRenderValue(tgs).txt);
|
||||
const partDefs = iconOverlay.then.GetRenderValue(tgs).txt.split(";").filter(prt => prt != "");
|
||||
|
||||
for (const badgePartStr of partDefs) {
|
||||
badgeParts.push(genHtmlFromString(badgePartStr))
|
||||
|
@ -432,6 +409,13 @@ export default class LayerConfig {
|
|||
.SetStyle("display:flex;height:50%;width:100%;position:absolute;top:50%;left:50%;");
|
||||
htmlParts.push(badgesComponent)
|
||||
}
|
||||
|
||||
|
||||
const label = self.label.GetRenderValue(tgs)?.Subs(tgs).SetClass("block w-min text-center")
|
||||
console.log("Generating label gave ", label, " source: ", self.label, "tags: ", tgs)
|
||||
if (label !== undefined) {
|
||||
htmlParts.push(new Combine([label]).SetClass("flex flex-col items-center");
|
||||
}
|
||||
return new Combine(htmlParts).Render();
|
||||
})
|
||||
|
||||
|
@ -461,7 +445,7 @@ export default class LayerConfig {
|
|||
for (const preset of this.presets) {
|
||||
parts.push(new Set<string>(preset.description?.ExtractImages(false)))
|
||||
}
|
||||
|
||||
|
||||
const allIcons = new Set<string>();
|
||||
for (const part of parts) {
|
||||
part?.forEach(allIcons.add, allIcons)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue