forked from MapComplete/MapComplete
Merge develop
This commit is contained in:
commit
d959b6b40b
290 changed files with 37178 additions and 2200 deletions
|
@ -1266,6 +1266,59 @@ 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) {
|
||||
|
@ -1294,6 +1347,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
|
|||
new SetDefault("titleIcons", ["icons.defaults"]),
|
||||
new AddRatingBadge(),
|
||||
new AddFavouriteBadges(),
|
||||
new AutoTitleIcon(),
|
||||
new On(
|
||||
"titleIcons",
|
||||
(layer) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue