forked from MapComplete/MapComplete
Themes: add icons, add 'auto'-title-icons
This commit is contained in:
parent
0f545b29cb
commit
2c662c9578
10 changed files with 313 additions and 44 deletions
|
@ -10,10 +10,7 @@ import {
|
|||
SetDefault,
|
||||
} from "./Conversion"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import {
|
||||
MinimalTagRenderingConfigJson,
|
||||
TagRenderingConfigJson,
|
||||
} from "../Json/TagRenderingConfigJson"
|
||||
import { MinimalTagRenderingConfigJson, TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import RewritableConfigJson from "../Json/RewritableConfigJson"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
|
@ -26,7 +23,7 @@ import predifined_filters from "../../../../assets/layers/filters/filters.json"
|
|||
import { TagConfigJson } from "../Json/TagConfigJson"
|
||||
import PointRenderingConfigJson, { IconConfigJson } from "../Json/PointRenderingConfigJson"
|
||||
import ValidationUtils from "./ValidationUtils"
|
||||
import { RenderingSpecification, SpecialVisualization } from "../../../UI/SpecialVisualization"
|
||||
import { RenderingSpecification } from "../../../UI/SpecialVisualization"
|
||||
import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
|
||||
import { ConfigMeta } from "../../../UI/Studio/configMeta"
|
||||
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
|
||||
|
@ -1220,6 +1217,54 @@ export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
|
|||
return json
|
||||
}
|
||||
}
|
||||
export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"The auto-icon creates a (non-clickable) title icon based on a tagRendering which has icons",
|
||||
["titleIcons"],
|
||||
"AutoTitleIcon"
|
||||
)
|
||||
}
|
||||
|
||||
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
|
||||
json = { ...json }
|
||||
json.titleIcons = [...json.titleIcons]
|
||||
for (let i = 0; i < json.titleIcons.length; i++) {
|
||||
const titleIcon = json.titleIcons[i]
|
||||
if (typeof titleIcon !== "string") {
|
||||
continue
|
||||
}
|
||||
if (!titleIcon.startsWith("auto:")) {
|
||||
continue
|
||||
}
|
||||
const trId = titleIcon.substring("auto:".length)
|
||||
const tr = <QuestionableTagRenderingConfigJson>json.tagRenderings.find((tr) => tr["id"] === trId)
|
||||
if (tr === undefined) {
|
||||
context
|
||||
.enters("titleIcons", i)
|
||||
.err("TagRendering with id " + trId + " not found")
|
||||
continue
|
||||
}
|
||||
const mappings: { if: TagConfigJson, then: string }[] = tr.mappings?.filter(m => m.icon !== undefined)
|
||||
.map(m => {
|
||||
const path: string = typeof m.icon === "string" ? m.icon : m.icon.path
|
||||
const img = `<img class="m-1 h-6 w-6 low-interaction rounded" src='${path}'/>`
|
||||
return ({ if: m.if, then: img })
|
||||
})
|
||||
if (mappings.length === 0) {
|
||||
context
|
||||
.enters("titleIcons", i)
|
||||
.warn("TagRendering with id " + trId + " does not have any icons, not generating an icon for this")
|
||||
continue
|
||||
}
|
||||
json.titleIcons[i] = <TagRenderingConfigJson>{
|
||||
id: "title_icon_auto_" + trId,
|
||||
mappings,
|
||||
}
|
||||
}
|
||||
return json
|
||||
}
|
||||
}
|
||||
|
||||
export class PrepareLayer extends Fuse<LayerConfigJson> {
|
||||
constructor(state: DesugaringContext) {
|
||||
|
@ -1247,6 +1292,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
|
|||
),
|
||||
new SetDefault("titleIcons", ["icons.defaults"]),
|
||||
new AddRatingBadge(),
|
||||
new AutoTitleIcon(),
|
||||
new On(
|
||||
"titleIcons",
|
||||
(layer) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue