forked from MapComplete/MapComplete
		
	Drop support for mapillary v3.0, small fix for custom themes
This commit is contained in:
		
							parent
							
								
									f9c4b7ae6d
								
							
						
					
					
						commit
						3570cfbaa8
					
				
					 2 changed files with 27 additions and 70 deletions
				
			
		| 
						 | 
					@ -12,42 +12,26 @@ export class Mapillary extends ImageProvider {
 | 
				
			||||||
    public static readonly valuePrefixes = [Mapillary.valuePrefix, "http://mapillary.com", "https://mapillary.com", "http://www.mapillary.com", "https://www.mapillary.com"]
 | 
					    public static readonly valuePrefixes = [Mapillary.valuePrefix, "http://mapillary.com", "https://mapillary.com", "http://www.mapillary.com", "https://www.mapillary.com"]
 | 
				
			||||||
    defaultKeyPrefixes = ["mapillary", "image"]
 | 
					    defaultKeyPrefixes = ["mapillary", "image"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static ExtractKeyFromURL(value: string, failIfNoMath = false): {
 | 
					    /**
 | 
				
			||||||
        key: string,
 | 
					     * Returns the correct key for API v4.0
 | 
				
			||||||
        isApiv4?: boolean
 | 
					     */
 | 
				
			||||||
    } {
 | 
					    private static ExtractKeyFromURL(value: string): number {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let key: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (value.startsWith(Mapillary.valuePrefix)) {
 | 
					 | 
				
			||||||
            const key = value.substring(0, value.lastIndexOf("?")).substring(value.lastIndexOf("/") + 1)
 | 
					 | 
				
			||||||
            return {key: key, isApiv4: !isNaN(Number(key))};
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        const newApiFormat = value.match(/https?:\/\/www.mapillary.com\/app\/\?pKey=([0-9]*)/)
 | 
					        const newApiFormat = value.match(/https?:\/\/www.mapillary.com\/app\/\?pKey=([0-9]*)/)
 | 
				
			||||||
        if (newApiFormat !== null) {
 | 
					        if (newApiFormat !== null) {
 | 
				
			||||||
            return {key: newApiFormat[1], isApiv4: true}
 | 
					            key = newApiFormat[1]
 | 
				
			||||||
 | 
					        } else if (value.startsWith(Mapillary.valuePrefix)) {
 | 
				
			||||||
 | 
					            key = value.substring(0, value.lastIndexOf("?")).substring(value.lastIndexOf("/") + 1)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const mapview = value.match(/https?:\/\/www.mapillary.com\/map\/im\/(.*)/)
 | 
					        const keyAsNumber = Number(key)
 | 
				
			||||||
        if (mapview !== null) {
 | 
					        if (!isNaN(keyAsNumber)) {
 | 
				
			||||||
            const key = mapview[1]
 | 
					            return keyAsNumber
 | 
				
			||||||
            return {key: key, isApiv4: !isNaN(Number(key))};
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return undefined
 | 
				
			||||||
        if (value.toLowerCase().startsWith("https://www.mapillary.com/map/im/")) {
 | 
					 | 
				
			||||||
            // Extract the key of the image
 | 
					 | 
				
			||||||
            value = value.substring("https://www.mapillary.com/map/im/".length);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const matchApi = value.match(/https?:\/\/images.mapillary.com\/([^/]*)(&.*)?/)
 | 
					 | 
				
			||||||
        if (matchApi !== null) {
 | 
					 | 
				
			||||||
            return {key: matchApi[1]};
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (failIfNoMath) {
 | 
					 | 
				
			||||||
            return undefined;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return {key: value, isApiv4: !isNaN(Number(value))};
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SourceIcon(backlinkSource?: string): BaseUIElement {
 | 
					    SourceIcon(backlinkSource?: string): BaseUIElement {
 | 
				
			||||||
| 
						 | 
					@ -59,54 +43,27 @@ export class Mapillary extends ImageProvider {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected async DownloadAttribution(url: string): Promise<LicenseInfo> {
 | 
					    protected async DownloadAttribution(url: string): Promise<LicenseInfo> {
 | 
				
			||||||
 | 
					        const license = new LicenseInfo()
 | 
				
			||||||
        const keyV = Mapillary.ExtractKeyFromURL(url)
 | 
					        license.artist = "Contributor name unavailable";
 | 
				
			||||||
        if (keyV.isApiv4) {
 | 
					        license.license = "CC BY-SA 4.0";
 | 
				
			||||||
            const license = new LicenseInfo()
 | 
					        // license.license = "Creative Commons Attribution-ShareAlike 4.0 International License";
 | 
				
			||||||
            license.artist = "Contributor name unavailable";
 | 
					 | 
				
			||||||
            license.license = "CC BY-SA 4.0";
 | 
					 | 
				
			||||||
            // license.license = "Creative Commons Attribution-ShareAlike 4.0 International License";
 | 
					 | 
				
			||||||
            license.attributionRequired = true;
 | 
					 | 
				
			||||||
            return license
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        const key = keyV.key
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        const metadataURL = `https://a.mapillary.com/v3/images/${key}?client_id=TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2`
 | 
					 | 
				
			||||||
        const data = await Utils.downloadJson(metadataURL)
 | 
					 | 
				
			||||||
        const license = new LicenseInfo();
 | 
					 | 
				
			||||||
        license.artist = data.properties?.username;
 | 
					 | 
				
			||||||
        license.licenseShortName = "CC BY-SA 4.0";
 | 
					 | 
				
			||||||
        license.license = "Creative Commons Attribution-ShareAlike 4.0 International License";
 | 
					 | 
				
			||||||
        license.attributionRequired = true;
 | 
					        license.attributionRequired = true;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return license
 | 
					        return license
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private async PrepareUrlAsync(key: string, value: string): Promise<ProvidedImage> {
 | 
					    private async PrepareUrlAsync(key: string, value: string): Promise<ProvidedImage> {
 | 
				
			||||||
        const failIfNoMatch = key.indexOf("mapillary") < 0
 | 
					        const mapillaryId = Mapillary.ExtractKeyFromURL(value)
 | 
				
			||||||
        const keyV = Mapillary.ExtractKeyFromURL(value, failIfNoMatch)
 | 
					        if (mapillaryId === undefined) {
 | 
				
			||||||
        if (keyV === undefined) {
 | 
					 | 
				
			||||||
            return undefined;
 | 
					            return undefined;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!keyV.isApiv4) {
 | 
					        const metadataUrl = 'https://graph.mapillary.com/' + mapillaryId + '?fields=thumb_1024_url&&access_token=' + Constants.mapillary_client_token_v4;
 | 
				
			||||||
            const url = `https://images.mapillary.com/${keyV.key}/thumb-640.jpg?client_id=${Constants.mapillary_client_token_v3}`
 | 
					        const response = await Utils.downloadJson(metadataUrl)
 | 
				
			||||||
            return {
 | 
					        const url = <string>response["thumb_1024_url"];
 | 
				
			||||||
                url: url,
 | 
					        return {
 | 
				
			||||||
                provider: this,
 | 
					            url: url,
 | 
				
			||||||
                key: key
 | 
					            provider: this,
 | 
				
			||||||
            }
 | 
					            key: key
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            const mapillaryId = keyV.key;
 | 
					 | 
				
			||||||
            const metadataUrl = 'https://graph.mapillary.com/' + mapillaryId + '?fields=thumb_1024_url&&access_token=' + Constants.mapillary_client_token_v4;
 | 
					 | 
				
			||||||
            const response = await Utils.downloadJson(metadataUrl)
 | 
					 | 
				
			||||||
            const url = <string>response["thumb_1024_url"];
 | 
					 | 
				
			||||||
            return {
 | 
					 | 
				
			||||||
                url: url,
 | 
					 | 
				
			||||||
                provider: this,
 | 
					 | 
				
			||||||
                key: key
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ export default class LegacyJsonConvert {
 | 
				
			||||||
            // This is a legacy format, lets create a pointRendering
 | 
					            // This is a legacy format, lets create a pointRendering
 | 
				
			||||||
            let location: ("point" | "centroid")[] = ["point"]
 | 
					            let location: ("point" | "centroid")[] = ["point"]
 | 
				
			||||||
            let wayHandling: number = config["wayHandling"] ?? 0
 | 
					            let wayHandling: number = config["wayHandling"] ?? 0
 | 
				
			||||||
            if (wayHandling === 2) {
 | 
					            if (wayHandling !== 0) {
 | 
				
			||||||
                location = ["point", "centroid"]
 | 
					                location = ["point", "centroid"]
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            config.mapRendering = [
 | 
					            config.mapRendering = [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue