-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathAttributionComponent.ts
More file actions
82 lines (66 loc) · 2.76 KB
/
AttributionComponent.ts
File metadata and controls
82 lines (66 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {combineLatest as observableCombineLatest, Observable, Subscription} from "rxjs";
import {map} from "rxjs/operators";
import * as vd from "virtual-dom";
import {
ComponentService,
Component,
IComponentConfiguration,
} from "../Component";
import {Node} from "../Graph";
import {
IVNodeHash,
ISize,
} from "../Render";
import {Urls} from "../Utils";
import {
Container,
Navigator,
} from "../Viewer";
export class AttributionComponent extends Component<IComponentConfiguration> {
public static componentName: string = "attribution";
private _disposable: Subscription;
constructor(name: string, container: Container, navigator: Navigator) {
super(name, container, navigator);
}
protected _activate(): void {
this._disposable = observableCombineLatest(
this._navigator.stateService.currentNode$,
this._container.renderService.size$).pipe(
map(
([node, size]: [Node, ISize]): IVNodeHash => {
return {
name: this._name,
vnode: this._getAttributionNode(node.username, node.key, node.capturedAt, size.width),
};
}))
.subscribe(this._container.domRenderer.render$);
}
protected _deactivate(): void {
this._disposable.unsubscribe();
}
protected _getDefaultConfiguration(): IComponentConfiguration {
return {};
}
private _getAttributionNode(username: string, key: string, capturedAt: number, width: number): vd.VNode {
const compact: boolean = width <= 640;
const mapillaryIcon: vd.VNode = vd.h("div.AttributionMapillaryLogo", []);
const mapillaryLink: vd.VNode = vd.h(
"a.AttributionIconContainer",
{ href: Urls.explore, target: "_blank" },
[mapillaryIcon]);
const imageBy: string = compact ? `${username}` : `image by ${username}`;
const imageByContent: vd.VNode = vd.h("div.AttributionUsername", { textContent: imageBy }, []);
const date: Date = new Date(capturedAt);
const formatted: string = compact ? date.toLocaleDateString() : date.toLocaleString();
const dateContent: vd.VNode = vd.h("div.AttributionDate", { textContent: formatted }, []);
const imageLink: vd.VNode =
vd.h(
"a.AttributionImageContainer",
{ href: Urls.exporeImage(key), target: "_blank" },
[imageByContent, dateContent]);
const compactClass: string = compact ? ".AttributionCompact" : "";
return vd.h("div.AttributionContainer" + compactClass, {}, [mapillaryLink, imageLink]);
}
}
ComponentService.register(AttributionComponent);
export default AttributionComponent;