Feature: add support for panoramax picturs for non-default keys (e.g. image:menu)
This commit is contained in:
parent
967f2f1617
commit
55cfd65f3b
5 changed files with 20 additions and 15 deletions
|
@ -90,13 +90,14 @@ export default class AllImageProviders {
|
|||
this._cache.set(cacheKey, source)
|
||||
const allSources: Store<ProvidedImage[]>[] = []
|
||||
for (const imageProvider of AllImageProviders.ImageAttributionSource) {
|
||||
let prefixes = imageProvider.defaultKeyPrefixes
|
||||
if (tagKey !== undefined) {
|
||||
prefixes = tagKey
|
||||
}
|
||||
|
||||
|
||||
const singleSource = imageProvider.GetRelevantUrls(tags, {
|
||||
prefixes: prefixes,
|
||||
/*
|
||||
By default, 'GetRelevantUrls' uses the defaultKeyPrefixes.
|
||||
However, we override them if a custom image tag is set, e.g. 'image:menu'
|
||||
*/
|
||||
prefixes: tagKey ?? imageProvider.defaultKeyPrefixes,
|
||||
})
|
||||
allSources.push(singleSource)
|
||||
singleSource.addCallbackAndRunD((_) => {
|
||||
|
|
|
@ -49,7 +49,7 @@ export default abstract class ImageProvider {
|
|||
if(key === "panoramax"){
|
||||
console.log("Inspecting", key,"against", prefixes)
|
||||
}
|
||||
if (!prefixes.some((prefix) => key.startsWith(prefix))) {
|
||||
if (!prefixes.some((prefix) => key === prefix || key.match(new RegExp(prefix+":[0-9]+")))) {
|
||||
continue
|
||||
}
|
||||
const values = Utils.NoEmpty(tags[key]?.split(";")?.map((v) => v.trim()) ?? [])
|
||||
|
|
|
@ -62,7 +62,7 @@ export class ImageUploadManager {
|
|||
* Gets various counters.
|
||||
* Note that counters can only increase
|
||||
* If a retry was a success, both 'retrySuccess' _and_ 'uploadFinished' will be increased
|
||||
* @param featureId: the id of the feature you want information for. '*' has a global counter
|
||||
* @param featureId the id of the feature you want information for. '*' has a global counter
|
||||
*/
|
||||
public getCountsFor(featureId: string | "*"): {
|
||||
retried: Store<number>
|
||||
|
@ -157,13 +157,14 @@ export class ImageUploadManager {
|
|||
const feature = this._indexedFeatures.featuresById.data.get(featureId)
|
||||
location = GeoOperations.centerpointCoordinates(feature)
|
||||
}
|
||||
let absoluteUrl: string
|
||||
try {
|
||||
;({ key, value } = await this._uploader.uploadImage(blob, location, author))
|
||||
;({ key, value, absoluteUrl } = await this._uploader.uploadImage(blob, location, author))
|
||||
} catch (e) {
|
||||
this.increaseCountFor(this._uploadRetried, featureId)
|
||||
console.error("Could not upload image, trying again:", e)
|
||||
try {
|
||||
;({ key, value } = await this._uploader.uploadImage(blob, location, author))
|
||||
;({ key, value , absoluteUrl} = await this._uploader.uploadImage(blob, location, author))
|
||||
this.increaseCountFor(this._uploadRetriedSuccess, featureId)
|
||||
} catch (e) {
|
||||
console.error("Could again not upload image due to", e)
|
||||
|
@ -173,12 +174,15 @@ export class ImageUploadManager {
|
|||
}
|
||||
console.log("Uploading image done, creating action for", featureId)
|
||||
key = targetKey ?? key
|
||||
if(targetKey){
|
||||
// This is a non-standard key, so we use the image link directly
|
||||
value = absoluteUrl
|
||||
}
|
||||
this.increaseCountFor(this._uploadFinished, featureId)
|
||||
const action = new LinkImageAction(featureId, key, value, properties, {
|
||||
return new LinkImageAction(featureId, key, value, properties, {
|
||||
theme: theme ?? this._layout.id,
|
||||
changeType: "add-image",
|
||||
})
|
||||
return action
|
||||
}
|
||||
|
||||
private getCounterFor(collection: Map<string, UIEventSource<number>>, key: string | "*") {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import { Feature } from "geojson"
|
||||
|
||||
export interface ImageUploader {
|
||||
maxFileSizeInMegabytes?: number
|
||||
/**
|
||||
|
@ -10,5 +8,5 @@ export interface ImageUploader {
|
|||
blob: File,
|
||||
currentGps: [number,number],
|
||||
author: string
|
||||
): Promise<{ key: string; value: string }>
|
||||
): Promise<{ key: string; value: string, absoluteUrl: string }>
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class PanoramaxImageProvider extends ImageProvider {
|
|||
|
||||
public static readonly singleton = new PanoramaxImageProvider()
|
||||
|
||||
public defaultKeyPrefixes: string[] = ["panoramax", "image"]
|
||||
public defaultKeyPrefixes: string[] = ["panoramax"]
|
||||
public readonly name: string = "panoramax"
|
||||
|
||||
private static knownMeta: Record<string, ImageData> = {}
|
||||
|
@ -128,6 +128,7 @@ export class PanoramaxUploader implements ImageUploader {
|
|||
async uploadImage(blob: File, currentGps: [number, number], author: string): Promise<{
|
||||
key: string;
|
||||
value: string;
|
||||
absoluteUrl: string
|
||||
}> {
|
||||
|
||||
const tags = await ExifReader.load(blob)
|
||||
|
@ -152,6 +153,7 @@ export class PanoramaxUploader implements ImageUploader {
|
|||
return {
|
||||
key: "panoramax",
|
||||
value: img.id,
|
||||
absoluteUrl: img.assets.hd.href
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue