Feature: load HD-images from mapillary in preview

This commit is contained in:
Pieter Vander Vennet 2023-12-07 01:04:43 +01:00
parent 1748e98bfc
commit 09993c2e44
3 changed files with 31 additions and 18 deletions

View file

@ -5,15 +5,16 @@ import { Utils } from "../../Utils"
export interface ProvidedImage { export interface ProvidedImage {
url: string url: string
url_hd?: string
key: string key: string
provider: ImageProvider, provider: ImageProvider
id: string id: string
} }
export default abstract class ImageProvider { export default abstract class ImageProvider {
public abstract readonly defaultKeyPrefixes: string[] public abstract readonly defaultKeyPrefixes: string[]
public abstract SourceIcon(id?: string, location?: {lon: number, lat: number}): BaseUIElement public abstract SourceIcon(id?: string, location?: { lon: number; lat: number }): BaseUIElement
/** /**
* Given a properies object, maps it onto _all_ the available pictures for this imageProvider * Given a properies object, maps it onto _all_ the available pictures for this imageProvider
@ -29,7 +30,7 @@ export default abstract class ImageProvider {
throw "No `defaultKeyPrefixes` defined by this image provider" throw "No `defaultKeyPrefixes` defined by this image provider"
} }
const relevantUrls = new UIEventSource< const relevantUrls = new UIEventSource<
{ id: string, url: string; key: string; provider: ImageProvider }[] { id: string; url: string; key: string; provider: ImageProvider }[]
>([]) >([])
const seenValues = new Set<string>() const seenValues = new Set<string>()
allTags.addCallbackAndRunD((tags) => { allTags.addCallbackAndRunD((tags) => {
@ -72,6 +73,4 @@ export default abstract class ImageProvider {
public backlink(): string | undefined { public backlink(): string | undefined {
return undefined return undefined
} }
} }

View file

@ -54,10 +54,14 @@ export class Mapillary extends ImageProvider {
return false return false
} }
static createLink(location: { static createLink(
lon: number, location: {
lat: number lon: number
} = undefined, zoom: number = 17, pKey?: string) { lat: number
} = undefined,
zoom: number = 17,
pKey?: string
) {
const params = { const params = {
focus: pKey === undefined ? "map" : "photo", focus: pKey === undefined ? "map" : "photo",
lat: location?.lat, lat: location?.lat,
@ -66,7 +70,11 @@ export class Mapillary extends ImageProvider {
pKey, pKey,
} }
const baselink = `https://www.mapillary.com/app/?` const baselink = `https://www.mapillary.com/app/?`
const paramsStr = Utils.NoNull(Object.keys(params).map(k => params[k] === undefined ? undefined : k + "=" + params[k])) const paramsStr = Utils.NoNull(
Object.keys(params).map((k) =>
params[k] === undefined ? undefined : k + "=" + params[k]
)
)
return baselink + paramsStr.join("&") return baselink + paramsStr.join("&")
} }
@ -97,10 +105,13 @@ export class Mapillary extends ImageProvider {
return ["https://mapillary.com", "https://www.mapillary.com", "https://graph.mapillary.com"] return ["https://mapillary.com", "https://www.mapillary.com", "https://graph.mapillary.com"]
} }
SourceIcon(id: string, location?: { SourceIcon(
lon: number, id: string,
lat: number location?: {
}): BaseUIElement { lon: number
lat: number
}
): BaseUIElement {
const icon = Svg.mapillary_svg() const icon = Svg.mapillary_svg()
if (!id) { if (!id) {
return icon return icon
@ -130,15 +141,18 @@ export class Mapillary extends ImageProvider {
const metadataUrl = const metadataUrl =
"https://graph.mapillary.com/" + "https://graph.mapillary.com/" +
mapillaryId + mapillaryId +
"?fields=thumb_1024_url&&access_token=" + "?fields=thumb_1024_url,thumb_original_url&access_token=" +
Constants.mapillary_client_token_v4 Constants.mapillary_client_token_v4
const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60) const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60)
const url = <string>response["thumb_1024_url"] const url = <string>response["thumb_1024_url"]
console.log(response)
const url_hd = <string>response["thumb_original_url"]
return { return {
id: "" + mapillaryId, id: "" + mapillaryId,
url: url, url,
url_hd,
provider: this, provider: this,
key: key, key,
} }
} }
} }

View file

@ -25,4 +25,4 @@
</script> </script>
<img bind:this={panzoomEl} src={image.url} class="w-fit h-fit"/> <img bind:this={panzoomEl} src={image.url_hd ?? image.url} class="w-full h-auto"/>