-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
300 lines (288 loc) · 11.8 KB
/
index.html
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- TODO download this css (Issue 1) -->
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
<link rel="stylesheet" href="./src/css/sunburst.css">
</head>
<body>
<div class="content">
<div id="breadcrumbs" class="crumbs breadcrumb">
<span class="crumb"></span>
</div>
<div id="container-chart" class="container-chart">
<div id="chart" class="chart"></div>
</div>
<div>
<div class="container-map">
<div id="map-loader">
<div class="loader"></div>
</div>
<div id="map" class="map">
<div class="advanced-button-control">
<a id="advanced-button" class="advanced-button button" target="_blank"></a>
</div>
</div>
<div id="container-description" class="container-description">
<div id="description-loader">
<div class="loader2"></div>
</div>
<div class="row">
<div class="col">
<div class="container-description-row">
<label id="container-title-row-content"></label>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="container-description-row">
<div id="container-description-row-content" class="container-description-row-content"></div>
</div>
</div>
</div>
</div>
<div id="container-legend" class="container-legend">
<div id="legend-loader">
<div class="loader2"></div>
</div>
<label>Legenda </label>
<img id="legend-image">
</div>
</div>
</div>
</div>
<div id="footer" class="footer">
<div id="img1" class="footer-image1">
<img class="footer-images" src="./src/images/portal.svg" alt="">
</div>
<div id="img2" class="footer-image2">
<img class="footer-images" src="./src/images/insa.svg" alt="">
</div>
</div>
<!-- TODO download this scripts (Issue 1) -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="./src/js/sunburst-chat-ed.js"></script>
<script src="./src/js/data/desertificacao-data.js"></script>
<script src="//d3js.org/d3.v5.min.js"></script>
<link href="./src/css/ol-geocoder-ed.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/ol-geocoder"></script>
<script type="text/javascript">
const GEONODE_URL = 'http://sades.insa.gov.br';
const GEOSERVER_URL = 'http://sades.insa.gov.br/geoserver/ows/';
const DEFAULT_LAYER_OPACITY = 0.85;
changeAdvancedButton = (imgName) => {
let url = GEONODE_URL + '/maps/new?layer=' + imgName;
$('#advanced-button').attr("href", url);
}
fillLegend = (imgName) => {
let legendContainerElement = $('#container-legend')
if (imgName == null || imgName === '') {
legendContainerElement.hide();
return;
} else {
legendContainerElement.show();
}
const urlSufix = '?service=wms&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=' + imgName;
// show loader
let legendLoadingElement = $('#legend-loader');
legendLoadingElement.show();
const url = GEOSERVER_URL + urlSufix;
let legendElement = $('#legend-image');
legendElement.attr("src", url);
legendElement.on("load", () => {
// hidden loader
legendLoadingElement.hide();
});
legendElement.on("error", () => {
// hidden loader
legendLoadingElement.hide();
});
}
fillBreadcrumbs = (data) => {
let breadcrumbsArr = getNameArray(data.__dataNode, []);
let breadcrumbs_container = $("#breadcrumbs");
breadcrumbs_container.empty();
breadcrumbsArr.reverse().forEach((value) => {
breadcrumbs_container.append('<span class="crumb">' + value + '</span>');
});
}
getNameArray = (data, array) => {
array = array || [];
array.push(data.data.name2);
if (data.parent) getNameArray(data.parent, array);
return array;
};
fillDescrition = (data) => {
let titleContentEl = '#container-title-row-content';
let descriptionContentEl = '#container-description-row-content';
$(titleContentEl).text(data.name2 ? data.name2 : '-');
$(descriptionContentEl).text('');
let descriptionLoaderElement = $('#description-loader');
descriptionLoaderElement.show();
let url = GEONODE_URL + '/layers/' + data.imgName + '/metadata_detail_rest';
$.get(url)
.done(function (data) {
$(titleContentEl).text(data.title);
$(descriptionContentEl).text(data.abstract);
})
.fail(function (error) {
$(titleContentEl).text(data.name2 ? data.name2 : '-');
$(descriptionContentEl).text('');
})
.always(function () {
descriptionLoaderElement.hide();
});
};
// TODO check. This "Loading" management might become a new js file
let layersLoadingCount = 0;
tryStartLoading = () => {
if (layersLoadingCount <= 0) {
$('#map-loader').show();
}
layersLoadingCount++;
}
tryEndLoading = () => {
layersLoadingCount > 0 && layersLoadingCount--;
if (layersLoadingCount == 0) {
$('#map-loader').hide();
}
}
tryForceEndLoading = () => {
$('#map-loader').hide();
layersLoadingCount = 0;
}
let currentLayer;
createLayer = (imgName) => {
currentLayer = imgName;
layer = new ol.layer.Tile({
opacity: DEFAULT_LAYER_OPACITY,
visible: true,
source: new ol.source.TileWMS({
url: GEOSERVER_URL,
params: {
'LAYERS': imgName,
'TILED': 'true'
},
ratio: 3,
serverType: "geoserver"
})
});
tryForceEndLoading();
layer.getSource().on('tileloadstart', function (event) {
tryStartLoading();
});
layer.getSource().on('tileloadend', function (event) {
tryEndLoading();
});
layer.getSource().on('tileloaderror', function (event) {
tryEndLoading();
});
return layer;
}
calculateChartSize = () => {
const DEFAULT_PERCENT_SIZE = 0.9;
const DEFAULT_SIZE = 400;
try {
return parseInt($("#container-chart").css('width')) * DEFAULT_PERCENT_SIZE;
} catch (error) {
return DEFAULT_SIZE;
}
};
stopPeddingRequests = () => {
window.stop();
}
let sunburst;
$(document).ready(() => {
let defaultL = new ol.layer.Tile({
source: new ol.source.OSM()
});
const initialImgNameLayer = dataDesertificacao.imgName;
let rootLayer = createLayer(initialImgNameLayer);
// TODO (refactoring) put the center parameters in a constant (Issue 4)
let map = new ol.Map({
layers: [defaultL, rootLayer],
target: "map",
view: new ol.View({
center: [-4615573.515972, -794945.094166],
zoom: 5
})
});
let geocoder = new Geocoder('nominatim', {
provider: 'osm',
lang: 'pt-BR',
placeholder: 'Pesquisa por município . . .',
targetType: 'glass-button',
limit: 2,
keepOpen: true
});
geocoder.on('addresschosen', function (evt) {
map.getView().animate({ zoom: 10, center: evt.coordinate });
// TODO study who the geocode works
// to colapse the search field
$("#map").click();
});
map.addControl(geocoder);
// TODO analyze this approach, because only works in the page initialization (Issue 5)
let chartContainerSize = calculateChartSize();
let color = d3.scaleOrdinal(d3.schemePaired);
// TODO (refactoring) put the "data" in another file. (Issue 6)
const DATA_DESERT_ATTR_LABEL = "name2";
const DATA_DESERT_ATTR_SIZE = "size";
sunburst = Sunburst()
.data(dataDesertificacao)
.label(DATA_DESERT_ATTR_LABEL)
.size(DATA_DESERT_ATTR_SIZE)
.width(chartContainerSize)
.height(chartContainerSize)
.color((d, parent) => d.color);
sunburst.onNodeClick(choosenData => {
let imgName = choosenData.imgName;
if (currentLayer === imgName) {
console.log('The same image. Do nothing.')
return;
}
stopPeddingRequests();
map.getLayers().clear();
sunburst.focusOnNode(choosenData);
let layer1 = createLayer(imgName);
map.addLayer(defaultL);
map.addLayer(layer1);
changeAdvancedButton(choosenData.imgName);
fillBreadcrumbs(choosenData);
fillLegend(choosenData.imgName);
fillDescrition(choosenData);
});
sunburst($("#chart")[0]);
changeAdvancedButton(initialImgNameLayer);
fillBreadcrumbs(dataDesertificacao);
fillLegend(initialImgNameLayer);
fillDescrition(dataDesertificacao);
});
$('#navbar li').on("click", () => {
stopPeddingRequests();
});
let resizing = false;
$(window).on('resize', function () {
const RESIZING_TIMEOUT = 1000;
if (!resizing) {
resizing = true;
setTimeout(() => {
let chartContainerSize = calculateChartSize();
sunburst.width(chartContainerSize);
sunburst.height(chartContainerSize);
$("#chart").html('');
sunburst($("#chart")[0]);
resizing = false;
}, RESIZING_TIMEOUT);
}
});
</script>
</body>
</html>