/
AttributionController.ts
178 lines (134 loc) · 4.21 KB
/
AttributionController.ts
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import ContainerController from "./ContainerController"
/**
* 著作権表示の表示制御
*/
class AttributionController extends ContainerController
{
private _attributions: AttributionController.Attribution[];
/**
* コンストラクタ
* @param container ルートコンテナ(Viewerクラスのcontainer_element)
* @param options 表示オプション
*/
constructor( container: HTMLElement | string, options: AttributionController.Option = {} )
{
super( container, options );
this._position = options.position || ContainerController.ContainerPosition.BOTTOM_RIGHT;
this._attributions = [];
if ( options && options.attributions ) {
this._copyAttributions(options.attributions);
} else {
this._copyAttributions(AttributionController._default_attribution);
}
}
/**
* 著作権表示の追加
*
* @param attribution 著作権表示オブジェクト
*/
addAttribution( attribution: AttributionController.Attribution ): void
{
this._attributions.push( attribution );
// コンテナの再作成
this._deleteContainer();
this.createContainer();
}
/**
* 著作権表示のリセット
*/
clearAttribution(): void
{
this._attributions = [];
// コンテナの再作成
this._deleteContainer();
this.createContainer();
}
/**
* リサイズイベント
*/
protected _sizeChanged(): void
{
if ( this._container )
{
var parent_container = this._container.parentElement;
if ( parent_container!.parentElement!.clientWidth < ContainerController._compact_size )
{
this._container.classList.add( "mapray-attribution-compact" )
}
else
{
this._container.classList.remove( "mapray-attribution-compact" )
}
}
}
/**
* 追加コンテナの作成
*/
createContainer(): void
{
var name = "control-" + this._position;
var parent_container = this._viewer_container.getElementsByClassName( name )[0];
var main_container = document.createElement( "div" );
main_container.classList.add( "control" );
main_container.classList.add( "mapray-attribution" );
var sub_container = document.createElement( "div" );
sub_container.classList.add( "mapray-attribution-container" );
for (var attribution of this._attributions )
{
if ( attribution.display )
{
var attribution_container = document.createElement( "a" );
if (attribution.link) {
attribution_container.href = ( attribution.link );
attribution_container.target = "_blank";
}
var text = document.createTextNode( attribution.display )
attribution_container.appendChild( text );
sub_container.appendChild( attribution_container )
}
}
main_container.appendChild(sub_container);
this._container = main_container;
parent_container.appendChild( this._container );
this._sizeChanged();
}
private _copyAttributions( src: AttributionController.Attribution[] ): void
{
this._attributions = src.map(d => d);
}
}
namespace AttributionController {
export interface Option extends ContainerController.Option {
/**
* 著作権リスト
*/
attributions?: Attribution[];
}
/**
* 著作権情報
*/
export interface Attribution {
/** 表示名 */
display: string;
/** リンク */
link: string;
}
/**
* デフォルト著作権情報
*/
export const _default_attribution: Attribution[] = [
{
display: "©Mapray",
link: "https://mapray.com"
},
{
display: "©JAXA",
link: "http://www.jaxa.jp/"
},
{
display: "測量法に基づく国土地理院長承認(複製)H30JHf626",
link: "https://www.gsi.go.jp/kiban/index.html"
}
];
} // namespace AttributionController
export default AttributionController;