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

@ -4,6 +4,7 @@ import { TagUtils } from "./TagUtils"
import { Tag } from "./Tag"
import { RegexTag } from "./RegexTag"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
export class And extends TagsFilter {
public and: TagsFilter[]
@ -429,4 +430,8 @@ export class And extends TagsFilter {
f(this)
this.and.forEach((sub) => sub.visit(f))
}
asMapboxExpression(): ExpressionSpecification {
return ["all", ...this.and.map(t => t.asMapboxExpression())]
}
}

View file

@ -2,6 +2,7 @@ import { TagsFilter } from "./TagsFilter"
import { TagUtils } from "./TagUtils"
import { And } from "./And"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
export class Or extends TagsFilter {
public or: TagsFilter[]
@ -288,4 +289,8 @@ export class Or extends TagsFilter {
f(this)
this.or.forEach((t) => t.visit(f))
}
asMapboxExpression(): ExpressionSpecification {
return ["any", ...this.or.map(t => t.asMapboxExpression())]
}
}

View file

@ -1,6 +1,7 @@
import { Tag } from "./Tag"
import { TagsFilter } from "./TagsFilter"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
export class RegexTag extends TagsFilter {
public readonly key: RegExp | string
@ -357,4 +358,11 @@ export class RegexTag extends TagsFilter {
visit(f: (TagsFilter) => void) {
f(this)
}
asMapboxExpression(): ExpressionSpecification {
if(typeof this.key=== "string" && typeof this.value === "string" ) {
return [this.invert ? "!=" : "==", ["get",this.key], this.value]
}
throw "TODO"
}
}

View file

@ -1,10 +1,12 @@
import { Utils } from "../../Utils"
import { TagsFilter } from "./TagsFilter"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
export class Tag extends TagsFilter {
public key: string
public value: string
constructor(key: string, value: string) {
super()
this.key = key
@ -63,7 +65,7 @@ export class Tag extends TagsFilter {
asOverpass(): string[] {
if (this.value === "") {
// NOT having this key
return ['[!"' + this.key + '"]']
return ["[!\"" + this.key + "\"]"]
}
return [`["${this.key}"="${this.value}"]`]
}
@ -81,7 +83,7 @@ export class Tag extends TagsFilter {
asHumanString(
linkToWiki?: boolean,
shorten?: boolean,
currentProperties?: Record<string, string>
currentProperties?: Record<string, string>,
) {
let v = this.value
if (typeof v !== "string") {
@ -165,4 +167,16 @@ export class Tag extends TagsFilter {
visit(f: (tagsFilter: TagsFilter) => void) {
f(this)
}
asMapboxExpression(): ExpressionSpecification {
if (this.value === "") {
return [
"any",
["!", ["has", this.key]],
["==", ["get", this.key], ""],
]
}
return ["==", ["get", this.key], this.value]
}
}

View file

@ -1,4 +1,5 @@
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
export abstract class TagsFilter {
abstract asOverpass(): string[]
@ -63,4 +64,6 @@ export abstract class TagsFilter {
* Walks the entire tree, every tagsFilter will be passed into the function once
*/
abstract visit(f: (tagsFilter: TagsFilter) => void)
abstract asMapboxExpression(): ExpressionSpecification
}