refactor: use urls class everywhere

This commit is contained in:
Oscar Lorentzon 2018-02-12 15:23:10 +00:00
parent 2cfc06a00a
commit 8e9ed43a07
4 changed files with 26 additions and 17 deletions

View File

@ -4,11 +4,18 @@ import * as vd from "virtual-dom";
import {Subscription} from "rxjs/Subscription";
import {Container, Navigator} from "../Viewer";
import {
ComponentService,
Component,
IComponentConfiguration,
} from "../Component";
import {Node} from "../Graph";
import {ComponentService, Component, IComponentConfiguration} from "../Component";
import {IVNodeHash} from "../Render";
import {Urls} from "../Utils";
import {
Container,
Navigator,
} from "../Viewer";
export class AttributionComponent extends Component<IComponentConfiguration> {
public static componentName: string = "attribution";
@ -37,13 +44,13 @@ export class AttributionComponent extends Component<IComponentConfiguration> {
private _getAttributionNode(username: string, key: string): vd.VNode {
return vd.h("div.Attribution", {}, [
vd.h("a", {href: `https://www.mapillary.com/app/user/${username}`,
vd.h("a", {href: Urls.exporeUser(username),
target: "_blank",
textContent: `@${username}`,
},
[]),
vd.h("span", {textContent: "|"}, []),
vd.h("a", {href: `https://www.mapillary.com/app/?pKey=${key}&focus=photo`,
vd.h("a", {href: Urls.exporeImage(key),
target: "_blank",
textContent: "mapillary.com",
},

View File

@ -8,19 +8,20 @@ import "rxjs/add/operator/filter";
import "rxjs/add/operator/map";
import "rxjs/add/operator/withLatestFrom";
import {Node} from "../Graph";
import {
Container,
Navigator,
} from "../Viewer";
import {
CoverState,
ICoverConfiguration,
ComponentService,
Component,
} from "../Component";
import {Node} from "../Graph";
import {IVNodeHash} from "../Render";
import {Urls} from "../Utils";
import {
Container,
ImageSize,
Navigator,
} from "../Viewer";
export class CoverComponent extends Component<ICoverConfiguration> {
public static componentName: string = "cover";
@ -81,14 +82,13 @@ export class CoverComponent extends Component<ICoverConfiguration> {
return vd.h(cover, [
this._getCoverBackgroundVNode(conf),
vd.h("button.CoverButton", { onclick: (): void => { this.configure({ state: CoverState.Loading }); } }, ["Explore"]),
vd.h("a.CoverLogo", {href: `https://www.mapillary.com`, target: "_blank"}, []),
vd.h("a.CoverLogo", {href: Urls.explore, target: "_blank"}, []),
]);
}
private _getCoverBackgroundVNode(conf: ICoverConfiguration): vd.VNode {
let url: string = conf.src != null ?
`url(${conf.src})` :
`url(https://d1cuyjsrcm0gby.cloudfront.net/${conf.key}/thumb-640.jpg)`;
`url(${conf.src})` : Urls.thumbnail(conf.key, ImageSize.Size640);
let properties: vd.createProperties = { style: { backgroundImage: url } };

View File

@ -317,7 +317,7 @@ export class NodeCache {
return Observable.create(
(subscriber: Subscriber<ILoadStatusObject<HTMLImageElement>>): void => {
let xmlHTTP: XMLHttpRequest = new XMLHttpRequest();
xmlHTTP.open("GET", Urls.thumbnail(key, imageSize), true);
xmlHTTP.open("GET", Urls.thumbnail(key, imageSize, Urls.origin), true);
xmlHTTP.responseType = "arraybuffer";
xmlHTTP.timeout = 15000;

View File

@ -41,8 +41,10 @@ export class Urls {
return `${Urls._scheme}://${Urls._meshHost}/v2/mesh/${key}`;
}
public static thumbnail(key: string, size: number): string {
return `${Urls._scheme}://${Urls._imageHost}/${key}/thumb-${size}.jpg?origin=${Urls.origin}`;
public static thumbnail(key: string, size: number, origin?: string): string {
const query: string = !!origin ? `?origin=${origin}` : "";
return `${Urls._scheme}://${Urls._imageHost}/${key}/thumb-${size}.jpg${query}`;
}
public static setOptions(options: IUrlOptions): void {