forked from MapComplete/MapComplete
Visualize attribution in the attribution panel
This commit is contained in:
parent
a16745d0d1
commit
12d99e0323
10 changed files with 122 additions and 28 deletions
|
@ -6,12 +6,18 @@ import State from "../../State";
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
import * as licenses from "../../assets/generated/license_info.json"
|
||||
import SmallLicense from "../../Models/smallLicense";
|
||||
import {Icon} from "leaflet";
|
||||
import Img from "../Base/Img";
|
||||
|
||||
/**
|
||||
* The attribution panel shown on mobile
|
||||
*/
|
||||
export default class AttributionPanel extends Combine {
|
||||
|
||||
private static LicenseObject = AttributionPanel.GenerateLicenses();
|
||||
|
||||
constructor(layoutToUse: UIEventSource<LayoutConfig>) {
|
||||
super([
|
||||
Translations.t.general.attribution.attributionContent,
|
||||
|
@ -19,8 +25,42 @@ export default class AttributionPanel extends Combine {
|
|||
"<br/>",
|
||||
new Attribution(undefined, undefined, State.state.layoutToUse, undefined),
|
||||
"<br/>",
|
||||
"<h4>", Translations.t.general.attribution.iconAttribution.title, "</h4>"
|
||||
|
||||
Translations.t.general.attribution.iconAttribution.title.Clone().SetClass("font-bold pt-12 pb-3"),
|
||||
...Array.from(layoutToUse.data.ExtractImages()).map(AttributionPanel.IconAttribution)
|
||||
]);
|
||||
this.SetClass("flex flex-col")
|
||||
}
|
||||
|
||||
private static IconAttribution(iconPath: string) {
|
||||
console.log("Attribution panel for ", iconPath)
|
||||
if (iconPath.startsWith("http")) {
|
||||
iconPath = "." + new URL(iconPath).pathname;
|
||||
}
|
||||
|
||||
const license: SmallLicense = AttributionPanel.LicenseObject[iconPath]
|
||||
if (license == undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if(license.license.indexOf("trivial")>=0){
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return new Combine([
|
||||
`<img src='${iconPath}' style="width: 50px; height: 50px; margin-right: 0.5em;">`,
|
||||
new Combine([
|
||||
new FixedUiElement(license.authors.join("; ")).SetClass("font-bold"),
|
||||
new Combine([license.license, license.sources.length > 0 ? " - " : "",
|
||||
...license.sources.map(link => `<a href='${link}'>${new URL(link).hostname}</a> `)]).SetClass("block")
|
||||
]).SetClass("flex flex-col")
|
||||
]).SetClass("flex")
|
||||
}
|
||||
|
||||
private static GenerateLicenses() {
|
||||
const allLicenses = {}
|
||||
for (const key in licenses) {
|
||||
const license: SmallLicense = licenses[key];
|
||||
allLicenses[license.path] = license
|
||||
}
|
||||
return allLicenses;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue