forked from MapComplete/MapComplete
Add support for mapillary api v4, fixes #364
This commit is contained in:
parent
5d81e7d792
commit
c8eacaa409
9 changed files with 117 additions and 63 deletions
|
@ -4,11 +4,15 @@ import BaseUIElement from "../BaseUIElement";
|
|||
export default class Img extends BaseUIElement {
|
||||
private _src: string;
|
||||
private readonly _rawSvg: boolean;
|
||||
private _options: { fallbackImage?: string };
|
||||
|
||||
constructor(src: string, rawSvg = false) {
|
||||
constructor(src: string, rawSvg = false, options?: {
|
||||
fallbackImage?: string
|
||||
}) {
|
||||
super();
|
||||
this._src = src;
|
||||
this._rawSvg = rawSvg;
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
static AsData(source: string) {
|
||||
|
@ -23,7 +27,7 @@ export default class Img extends BaseUIElement {
|
|||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
|
||||
const self = this;
|
||||
if (this._rawSvg) {
|
||||
const e = document.createElement("div")
|
||||
e.innerHTML = this._src
|
||||
|
@ -35,6 +39,15 @@ export default class Img extends BaseUIElement {
|
|||
el.onload = () => {
|
||||
el.style.opacity = "1"
|
||||
}
|
||||
el.onerror = () => {
|
||||
if (self._options?.fallbackImage) {
|
||||
if(el.src === self._options.fallbackImage){
|
||||
// Sigh... nothing to be done anymore
|
||||
return;
|
||||
}
|
||||
el.src = self._options.fallbackImage
|
||||
}
|
||||
}
|
||||
return el;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue