Themes: add proper 'image along way' possibility

This commit is contained in:
Pieter Vander Vennet 2024-02-12 12:39:35 +01:00
parent 29f8e08509
commit 584fb3cb57
17 changed files with 259 additions and 70 deletions

View file

@ -1,4 +1,7 @@
import { MinimalTagRenderingConfigJson } from "./TagRenderingConfigJson"
import { MappingConfigJson } from "./QuestionableTagRenderingConfigJson"
import { TagsFilter } from "../../../Logic/Tags/TagsFilter"
import { TagConfigJson } from "./TagConfigJson"
/**
* The LineRenderingConfig gives all details onto how to render a single line of a feature.
@ -74,4 +77,12 @@ export default interface LineRenderingConfigJson {
* type: int
*/
offset?: number | MinimalTagRenderingConfigJson
/**
* question: What PNG-image should be shown along the way?
*
* ifunset: no image is shown along the way
* suggestions: [{if: "./assets/png/oneway.png", then: "Show a oneway error"}]
* type: image
*/
imageAlongWay?: {if: TagConfigJson, then: string}[] | string
}

View file

@ -1,7 +1,8 @@
import WithContextLoader from "./WithContextLoader"
import TagRenderingConfig from "./TagRenderingConfig"
import { Utils } from "../../Utils"
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson"
import { TagUtils } from "../../Logic/Tags/TagUtils"
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
export default class LineRenderingConfig extends WithContextLoader {
public readonly color: TagRenderingConfig
@ -12,6 +13,7 @@ export default class LineRenderingConfig extends WithContextLoader {
public readonly fill: TagRenderingConfig
public readonly fillColor: TagRenderingConfig
public readonly leftRightSensitive: boolean
public readonly imageAlongWay: { if?: TagsFilter, then: string }[]
constructor(json: LineRenderingConfigJson, context: string) {
super(json, context)
@ -21,6 +23,28 @@ export default class LineRenderingConfig extends WithContextLoader {
this.lineCap = this.tr("lineCap", "round")
this.fill = this.tr("fill", undefined)
this.fillColor = this.tr("fillColor", undefined)
this.imageAlongWay = []
if (json.imageAlongWay) {
if (typeof json.imageAlongWay === "string") {
this.imageAlongWay.push({
then: json.imageAlongWay,
})
} else {
for (let i = 0; i < json.imageAlongWay.length; i++) {
const imgAlong = json.imageAlongWay[i]
const ctx = context + ".imageAlongWay[" + i + "]"
if(!imgAlong.then.endsWith(".png")){
throw "An imageAlongWay should always be a PNG image"
}
this.imageAlongWay.push(
{
if: TagUtils.Tag(imgAlong.if, ctx),
then: imgAlong.then,
},
)
}
}
}
if (typeof json.offset === "string") {
json.offset = parseFloat(json.offset)