-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
398 lines (341 loc) · 11.3 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Incendios Verano 2023</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' />
<link href='https://api.mapbox.com/mapbox-assembly/v1.3.0/assembly.min.css' rel='stylesheet'>
<script src='https://api.mapbox.com/mapbox-assembly/v1.3.0/assembly.js'></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<style>
.map-overlay {
position: absolute;
width: 25%;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay-inner {
font-family: sans-serif;
font-size: 8;
}
.map-overlay h2 {
line-height: 24px;
display: block;
margin: 0 0 10px;
font-family: sans-serif;
font-size: 10;
font-weight: bold;
}
.map-overlay .legend .bar {
height: 10px;
width: 100%;
background: linear-gradient(to right, yellow, red);
}
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
.legend-container {
display: inline-block;
vertical-align: middle;
}
.leg400 {
text-align: right;
}
.toggle-group {
display: flex;
margin-right: 18px;
}
.toggle-container {
display: flex;
align-items: center;
margin-right: 10px;
}
.toggle-container input[type='radio'] {
display: none;
}
.toggle {
background-color: #ccc;
padding: 4px 10px;
border-radius: 20px;
cursor: pointer;
}
.toggle input[type='radio']:checked + .toggle {
background-color: #45a049;
color: white;
}
.legend .value-container {
display: flex;
justify-content: space-between;
}
.legend .value-container .value {
flex: 1;
font-size: 10px;
}
.textos {
font-size: 12px;
}
</style>
<div id="map"></div>
<div class="map-overlay top">
<div class="map-overlay-inner">
<h4 class='txt-m txt-bold mb6'>Incendios desde agosto 01 - 2023 hasta agosto 19</h4>
<label class='textos' id="date"></label>
<div class='range range--darken50'>
<input id="slider" type="range" min="0" max="48" step="1" value="0">
</div>
<button class="btn btn--stroke btn--green" id="play-button"><svg class='icon'><use xlink:href='#icon-play'/></svg></button>
<button class="btn btn--stroke btn--red" id="pause-button"><svg class='icon'><use xlink:href='#icon-pause'/></svg></button>
</div>
<div class="map-overlay-inner">
<div id="legend" class="legend">
<div class="bar"></div>
<div class="value-container">
<div class="value">200</div>
<div class="value leg400">400</div>
</div>
<div class='textos'>Luminosidad (grados Kelvin)</div>
</div>
<h4 class='txt-m txt-bold mb6'>Seleccionar dia/noche</h4>
<div class='mb12 mr12 toggle-group align-center'>
<label class='toggle-container'>
<input name='toggle-1' type='radio' value="D" />
<div class='toggle'>Día</div>
</label>
<label class='toggle-container'>
<input name='toggle-1' type='radio' value="N"/>
<div class='toggle'>Noche</div>
</label>
<label class='toggle-container'>
<input checked name='toggle-1' type='radio' value="All"/>
<div class='toggle'>Todos</div>
</label>
</div>
</div>
</div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZm12YWxkZXpnODQiLCJhIjoiY2w5eWJzMzkwMDNiaDNvbGltamV1ajdvNiJ9.esyugI1HyBVPAQcRN551xw';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v11?optimize=true',
center: [-78.46427, -0.20577],
zoom: 10.5,
attributionControl: false,
});
const dates = [
'2023-08-01',
'2023-08-02',
'2023-08-03',
'2023-08-04',
'2023-08-05',
'2023-08-06',
'2023-08-07',
'2023-08-08',
'2023-08-09',
'2023-08-10',
'2023-08-11',
'2023-08-12',
'2023-08-13',
'2023-08-14',
'2023-08-15',
'2023-08-16',
'2023-08-17',
'2023-08-18',
'2023-08-19',
'2023-08-20',
'2023-08-21',
'2023-08-22',
'2023-08-23',
'2023-08-24',
'2023-08-25',
'2023-08-26',
'2023-08-27',
'2023-08-28',
'2023-08-29',
'2023-08-30',
'2023-09-01',
'2023-09-02',
'2023-09-03',
'2023-09-04',
'2023-09-05',
'2023-09-06',
'2023-09-07',
'2023-09-08',
'2023-09-09',
'2023-09-10',
'2023-09-11',
'2023-09-12',
'2023-09-13',
'2023-09-14',
'2023-09-15',
'2023-09-16',
'2023-09-17',
'2023-09-18',
'2023-09-19'
];
let dayNightFilter = null;
let dateIndex = 0;
let animationInterval = null;
function filterByDateAndDayNight(dateIndex, dayNight) {
const dateFilter = ['<=', ['get', 'acq_date'], dates[dateIndex]];
let dayNightFilterValue = null;
if (dayNight === 'D') {
dayNightFilterValue = ['==', ['get', 'daynight'], 'D'];
} else if (dayNight === 'N') {
dayNightFilterValue = ['==', ['get', 'daynight'], 'N'];
}
const combinedFilter = ['all', dateFilter];
if (dayNightFilterValue !== null) {
combinedFilter.push(dayNightFilterValue);
}
map.setFilter('fires2023-layer', combinedFilter);
map.setFilter('fires-labels', combinedFilter);
document.getElementById('date').textContent = dates[dateIndex];
}
document.getElementById('play-button').addEventListener('click', () => {
document.getElementById('play-button').disabled = true;
document.getElementById('pause-button').disabled = false;
animationInterval = setInterval(() => {
// Increment the date index
dateIndex++;
// Reset the date index to 0 if it goes beyond the maximum
if (dateIndex >= dates.length) {
dateIndex = 0;
}
// Update the slider value
document.getElementById('slider').value = dateIndex;
// Get the selected day/night option
const selectedOption = document.querySelector('input[name="toggle-1"]:checked');
const dayNight = selectedOption ? selectedOption.value : 'all';
// Update the map based on the new date and day/night option
filterByDateAndDayNight(dateIndex, dayNight);
}, 500); // Interval in milliseconds
});
document.getElementById('pause-button').addEventListener('click', () => {
document.getElementById('play-button').disabled = false;
document.getElementById('pause-button').disabled = true;
clearInterval(animationInterval); // Stop the animation interval
});
map.on('load', () => {
map.addSource('fires2023', {
'type': 'geojson',
data: 'https://raw.githubusercontent.com/fmvaldezg/Quito_Fires2023/main/data/output_file.json',
//'attribution': 'data source: NASA FIRMS @https://earthdata.nasa.gov/firms | Map by © Felipe Valdez'
});
map.addLayer({
'id': 'fires2023-layer',
'type': 'circle',
'source': 'fires2023',
'paint': {
'circle-color': [
'interpolate',
['linear'],
['get', 'brightness'],
200,
'yellow',
400,
'red'
],
'circle-opacity': 0.75,
'circle-radius': [
'interpolate',
['linear'],
['get', 'brightness'],
280,
5,
400,
20
]
}
});
map.addLayer({
'id': 'fires-labels',
'type': 'symbol',
'source': 'fires2023',
'layout': {
'text-field': ['concat', ['to-string', ['get', 'daynight']], ''],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 10
},
'paint': {
'text-color': '#5e5959'
}
});
const scale = new mapboxgl.ScaleControl({
maxWidth: 80,
unit: 'imperial'
});
map.addControl(scale);
scale.setUnit('metric');
// Set filter to the first date and 'all' by default
filterByDateAndDayNight(0, 'all');
document.getElementById('slider').addEventListener('input', (e) => {
const dateIndex = parseInt(e.target.value, 10);
const selectedOption = document.querySelector('input[name="toggle-1"]:checked');
const dayNight = selectedOption ? selectedOption.value : 'all';
filterByDateAndDayNight(dateIndex, dayNight);
});
// Add event listeners for the toggle buttons
const toggleButtons = document.querySelectorAll('input[name="toggle-1"]');
toggleButtons.forEach((button) => {
button.addEventListener('change', () => {
const dateIndex = parseInt(document.getElementById('slider').value, 10);
const selectedOption = document.querySelector('input[name="toggle-1"]:checked');
const dayNight = selectedOption ? selectedOption.value : 'all';
filterByDateAndDayNight(dateIndex, dayNight);
});
});
let dateIndex = 0; // Initialize the date index
// Function to update the time slider and map
function updateSliderAndMap() {
// Increment the date index
dateIndex++;
// Reset the date index to 0 if it goes beyond the maximum
if (dateIndex >= dates.length) {
dateIndex = 0;
}
// Update the slider value
document.getElementById('slider').value = dateIndex;
// Get the selected day/night option
const selectedOption = document.querySelector('input[name="toggle-1"]:checked');
const dayNight = selectedOption ? selectedOption.value : 'all';
// Update the map based on the new date and day/night option
filterByDateAndDayNight(dateIndex, dayNight);
}
// Set an interval to automatically update the slider and map (e.g., every 2 seconds)
animationInterval = setInterval(updateSliderAndMap, 500);
// Stop the animation when the user interacts with the slider
document.getElementById('slider').addEventListener('input', () => {
clearInterval(animationInterval); // Stop the animation interval
});
});
map.addControl(
new mapboxgl.AttributionControl({
compact: true,
customAttribution: mapboxgl.accessToken
? 'Fire data <a href="https://earthdata.nasa.gov/firms">NASA FIRMS</a>| Map by © Felipe Valdez' // Included by mapbox
: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}),
);
</script>
</body>
</html>