forked from MapComplete/MapComplete
Studio: add tagInput element
This commit is contained in:
parent
48e976e6b7
commit
2147b8d368
16 changed files with 413 additions and 42 deletions
49
Logic/Web/TagInfo.ts
Normal file
49
Logic/Web/TagInfo.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import exp from "constants"
|
||||
import { Utils } from "../../Utils"
|
||||
|
||||
export interface TagInfoStats {
|
||||
/**
|
||||
* The total number of entries in the data array, **not** the total number of objects known in OSM!
|
||||
*
|
||||
* Use `data.find(item => item.type==="all").count` for this
|
||||
*/
|
||||
total: number
|
||||
data: {
|
||||
type: "all" | "nodes" | "ways" | "relations"
|
||||
count: number
|
||||
count_fraction: number
|
||||
}[]
|
||||
}
|
||||
|
||||
export default class TagInfo {
|
||||
private readonly _backend: string
|
||||
|
||||
public static readonly global = new TagInfo()
|
||||
|
||||
constructor(backend = "https://taginfo.openstreetmap.org/") {
|
||||
this._backend = backend
|
||||
}
|
||||
|
||||
public getStats(key: string, value?: string): Promise<TagInfoStats> {
|
||||
let url: string
|
||||
if (value) {
|
||||
url = `${this._backend}api/4/tag/stats?key=${key}&value=${value}`
|
||||
} else {
|
||||
url = `${this._backend}api/4/key/stats?key=${key}`
|
||||
}
|
||||
return Utils.downloadJsonCached(url, 1000 * 60 * 60)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the URL to the webpage containing more information
|
||||
* @param k
|
||||
* @param v
|
||||
*/
|
||||
webUrl(k: string, v: string) {
|
||||
if (v) {
|
||||
return `${this._backend}/tags/${k}=${v}#overview`
|
||||
} else {
|
||||
return `${this._backend}/keys/${k}#overview`
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue