UX: add link to Mapillary, fix #1637

This commit is contained in:
Pieter Vander Vennet 2023-12-02 03:12:34 +01:00
parent c7089c27a0
commit 804005e402
12 changed files with 82 additions and 37 deletions

View file

@ -4,6 +4,7 @@ import Svg from "../../Svg"
import { Utils } from "../../Utils"
import { LicenseInfo } from "./LicenseInfo"
import Constants from "../../Models/Constants"
import Link from "../../UI/Base/Link"
export class Mapillary extends ImageProvider {
public static readonly singleton = new Mapillary()
@ -17,10 +18,6 @@ export class Mapillary extends ImageProvider {
]
defaultKeyPrefixes = ["mapillary", "image"]
apiUrls(): string[] {
return ["https://mapillary.com", "https://www.mapillary.com", "https://graph.mapillary.com"]
}
/**
* Indicates that this is the same URL
* Ignores 'stp' parameter
@ -57,6 +54,22 @@ export class Mapillary extends ImageProvider {
return false
}
static createLink(location: {
lon: number,
lat: number
} = undefined, zoom: number = 17, pKey?: string) {
const params = {
focus: pKey === undefined ? "map" : "photo",
lat: location.lat,
lng: location.lon,
z: location === undefined ? undefined : Math.max((zoom ?? 2) - 1, 1),
pKey,
}
const baselink = `https://www.mapillary.com/app/?`
const paramsStr = Utils.NoNull(Object.keys(params).map(k => params[k] === undefined ? undefined : k + "=" + params[k]))
return baselink + paramsStr.join("&")
}
/**
* Returns the correct key for API v4.0
*/
@ -80,8 +93,19 @@ export class Mapillary extends ImageProvider {
return undefined
}
SourceIcon(backlinkSource?: string): BaseUIElement {
return Svg.mapillary_svg()
apiUrls(): string[] {
return ["https://mapillary.com", "https://www.mapillary.com", "https://graph.mapillary.com"]
}
SourceIcon(id: string, location?: {
lon: number,
lat: number
}): BaseUIElement {
const icon = Svg.mapillary_svg()
if (!id) {
return icon
}
return new Link(icon, Mapillary.createLink(location, 16, "" + id), true)
}
async ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]> {
@ -111,6 +135,7 @@ export class Mapillary extends ImageProvider {
const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60)
const url = <string>response["thumb_1024_url"]
return {
id: "" + mapillaryId,
url: url,
provider: this,
key: key,