Refactoring: remove unused file

This commit is contained in:
Pieter Vander Vennet 2025-07-11 20:24:51 +02:00
parent 4e033a93a5
commit 6383311dc2
4 changed files with 34 additions and 76 deletions

26
src/Logic/Osm/OsmWiki.ts Normal file
View file

@ -0,0 +1,26 @@
/**
* Various tools for the OSM wiki
*/
export default class OsmWiki {
/**
* Create a link to the wiki for the given key and value (optional)
* @param key
* @param value
*/
public static constructLink(key: string, value?: string) : string{
if (value !== undefined) {
return `https://wiki.openstreetmap.org/wiki/Tag:${key}%3D${value}`
}
return "https://wiki.openstreetmap.org/wiki/Key:" + key
}
public static constructLinkMd(key: string, value?: string) : string {
const link = this.constructLink(key, value)
let displayed = key
if(value){
displayed += "="+value
}
return `[${displayed}](${link})`
}
}

View file

@ -6,6 +6,7 @@ import { RegexTag } from "./RegexTag"
import { OptimizedTag } from "./TagTypes"
import { Or } from "./Or"
import { And } from "./And"
import OsmWiki from "../Osm/OsmWiki"
export class Tag extends TagsFilter {
public key: string
@ -113,10 +114,12 @@ export class Tag extends TagsFilter {
return "<span class='line-through'>" + this.key + "</span>"
}
if (linkToWiki) {
const hrefK = OsmWiki.constructLink(this.key)
const hrefKV = OsmWiki.constructLink(this.key, this.value)
return (
`<a href='https://wiki.openstreetmap.org/wiki/Key:${this.key}' target='_blank'>${this.key}</a>` +
`<a href='${hrefK}' target='_blank'>${this.key}</a>` +
`=` +
`<a href='https://wiki.openstreetmap.org/wiki/Tag:${this.key}%3D${this.value}' target='_blank'>${v}</a>`
`<a href='${hrefKV}' target='_blank'>${v}</a>`
)
}
return this.key + "=" + v

View file

@ -13,7 +13,6 @@ import PointRenderingConfig from "./PointRenderingConfig"
import WithContextLoader from "./WithContextLoader"
import LineRenderingConfig from "./LineRenderingConfig"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import Link from "../../UI/Base/Link"
import { Utils } from "../../Utils"
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
import FilterConfigJson from "./Json/FilterConfigJson"
@ -22,6 +21,7 @@ import Constants from "../Constants"
import { QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
import MarkdownUtils from "../../Utils/MarkdownUtils"
import { And } from "../../Logic/Tags/And"
import OsmWiki from "../../Logic/Osm/OsmWiki"
export default class LayerConfig extends WithContextLoader {
public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const
@ -574,7 +574,7 @@ export default class LayerConfig extends WithContextLoader {
.filter((values) => values.key !== "id")
.map((values) => {
const embedded: string[] = values.values?.map((v) =>
Link.OsmWiki(values.key, v, true).SetClass("mr-2").AsMarkdown()
OsmWiki.constructLinkMd(values.key, v)
) ?? ["_no preset options defined, or no values in them_"]
const statistics = `https://taghistory.raifer.tech/?#***/${encodeURIComponent(
values.key
@ -584,8 +584,7 @@ export default class LayerConfig extends WithContextLoader {
[
`<a target="_blank" href='${tagInfo}'><img src='https://mapcomplete.org/assets/svg/search.svg' height='18px'></a>`,
`<a target="_blank" href='${statistics}'><img src='https://mapcomplete.org/assets/svg/statistics.svg' height='18px'></a>`,
Link.OsmWiki(values.key).AsMarkdown(),
OsmWiki.constructLinkMd(values.key),
].join(" "),
values.type === undefined
? "Multiple choice"

View file

@ -1,70 +0,0 @@
import Translations from "../i18n/Translations"
import BaseUIElement from "../BaseUIElement"
import { Store } from "../../Logic/UIEventSource"
export default class Link extends BaseUIElement {
private readonly _href: string | Store<string>
private readonly _embeddedShow: BaseUIElement
private readonly _newTab: boolean
private readonly _download: string
constructor(
embeddedShow: BaseUIElement | string,
href: string | Store<string>,
newTab: boolean = false,
download: string = undefined
) {
super()
this._download = download
this._embeddedShow = Translations.W(embeddedShow)
this._href = href
this._newTab = newTab
if (this._embeddedShow === undefined) {
throw "Error: got a link where embeddedShow is undefined"
}
this.onClick(() => {})
}
public static OsmWiki(key: string, value?: string, hideKey = false) {
if (value !== undefined) {
let k = ""
if (!hideKey) {
k = key + "="
}
return new Link(
k + value,
`https://wiki.openstreetmap.org/wiki/Tag:${key}%3D${value}`,
true
)
}
return new Link(key, "https://wiki.openstreetmap.org/wiki/Key:" + key, true)
}
AsMarkdown(): string {
// @ts-ignore
return `[${this._embeddedShow.AsMarkdown()}](${this._href.data ?? this._href})`
}
protected InnerConstructElement(): HTMLElement {
const embeddedShow = this._embeddedShow?.ConstructElement()
if (embeddedShow === undefined) {
return undefined
}
const el = document.createElement("a")
if (typeof this._href === "string") {
el.setAttribute("href", this._href)
} else {
this._href.addCallbackAndRun((href) => {
el.setAttribute("href", href)
})
}
if (this._newTab) {
el.target = "_blank"
}
if (this._download) {
el.setAttribute("download", this._download)
}
el.appendChild(embeddedShow)
return el
}
}