forked from MapComplete/MapComplete
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)
|
this._cache.set(cacheKey, source)
|
||||||
const allSources: Store<ProvidedImage[]>[] = []
|
const allSources: Store<ProvidedImage[]>[] = []
|
||||||
for (const imageProvider of AllImageProviders.ImageAttributionSource) {
|
for (const imageProvider of AllImageProviders.ImageAttributionSource) {
|
||||||
let prefixes = imageProvider.defaultKeyPrefixes
|
|
||||||
if (tagKey !== undefined) {
|
|
||||||
prefixes = tagKey
|
|
||||||
}
|
|
||||||
|
|
||||||
const singleSource = imageProvider.GetRelevantUrls(tags, {
|
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)
|
allSources.push(singleSource)
|
||||||
singleSource.addCallbackAndRunD((_) => {
|
singleSource.addCallbackAndRunD((_) => {
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default abstract class ImageProvider {
|
||||||
if(key === "panoramax"){
|
if(key === "panoramax"){
|
||||||
console.log("Inspecting", key,"against", prefixes)
|
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
|
continue
|
||||||
}
|
}
|
||||||
const values = Utils.NoEmpty(tags[key]?.split(";")?.map((v) => v.trim()) ?? [])
|
const values = Utils.NoEmpty(tags[key]?.split(";")?.map((v) => v.trim()) ?? [])
|
||||||
|
|
|
@ -62,7 +62,7 @@ export class ImageUploadManager {
|
||||||
* Gets various counters.
|
* Gets various counters.
|
||||||
* Note that counters can only increase
|
* Note that counters can only increase
|
||||||
* If a retry was a success, both 'retrySuccess' _and_ 'uploadFinished' will be increased
|
* 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 | "*"): {
|
public getCountsFor(featureId: string | "*"): {
|
||||||
retried: Store<number>
|
retried: Store<number>
|
||||||
|
@ -157,13 +157,14 @@ export class ImageUploadManager {
|
||||||
const feature = this._indexedFeatures.featuresById.data.get(featureId)
|
const feature = this._indexedFeatures.featuresById.data.get(featureId)
|
||||||
location = GeoOperations.centerpointCoordinates(feature)
|
location = GeoOperations.centerpointCoordinates(feature)
|
||||||
}
|
}
|
||||||
|
let absoluteUrl: string
|
||||||
try {
|
try {
|
||||||
;({ key, value } = await this._uploader.uploadImage(blob, location, author))
|
;({ key, value, absoluteUrl } = await this._uploader.uploadImage(blob, location, author))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.increaseCountFor(this._uploadRetried, featureId)
|
this.increaseCountFor(this._uploadRetried, featureId)
|
||||||
console.error("Could not upload image, trying again:", e)
|
console.error("Could not upload image, trying again:", e)
|
||||||
try {
|
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)
|
this.increaseCountFor(this._uploadRetriedSuccess, featureId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Could again not upload image due to", 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)
|
console.log("Uploading image done, creating action for", featureId)
|
||||||
key = targetKey ?? key
|
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)
|
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,
|
theme: theme ?? this._layout.id,
|
||||||
changeType: "add-image",
|
changeType: "add-image",
|
||||||
})
|
})
|
||||||
return action
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCounterFor(collection: Map<string, UIEventSource<number>>, key: string | "*") {
|
private getCounterFor(collection: Map<string, UIEventSource<number>>, key: string | "*") {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { Feature } from "geojson"
|
|
||||||
|
|
||||||
export interface ImageUploader {
|
export interface ImageUploader {
|
||||||
maxFileSizeInMegabytes?: number
|
maxFileSizeInMegabytes?: number
|
||||||
/**
|
/**
|
||||||
|
@ -10,5 +8,5 @@ export interface ImageUploader {
|
||||||
blob: File,
|
blob: File,
|
||||||
currentGps: [number,number],
|
currentGps: [number,number],
|
||||||
author: string
|
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 static readonly singleton = new PanoramaxImageProvider()
|
||||||
|
|
||||||
public defaultKeyPrefixes: string[] = ["panoramax", "image"]
|
public defaultKeyPrefixes: string[] = ["panoramax"]
|
||||||
public readonly name: string = "panoramax"
|
public readonly name: string = "panoramax"
|
||||||
|
|
||||||
private static knownMeta: Record<string, ImageData> = {}
|
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<{
|
async uploadImage(blob: File, currentGps: [number, number], author: string): Promise<{
|
||||||
key: string;
|
key: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
absoluteUrl: string
|
||||||
}> {
|
}> {
|
||||||
|
|
||||||
const tags = await ExifReader.load(blob)
|
const tags = await ExifReader.load(blob)
|
||||||
|
@ -152,6 +153,7 @@ export class PanoramaxUploader implements ImageUploader {
|
||||||
return {
|
return {
|
||||||
key: "panoramax",
|
key: "panoramax",
|
||||||
value: img.id,
|
value: img.id,
|
||||||
|
absoluteUrl: img.assets.hd.href
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue