-
Notifications
You must be signed in to change notification settings - Fork 2
/
configuration.js
184 lines (147 loc) · 3.49 KB
/
configuration.js
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
179
180
181
182
183
184
import Core from '/basic-tools/tools/core.js';
export default class Configuration {
// Get for untransformed properties
get ID() {
return this.id;
}
get Style() {
return this.style;
}
// Get for localized strings
get Abbr() {
return this.abbr;
}
// Get for localized strings
get Title() {
return this.title;
}
// Get for localized strings
get FullTitle() {
return `${this.Title} (${this.Abbr})`;
}
// Get for localized strings
get TableUrl() {
return this.tableUrl;
}
get Table() {
if (!this.table) return null;
return {
path : this.table.path,
summary : this.table.summary,
title : this.table.title,
description : this.table.description,
fields : this.Fields
}
}
get Description() {
return this.description;
}
get Layers() {
return this.layers;
}
// Get for transformed properties
get LayerIDs() {
var layers = this.Layers;
return layers && layers.map(l => l.id);
}
get VisibleLayers() {
var layers = this.Layers;
return layers && layers.filter(l => (l.visible || l.visible === undefined));
}
get VisibleLayerIDs() {
var layers = this.VisibleLayers;
return layers && layers.map(l => l.id);
}
get SelectedLayers() {
var layers = this.Layers;
return layers.filter(l => l.selected);
}
get SelectedLayerIDs() {
var layers = this.SelectedLayers;
return layers && layers.map(l => l.id);
}
get ClickableLayers() {
var layers = this.Layers;
return layers && layers.filter(l => !!l.click);
}
get ClickableLayersIDs() {
var layers = this.ClickableLayers;
return layers && layers.map(l => l.id);
}
multiLegend(legend){
return legend && legend.map(l => {
return {
color : l.color,
label : l.label && l.label[Core.locale],
title : Core.Nls("Legend_Checkbox_Title"),
value : l.value
}
});
}
get Legend() {
return this.legend && this.legend.map(l => {
return {
color : l.color,
label : l.label && l.label[Core.locale],
title : Core.Nls("Legend_Checkbox_Title"),
value : l.value
}
});
}
get Fields() {
if (!this.table) return null;
return this.table.fields.map(f => {
return {
id : f.id,
label : f[Core.locale],
type : f.type || null
}
});
}
UpdateTable(json) {
this.table = {
path : json.path,
summary : json.summary,
title : json.title[Core.locale],
description : json.description[Core.locale],
fields : json.fields
}
}
constructor() {
this.id = null;
this.style = null;
this.tableUrl = null;
this.layers = null;
this.title = null;
this.abbr = null;
this.description = null;
this.legend = null;
this.table = null;
this.type = null;
this.indicators = null;
this.useIndicatorTitles = null;
this.variables = null;
}
HasLayer(layerId) {
for (var i=0; i < this.layers.length; i++) {
if (this.layers[i].id === layerId) return true;
}
return false;
}
static FromJSON(json) {
var c = new Configuration();
c.id = json.id;
c.style = json.style;
c.tableUrl = json.table || null;
c.layers = json.layers || null;
c.title = json.title && json.title[Core.locale] || null;
c.abbr = json.abbr && json.abbr[Core.locale] || null;
c.description = json.description && json.description[Core.locale] || null;
c.legend = json.legend || null;
c.type = json.type || null;
c.indicators = json.indicators || null;
c.useIndicatorTitles = json.useIndicatorTitles || null;
c.variables = json.variables || null;
return c;
}
}