From 6d355cd90cc10ba56bcca7a86c9984dfebf44ca7 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 17 Mar 2021 14:33:22 +0100 Subject: [PATCH] Fix attribution style of wikimedia images --- UI/Image/MapillaryImage.ts | 20 +++++++++----------- UI/Image/WikimediaImage.ts | 29 ++++++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/UI/Image/MapillaryImage.ts b/UI/Image/MapillaryImage.ts index 1df5c3e..53c0e53 100644 --- a/UI/Image/MapillaryImage.ts +++ b/UI/Image/MapillaryImage.ts @@ -11,7 +11,7 @@ import Attribution from "./Attribution"; export class MapillaryImage extends UIElement { /*** - * Dictionary from url to alreayd known license info + * Dictionary from url to already known license info */ private static allLicenseInfos: any = {}; private readonly _imageMeta: UIEventSource; @@ -19,11 +19,11 @@ export class MapillaryImage extends UIElement { constructor(source: string) { super() - - if(source.toLowerCase().startsWith("https://www.mapillary.com/map/im/")){ + + if (source.toLowerCase().startsWith("https://www.mapillary.com/map/im/")) { source = source.substring("https://www.mapillary.com/map/im/".length); } - + this._imageLocation = source; if (MapillaryImage.allLicenseInfos[source] !== undefined) { this._imageMeta = MapillaryImage.allLicenseInfos[source]; @@ -42,20 +42,18 @@ export class MapillaryImage extends UIElement { InnerRender(): string { const url = `https://images.mapillary.com/${this._imageLocation}/thumb-640.jpg?client_id=TXhLaWthQ1d4RUg0czVxaTVoRjFJZzowNDczNjUzNmIyNTQyYzI2`; - const image =new SimpleImageElement(new UIEventSource(url)) - - if (!this._imageMeta?.data ) { + const image = new SimpleImageElement(new UIEventSource(url)) + + const meta = this._imageMeta?.data; + if (!meta) { return image.Render(); } - - const meta = this._imageMeta.data; - return new Combine([ image, new Attribution(meta.artist, meta.license, Svg.mapillary_svg()) ]).SetClass("relative block").Render(); - + } diff --git a/UI/Image/WikimediaImage.ts b/UI/Image/WikimediaImage.ts index f8d4a46..ceae322 100644 --- a/UI/Image/WikimediaImage.ts +++ b/UI/Image/WikimediaImage.ts @@ -3,8 +3,9 @@ import {LicenseInfo, Wikimedia} from "../../Logic/Web/Wikimedia"; import {UIEventSource} from "../../Logic/UIEventSource"; import Svg from "../../Svg"; import Link from "../Base/Link"; -import {FixedUiElement} from "../Base/FixedUiElement"; import Combine from "../Base/Combine"; +import {SimpleImageElement} from "./SimpleImageElement"; +import Attribution from "./Attribution"; export class WikimediaImage extends UIElement { @@ -30,25 +31,27 @@ export class WikimediaImage extends UIElement { this.ListenTo(this._imageMeta); - + } InnerRender(): string { - let url = Wikimedia.ImageNameToUrl(this._imageLocation, 500, 400); - url = url.replace(/'/g, '%27'); + const url = Wikimedia.ImageNameToUrl(this._imageLocation, 500, 400) + .replace(/'/g, '%27'); + const image = new SimpleImageElement(new UIEventSource(url)) + const meta = this._imageMeta?.data; - const wikimediaLink = new Link(Svg.wikimedia_commons_white_img, + if (!meta) { + return image.Render(); + } + new Link(Svg.wikimedia_commons_white_img, `https://commons.wikimedia.org/wiki/${this._imageLocation}`, true) .SetStyle("width:2em;height: 2em"); + + return new Combine([ + image, + new Attribution(meta.artist, meta.license, Svg.wikimedia_commons_white_svg()) + ]).SetClass("relative block").Render() - const attribution = new FixedUiElement(this._imageMeta.data.artist ?? "").SetClass("attribution-author"); - const license = new FixedUiElement(this._imageMeta.data.licenseShortName ?? "").SetClass("license"); - const image = ""; - - return "
" + - image + - new Combine([wikimediaLink, attribution]).SetClass("attribution").Render() + - "
"; }