forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
aa50d33b81
53 changed files with 1094 additions and 411 deletions
|
@ -14,18 +14,19 @@ import {Utils} from "../../Utils";
|
|||
export default class AvailableBaseLayers {
|
||||
|
||||
|
||||
public static osmCarto: BaseLayer =
|
||||
public static osmCarto: BaseLayer =
|
||||
{
|
||||
id: "osm",
|
||||
name: "OpenStreetMap",
|
||||
layer: AvailableBaseLayers.CreateBackgroundLayer("osm", "OpenStreetMap",
|
||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png", "OpenStreetMap", "https://openStreetMap.org/copyright",
|
||||
19,
|
||||
false, false),
|
||||
name: "OpenStreetMap",
|
||||
layer: () => AvailableBaseLayers.CreateBackgroundLayer("osm", "OpenStreetMap",
|
||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png", "OpenStreetMap", "https://openStreetMap.org/copyright",
|
||||
19,
|
||||
false, false),
|
||||
feature: null,
|
||||
max_zoom: 19,
|
||||
min_zoom: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static layerOverview = AvailableBaseLayers.LoadRasterIndex().concat(AvailableBaseLayers.LoadProviderIndex());
|
||||
|
@ -123,7 +124,7 @@ export default class AvailableBaseLayers {
|
|||
continue
|
||||
}
|
||||
|
||||
const leafletLayer = AvailableBaseLayers.CreateBackgroundLayer(
|
||||
const leafletLayer: () => TileLayer = () => AvailableBaseLayers.CreateBackgroundLayer(
|
||||
props.id,
|
||||
props.name,
|
||||
props.url,
|
||||
|
@ -150,10 +151,10 @@ export default class AvailableBaseLayers {
|
|||
private static LoadProviderIndex(): BaseLayer[] {
|
||||
// @ts-ignore
|
||||
X; // Import X to make sure the namespace is not optimized away
|
||||
function l(id: string, name: string) {
|
||||
function l(id: string, name: string) : BaseLayer{
|
||||
try {
|
||||
const layer: any = L.tileLayer.provider(id, undefined);
|
||||
return {
|
||||
const layer: any = () => L.tileLayer.provider(id, undefined);
|
||||
const baseLayer : BaseLayer = {
|
||||
feature: null,
|
||||
id: id,
|
||||
name: name,
|
||||
|
@ -161,6 +162,7 @@ export default class AvailableBaseLayers {
|
|||
min_zoom: layer.minzoom,
|
||||
max_zoom: layer.maxzoom
|
||||
}
|
||||
return baseLayer
|
||||
} catch (e) {
|
||||
console.error("Could not find provided layer", name, e);
|
||||
return null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {ImagesInCategory, Wikidata, Wikimedia} from "../Web/Wikimedia";
|
||||
import {ImagesInCategory, Wikidata, Wikimedia} from "../ImageProviders/Wikimedia";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
/**
|
||||
|
|
9
Logic/ImageProviders/AllImageProviders.ts
Normal file
9
Logic/ImageProviders/AllImageProviders.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import {Mapillary} from "./Mapillary";
|
||||
import {Wikimedia} from "./Wikimedia";
|
||||
import {Imgur} from "./Imgur";
|
||||
|
||||
export default class AllImageProviders{
|
||||
|
||||
public static ImageAttributionSource = [Imgur.singleton, Mapillary.singleton, Wikimedia.singleton]
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import BaseUIElement from "../../UI/BaseUIElement";
|
|||
|
||||
export default abstract class ImageAttributionSource {
|
||||
|
||||
|
||||
private _cache = new Map<string, UIEventSource<LicenseInfo>>()
|
||||
|
||||
GetAttributionFor(url: string): UIEventSource<LicenseInfo> {
|
||||
|
@ -22,6 +21,7 @@ export default abstract class ImageAttributionSource {
|
|||
|
||||
public abstract SourceIcon(backlinkSource?: string) : BaseUIElement;
|
||||
protected abstract DownloadAttribution(url: string): UIEventSource<LicenseInfo>;
|
||||
/*Converts a value to a URL. Can return null if not applicable*/
|
||||
public PrepareUrl(value: string): string{
|
||||
return value;
|
||||
}
|
|
@ -4,6 +4,7 @@ import BaseUIElement from "../../UI/BaseUIElement";
|
|||
import Svg from "../../Svg";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import Link from "../../UI/Base/Link";
|
||||
import {Utils} from "../../Utils";
|
||||
|
||||
/**
|
||||
* This module provides endpoints for wikipedia/wikimedia and others
|
||||
|
@ -138,21 +139,28 @@ export class Wikimedia extends ImageAttributionSource {
|
|||
"api.php?action=query&prop=imageinfo&iiprop=extmetadata&" +
|
||||
"titles=" + filename +
|
||||
"&format=json&origin=*";
|
||||
console.log("Getting attribution at ", url)
|
||||
$.getJSON(url, function (data) {
|
||||
const licenseInfo = new LicenseInfo();
|
||||
const license = data.query.pages[-1].imageinfo[0].extmetadata;
|
||||
Utils.downloadJson(url).then(
|
||||
data =>{
|
||||
const licenseInfo = new LicenseInfo();
|
||||
const license = (data.query.pages[-1].imageinfo ?? [])[0]?.extmetadata;
|
||||
if(license === undefined){
|
||||
console.error("This file has no usable metedata or license attached... Please fix the license info file yourself!")
|
||||
source.setData(null)
|
||||
return;
|
||||
}
|
||||
|
||||
licenseInfo.artist = license.Artist?.value;
|
||||
licenseInfo.license = license.License?.value;
|
||||
licenseInfo.copyrighted = license.Copyrighted?.value;
|
||||
licenseInfo.attributionRequired = license.AttributionRequired?.value;
|
||||
licenseInfo.usageTerms = license.UsageTerms?.value;
|
||||
licenseInfo.licenseShortName = license.LicenseShortName?.value;
|
||||
licenseInfo.credit = license.Credit?.value;
|
||||
licenseInfo.description = license.ImageDescription?.value;
|
||||
source.setData(licenseInfo);
|
||||
});
|
||||
licenseInfo.artist = license.Artist?.value;
|
||||
licenseInfo.license = license.License?.value;
|
||||
licenseInfo.copyrighted = license.Copyrighted?.value;
|
||||
licenseInfo.attributionRequired = license.AttributionRequired?.value;
|
||||
licenseInfo.usageTerms = license.UsageTerms?.value;
|
||||
licenseInfo.licenseShortName = license.LicenseShortName?.value;
|
||||
licenseInfo.credit = license.Credit?.value;
|
||||
licenseInfo.description = license.ImageDescription?.value;
|
||||
source.setData(licenseInfo);
|
||||
}
|
||||
)
|
||||
|
||||
return source;
|
||||
|
||||
}
|
|
@ -97,7 +97,7 @@ export class OsmPreferences {
|
|||
|
||||
public GetPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> {
|
||||
key = prefix + key;
|
||||
key = key.replace(/[:\\\/"' {}.%_]/g, '')
|
||||
key = key.replace(/[:\\\/"' {}.%]/g, '')
|
||||
if (key.length >= 255) {
|
||||
throw "Preferences: key length to big";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue