Feature: add provider to photosphereview

This commit is contained in:
Pieter Vander Vennet 2025-06-05 11:40:56 +02:00
parent 236d4d87da
commit b269d210bb
5 changed files with 19 additions and 12 deletions

View file

@ -17,7 +17,7 @@ interface ImageFetcher {
* @param lat
* @param lon
*/
fetchImages(lat: number, lon: number): Promise<P4CPicture[]>
fetchImages(lat: number, lon: number): Promise<(P4CPicture & { id: string })[]>
readonly name: string
}
@ -25,7 +25,7 @@ interface ImageFetcher {
class CachedFetcher implements ImageFetcher {
private readonly _fetcher: ImageFetcher
private readonly _zoomlevel: number
private readonly cache: Map<number, Promise<P4CPicture[]>> = new Map<
private readonly cache: Map<number, Promise<(P4CPicture & { id: string })[]>> = new Map<
number,
Promise<P4CPicture[]>
>()
@ -37,7 +37,7 @@ class CachedFetcher implements ImageFetcher {
this.name = fetcher.name
}
fetchImages(lat: number, lon: number): Promise<P4CPicture[]> {
fetchImages(lat: number, lon: number): Promise<(P4CPicture & { id: string })[]> {
const tile = Tiles.embedded_tile(lat, lon, this._zoomlevel)
const tileIndex = Tiles.tile_index(tile.z, tile.x, tile.y)
if (this.cache.has(tileIndex)) {
@ -80,7 +80,7 @@ class NearbyImageUtils {
}
class P4CImageFetcher implements ImageFetcher {
public static readonly services = ["mapillary", "flickr", "kartaview", "wikicommons"] as const
public static readonly services = ["flickr", "kartaview", "wikicommons"] as const
public static readonly apiUrls = ["https://api.flickr.com"]
private _options: { maxDaysOld: number; searchRadius: number }
public readonly name: P4CService
@ -90,7 +90,7 @@ class P4CImageFetcher implements ImageFetcher {
this._options = options
}
async fetchImages(lat: number, lon: number): Promise<P4CPicture[]> {
async fetchImages(lat: number, lon: number): Promise<(P4CPicture & { id: string })[]> {
const picManager = new P4C.PicturesManager({ usefetchers: [this.name] })
const maxAgeSeconds = (this._options?.maxDaysOld ?? 3 * 365) * 24 * 60 * 60 * 1000
const searchRadius = this._options?.searchRadius ?? 100
@ -272,7 +272,7 @@ class MapillaryFetcher implements ImageFetcher {
this.end_captured_at = options?.end_captured_at
}
async fetchImages(lat: number, lon: number): Promise<P4CPicture[]> {
async fetchImages(lat: number, lon: number): Promise<(P4CPicture & { id: string })[]> {
const boundingBox = new BBox([[lon, lat]]).padAbsolute(0.003)
let url =
"https://graph.mapillary.com/images?fields=geometry,computed_geometry,creator,id,captured_at,thumb_256_url,thumb_original_url,compass_angle&bbox=" +
@ -313,7 +313,7 @@ class MapillaryFetcher implements ImageFetcher {
captured_at: number
}[]
}>(url)
const pics: P4CPicture[] = []
const pics: (P4CPicture & { id: string })[] = []
for (const img of response.data) {
const c = img.computed_geometry?.coordinates ?? img.geometry.coordinates
if (img.thumb_original_url === undefined) {
@ -322,6 +322,7 @@ class MapillaryFetcher implements ImageFetcher {
const [lon, lat] = img.computed_geometry.coordinates
pics.push({
pictureUrl: img.thumb_original_url,
id: img.id,
provider: "Mapillary",
coordinates: { lng: c[0], lat: c[1] },
thumbUrl: img.thumb_256_url,
@ -411,7 +412,7 @@ export class CombinedFetcher {
lon: number,
lat: number
): {
images: Store<P4CPicture[]>
images: Store<(P4CPicture & { provider })[]>
state: Store<Record<string, "loading" | "done" | "error">>
} {
const sink = new UIEventSource<P4CPicture[]>([])