forked from MapComplete/MapComplete
UX: show loading icon if images are being loaded
This commit is contained in:
parent
d7509c8d6f
commit
32993df92a
7 changed files with 97 additions and 57 deletions
|
@ -22,7 +22,7 @@ export default class AllImageProviders {
|
|||
...WikimediaImageProvider.commonsPrefixes,
|
||||
...Mapillary.valuePrefixes,
|
||||
...AllImageProviders.dontLoadFromPrefixes,
|
||||
"Category:",
|
||||
"Category:"
|
||||
])
|
||||
|
||||
private static ImageAttributionSource: ImageProvider[] = [
|
||||
|
@ -31,7 +31,7 @@ export default class AllImageProviders {
|
|||
WikidataImageProvider.singleton,
|
||||
WikimediaImageProvider.singleton,
|
||||
Panoramax.singleton,
|
||||
AllImageProviders.genericImageProvider,
|
||||
AllImageProviders.genericImageProvider
|
||||
]
|
||||
public static apiUrls: string[] = [].concat(
|
||||
...AllImageProviders.ImageAttributionSource.map((src) => src.apiUrls())
|
||||
|
@ -44,7 +44,7 @@ export default class AllImageProviders {
|
|||
mapillary: Mapillary.singleton,
|
||||
wikidata: WikidataImageProvider.singleton,
|
||||
wikimedia: WikimediaImageProvider.singleton,
|
||||
panoramax: Panoramax.singleton,
|
||||
panoramax: Panoramax.singleton
|
||||
}
|
||||
|
||||
public static byName(name: string) {
|
||||
|
@ -67,6 +67,28 @@ export default class AllImageProviders {
|
|||
}
|
||||
|
||||
private static readonly _cachedImageStores: Record<string, Store<ProvidedImage[]>> = {}
|
||||
|
||||
/**
|
||||
* Does a guess on the number of images that are probably there.
|
||||
* Will simply count all image tags
|
||||
*
|
||||
* AllImageProviders.estimateNumberOfImages({image:"abc", "mapillary": "123", "panoramax:0"}) // => 3
|
||||
*
|
||||
*/
|
||||
public static estimateNumberOfImages(tags: Record<string, string>, prefixes: string[] = undefined): number {
|
||||
let count = 0
|
||||
|
||||
const allPrefixes = prefixes ?? [].concat(...AllImageProviders.ImageAttributionSource.map(s => s.defaultKeyPrefixes))
|
||||
for (const k in tags) {
|
||||
for (const prefix of allPrefixes) {
|
||||
if (k === prefix || k.startsWith(prefix + ":")) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to extract all image data for this image. Cached on tags?.data?.id
|
||||
*/
|
||||
|
@ -108,7 +130,7 @@ export default class AllImageProviders {
|
|||
*/
|
||||
public static loadImagesFrom(urls: string[]): Store<ProvidedImage[]> {
|
||||
const tags = {
|
||||
id: urls.join(";"),
|
||||
id: urls.join(";")
|
||||
}
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
tags["image:" + i] = urls[i]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue