-
Notifications
You must be signed in to change notification settings - Fork 0
/
m-radar.html
704 lines (621 loc) · 29.2 KB
/
m-radar.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
<!DOCTYPE html>
<html>
<head>
<title>Radar</title>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<link href="https://unpkg.com/[email protected]/dist/leaflet.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<style type="text/css">
a {
color: lightblue;
}
a:hover {
color: black;
}
.sli {
list-style: none;
display: inline-block;
}
body{
background-color: rgb(26, 26, 26);
color: white;
font-family: Bahnschrift, Veranda, sans-serif;
overflow-y: hidden;
}
.material-symbols-outlined {
font-variation-settings:
'FILL' 0,
'wght' 600,
'GRAD' 0,
'opsz' 20
}
button {
background-color: white;
border: grey 2px solid;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
font-size: 10px;
font-weight: bold;
border-radius: 10px;
}
.close {
border-radius: 100%;
border: none;
background: red;
color: white;
text-align: center;
padding: 0;
padding-left: 2px;
padding-right: 2px;
padding-top: 1px;
position: relative;
left: calc(100% - 20px);
}
.close:hover {
background-color: darkred;
}
select {
width: 100%;
border: none;
border-radius: 100px;
background: white;
padding: 5px;
}
</style>
</head>
<body>
<div id="setup" style="width: 200px; height: 200px; border-radius: 20px; padding: 10px; position: absolute; left: 10%; top: 20%; border: white 5px solid; z-index: 999; background: black;">
<button onclick="closeSettings();" class="close"><span class="material-symbols-outlined" style="font-size: 16px;">close</span></button>
<p style="font-size: 20px;">Quick Calibration</p>
<p>Drag the slider until you see the bottom edge of the settings box.</p>
<input width="250px" type="range" min="20" max="90" value="50" class="slider" id="sizer" oninput="changeSize()" title="Alert Opacity"><br>
</div>
<ul style="padding: 5px; text-align: center;">
<li class="sli"><button onclick="stop(); showFrame(animationPosition - 1); return;"><</button></li>
<li class="sli"><button onclick="playStop();">Play / Stop</button></li>
<li class="sli"><button onclick="stop(); showFrame(animationPosition + 1); return;">></button></li>
<li class="sli"><button onclick="refresh();">Refresh</button></li>
<li class="sli"><button onclick="settings();" id="modalBtn">Settings</button></li>
</ul>
<div id="timestamp" style="margin-bottom: 5px; text-align:center; font-size: 11px;"></div>
<div id="mapid" style="border-radius: 10px; width: 100%; height: 90vh;"></div>
<div style="padding: 10px; font-size: 11px; display: none; overflow-y: auto; margin-top: 10px; height: 30vh; border: 5px solid white; border-radius: 15px; -moz-border-radius: 10px; scrollbar-width: thin;" id="alertDeets">
<button onclick="closeSettings();" class="close"><span class="material-symbols-outlined" style="font-size: 16px;">
close
</span></button>
<p style="height:2px"></p>
<h3 id="alert_title" style="margin: 4px; ">Unknown alert</h3>
<p style="height:2px"></p>
<p id="alert_issued" style="margin: 4px;">Unknown issuance</p>
<p id="alert_expiration" style="margin: 4px;">Unknown expiration</p>
<p style="height:2px"></p>
<p id="alert_hazards" style="margin: 4px;">Unknown issuance</p>
<p id="alert_impacts" style="margin: 4px;">Unknown issuance</p>
<p style="height:2px"></p>
<p id="alert_areas" style="margin: 4px;">Unknown areas</p>
<br>
<p id="alert_description" style="margin: 4px;">Unknown description</p>
</div>
</div>
<div id="settingsModal" style="padding: 10px; font-size: 11px; display: block; overflow-y: auto; margin-top: 10px; height: 30vh; border: 5px solid white; border-radius: 15px; -moz-border-radius: 10px; scrollbar-width: thin;">
<button onclick="closeSettings();" class="close"><span class="material-symbols-outlined" style="font-size: 16px;">
close
</span></button>
<br><br>
<p style="margin-bottom: 1px; margin-top: 1px;">Radar Type</p>
<input type="radio" name="kind" checked="checked" onchange="setKind('radar')">Radar <input type="radio" name="kind" onchange="setKind('satellite')">Infrared Satellite<br>
<p style="margin-bottom: 1px;">Radar Time</p>
<input type="radio" name="duration" checked="checked" onchange="setKind('past')">Past <input type="radio" name="duration" onchange="setKind('future')">Past + Future<br>
<p style="margin-bottom: 1px;">Radar Opacity</p>
<input width="250px" type="range" min="1" max="100" value="75" class="slider" id="radop" onchange="radarOpacityChange()" title="Radar Opacity"><br>
<p style="margin-bottom: 1px;">Alert Fill Opacity</p>
<input width="250px" type="range" min="1" max="100" value="40" class="slider" id="alop" onchange="alertOpacityChange()" title="Alert Opacity"><br>
<p style="margin-bottom: 1px;">Radar Color Scheme</p>
<select id="colors" onchange="setColors(); return;">
<option value="0">Black and White Values</option>
<option value="1">Original</option>
<option value="2">Universal Blue</option>
<option value="3">TITAN</option>
<option value="4">The Weather Channel</option>
<option value="5">Meteored</option>
<option value="6" selected="selected"> NEXRAD Level-III (default)</option>
<option value="7">RAINBOW @ SELEX-SI</option>
<option value="8">Dark Sky</option>
</select>
</div>
<script>
var map = L.map('mapid').setView([38.0, -95.2], 6);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
/**
* RainViewer radar animation part
* @type {number[]}
*/
var apiData = {};
var mapFrames = [];
var lastPastFramePosition = -1;
var radarLayers = [];
var doFuture = false; // Whether or not to show future radar
var optionKind = 'radar'; // can be 'radar' or 'satellite'
var optionTileSize = 256; // can be 256 or 512.
var optionColorScheme = 6; // from 0 to 8. Check the https://rainviewer.com/api/color-schemes.html for additional information
var optionSmoothData = 1; // 0 - not smooth, 1 - smooth
var optionSnowColors = 1; // 0 - do not show snow colors, 1 - show snow colors
var radarOpacity = 0.75
var alertOpacity = 0.4
var animationPosition = 0;
var animationTimer = false;
var loadingTilesCount = 0;
var loadedTilesCount = 0;
var alertData = []
var allalerts = [];
var displayFloodWarnings = true;
var displayFFloodWarnings = true;
var displayOtherWarnings = true;
var displaySpecWarnings = true;
var displayTorWarnings = true;
var displaySvrWarnings = true;
var highHeightOfMap = "85vh";
var lowHeightOfMap = "50vh";
function changeSize(){
var heightOfMap = document.getElementById('sizer').value;
highHeightOfMap = heightOfMap + 'vh';
heightOfMap = Number(heightOfMap) + 35;
lowHeightOfMap = heightOfMap + 'vh';
document.getElementById('mapid').style.height = highHeightOfMap;
}
function floodChange(){
displayFloodWarnings = !displayFloodWarnings;
loadAlerts();
}
function ffloodChange(){
displayFFloodWarnings = !displayFFloodWarnings;
loadAlerts();
}
function othChange(){
displayOtherWarnings = !displayOtherWarnings;
loadAlerts();
}
function svrChange(){
displaySvrWarnings = !displaySvrWarnings;
loadAlerts();
}
function specChange(){
displaySpecWarnings = !displaySpecWarnings;
loadAlerts();
}
function torChange(){
displayTorWarnings = !displayTorWarnings;
loadAlerts();
}
function settings(){
document.getElementById("settingsModal").style.display = "block";
document.getElementById("alertDeets").style.display = "none";
document.getElementById('mapid').style.height = highHeightOfMap;
}
function closeSettings(){
document.getElementById("settingsModal").style.display = "none";
document.getElementById("alertDeets").style.display = "none";
document.getElementById("setup").style.display = "none";
document.getElementById('mapid').style.height = lowHeightOfMap;
}
function formatTimestamp(isoTimestamp) {
const date = new Date(isoTimestamp);
const options = {
year: 'numeric', month: 'long', day: 'numeric',
hour: '2-digit', minute: '2-digit', timeZoneName: 'short'
};
return date.toLocaleString('en-US', options);
}
function reverseSubarrays(arr) {
return arr.map(subArr => subArr.slice().reverse());
}
function findPair(list, target) {
for (let i = 0; i < list.length; i++) {
if (list[i][0] === target) {
return list[i][1];
}
}
return null
}
function findPairInDictionary(dicts, target) {
for (const dict of dicts) {
console.log(dict + " with target " + target)
console.log(alertData)
if (target in dict) {
return dict[target];
}
}
console.log("Couldn't find obj.")
}
function convertDictsToArrayOfArrays(arr) {
return arr.map(obj => Object.values(obj));
}
function radarOpacityChange() {
var sliderValue = document.getElementById('radop').value;
radarOpacity = sliderValue / 100;
refresh()
}
function alertOpacityChange() {
var sliderValue = document.getElementById('alop').value;
alertOpacity = sliderValue / 100;
refresh()
}
function getAlert(polycoords){
thisID = findPair(allalerts, polycoords.join());
console.log(thisID);
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.weather.gov/alerts/'+thisID, true);
xhr.setRequestHeader('Accept', 'Application/geo+json');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
document.getElementById("settingsModal").style.display = "none";
document.getElementById("alertDeets").style.display = "block";
document.getElementById('mapid').style.height = highHeightOfMap;
var alertInfo = JSON.parse(xhr.responseText);
var alertTitle = document.getElementById('alert_title');
if (alertInfo.properties.event.includes("Severe Thunderstorm")){
alertTitle.style.color = "yellow";
} else if (alertInfo.properties.event.includes("Tornado")){
alertTitle.style.color = "red";
} else if (alertInfo.properties.event.includes("Flash Flood")){
alertTitle.style.color = "green";
} else if (alertInfo.properties.event.includes("Flood Warning")){
alertTitle.style.color = "magenta";
} else if (alertInfo.properties.event.includes("Special Weather")){
alertTitle.style.color = "blue";
} else {
alertTitle.style.color = "orange";
}
alertTitle.textContent = alertInfo.properties.event;
var alertExp = document.getElementById('alert_expiration');
alertExp.textContent = "Expires: " + formatTimestamp(alertInfo.properties.expires);
var alertiss = document.getElementById('alert_issued');
alertiss.textContent = "Issued: " + formatTimestamp(alertInfo.properties.sent);
var areasl = document.getElementById('alert_areas');
areasl.textContent = "Areas: " + alertInfo.properties.areaDesc;
var alertdesc = document.getElementById('alert_description');
alertdesc.textContent = alertInfo.properties.description;
try {
var hazards = alertInfo.properties.description.split("HAZARD...")[1].split("\n\n")[0].replace(/\n/g, " ");
} catch {
var hazards = "No hazards identified."
}
var haz = document.getElementById('alert_hazards');
haz.textContent = "Hazards: " + hazards;
try {
var impacts = alertInfo.properties.description.split("IMPACTS...")[1].split("\n\n")[0].replace(/\n/g, " ");
} catch {
try {
var impacts = alertInfo.properties.description.split("IMPACT...")[1].split("\n\n")[0].replace(/\n/g, " ");
} catch {
var impacts = "No impacts identified."
}
}
var imp = document.getElementById('alert_impacts');
imp.textContent = "Impacts: " + impacts;
} else {
console.log(xhr.status);
}
}
xhr.send();
}
function loadAlerts() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.weather.gov/alerts/active?limit=500', true);
xhr.setRequestHeader('Accept', 'Application/geo+json');
map.eachLayer(function(layer) {
if (layer instanceof L.Polygon) {
map.removeLayer(layer);
}
});
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var alerts = JSON.parse(xhr.responseText).features;
alerts.forEach(function(alert) {
try {
var thisItem = alert.geometry.coordinates[0];
console.log(thisItem);
if (alert.properties.event.includes("Severe Thunderstorm")){
if (displaySvrWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: 'yellow'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: 'yellow', fillOpacity: alertOpacity });
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
} else if (alert.properties.event.includes("Tornado")){
if (displayTorWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: 'red'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: 'red', fillOpacity: alertOpacity});
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
} else if (alert.properties.event.includes("Special Weather")){
if (displaySpecWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: 'blue'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: 'blue', fillOpacity: alertOpacity});
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
} else if (alert.properties.event.includes("Flash Flood")){
if (displayFFloodWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: 'green'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: 'green', fillOpacity: alertOpacity});
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
} else if (alert.properties.event.includes("Flood Warning")){
if (displayFloodWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: 'magenta'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: 'magenta', fillOpacity: alertOpacity });
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
} else {
if (displayOtherWarnings) {
var polygon = L.polygon(reverseSubarrays(thisItem), {color: '#FF8E02'}).addTo(map);
polygon.setStyle({fillOpacity: alertOpacity});
var thisAlert = [];
thisAlert.push(polygon.getLatLngs().join())
thisAlert.push(alert.properties.id)
allalerts.push(thisAlert);
polygon.on('mouseover', function (e) {
polygon.setStyle({ color: 'purple', fillOpacity: 0.7 });
}); polygon.on('mouseout', function (e) {
polygon.setStyle({ color: '#FF8E02', fillOpacity: alertOpacity });
}); polygon.on('click', function (e) {
document.getElementById("alertDeets").style.display = "block";
getAlert(e.target.getLatLngs());
});
}
}
console.log("Added alert")
} catch {
console.log("No coords for obj.")
}
});
}
};
xhr.send();
}
function startLoadingTile() {
loadingTilesCount++;
}
function finishLoadingTile() {
// Delayed increase loaded count to prevent changing the layer before
// it will be replaced by next
setTimeout(function() { loadedTilesCount++; }, 250);
}
function isTilesLoading() {
return loadingTilesCount > loadedTilesCount;
}
/**
* Load all the available maps frames from RainViewer API
*/
var apiRequest = new XMLHttpRequest();
apiRequest.open("GET", "https://api.rainviewer.com/public/weather-maps.json", true);
apiRequest.onload = function(e) {
// store the API response for re-use purposes in memory
apiData = JSON.parse(apiRequest.response);
initialize(apiData, optionKind);
};
apiRequest.send();
/**
* Initialize internal data from the API response and options
*/
function initialize(api, kind) {
// remove all already added tiled layers
for (var i in radarLayers) {
map.removeLayer(radarLayers[i]);
}
mapFrames = [];
radarLayers = [];
animationPosition = 0;
if (!api) {
return;
}
if (kind == 'satellite' && api.satellite && api.satellite.infrared) {
mapFrames = api.satellite.infrared;
lastPastFramePosition = api.satellite.infrared.length - 1;
showFrame(lastPastFramePosition, true);
}
else if (api.radar && api.radar.past) {
mapFrames = api.radar.past;
if (api.radar.nowcast) {
if (doFuture){
mapFrames = mapFrames.concat(api.radar.nowcast);
}
}
// show the last "past" frame
lastPastFramePosition = api.radar.past.length - 1;
showFrame(lastPastFramePosition, true);
}
}
/**
* Animation functions
* @param path - Path to the XYZ tile
*/
function addLayer(frame) {
if (!radarLayers[frame.path]) {
var colorScheme = optionKind == 'satellite' ? 0 : optionColorScheme;
var smooth = optionKind == 'satellite' ? 0 : optionSmoothData;
var snow = optionKind == 'satellite' ? 0 : optionSnowColors;
var source = new L.TileLayer(apiData.host + frame.path + '/' + optionTileSize + '/{z}/{x}/{y}/' + colorScheme + '/' + smooth + '_' + snow + '.png', {
tileSize: 256,
opacity: 0.01,
zIndex: frame.time
});
// Track layer loading state to not display the overlay
// before it will completelly loads
source.on('loading', startLoadingTile);
source.on('load', finishLoadingTile);
source.on('remove', finishLoadingTile);
radarLayers[frame.path] = source;
}
if (!map.hasLayer(radarLayers[frame.path])) {
map.addLayer(radarLayers[frame.path]);
}
}
/**
* Display particular frame of animation for the @position
* If preloadOnly parameter is set to true, the frame layer only adds for the tiles preloading purpose
* @param position
* @param preloadOnly
* @param force - display layer immediatelly
*/
function changeRadarPosition(position, preloadOnly, force) {
while (position >= mapFrames.length) {
position -= mapFrames.length;
}
while (position < 0) {
position += mapFrames.length;
}
var currentFrame = mapFrames[animationPosition];
var nextFrame = mapFrames[position];
addLayer(nextFrame);
// Quit if this call is for preloading only by design
// or some times still loading in background
if (preloadOnly || (isTilesLoading() && !force)) {
return;
}
animationPosition = position;
if (radarLayers[currentFrame.path]) {
radarLayers[currentFrame.path].setOpacity(0);
}
radarLayers[nextFrame.path].setOpacity(radarOpacity);
var pastOrForecast = nextFrame.time > Date.now() / 1000 ? 'FORECAST' : 'PAST';
document.getElementById("timestamp").innerHTML = pastOrForecast + ': ' + (new Date(nextFrame.time * 1000)).toString();
}
/**
* Check avialability and show particular frame position from the timestamps list
*/
function showFrame(nextPosition, force) {
var preloadingDirection = nextPosition - animationPosition > 0 ? 1 : -1;
changeRadarPosition(nextPosition, false, force);
// preload next next frame (typically, +1 frame)
// if don't do that, the animation will be blinking at the first loop
changeRadarPosition(nextPosition + preloadingDirection, true);
}
/**
* Stop the animation
* Check if the animation timeout is set and clear it.
*/
function stop() {
if (animationTimer) {
clearTimeout(animationTimer);
animationTimer = false;
return true;
}
return false;
}
function play() {
showFrame(animationPosition + 1);
// Main animation driver. Run this function every 500 ms
animationTimer = setTimeout(play, 500);
}
function playStop() {
if (!stop()) {
play();
}
}
/**
* Change map options
*/
function setKind(kind) {
if (kind == 'satellite' || kind == 'radar'){
optionKind = kind;
initialize(apiData, optionKind);
} else if (kind == 'future') {
doFuture = true;
initialize(apiData, optionKind);
} else if (kind == 'past') {
doFuture = false;
initialize(apiData, optionKind);
}
}
function setColors() {
var e = document.getElementById('colors');
optionColorScheme = e.options[e.selectedIndex].value;
initialize(apiData, optionKind);
}
function refresh(){
var apiRequest = new XMLHttpRequest();
apiRequest.open("GET", "https://api.rainviewer.com/public/weather-maps.json", true);
apiRequest.onload = function(e) {
// store the API response for re-use purposes in memory
apiData = JSON.parse(apiRequest.response);
initialize(apiData, optionKind);
};
apiRequest.send();
loadAlerts();
console.log("Refreshed!")
}
function loop() {
var apiRequest = new XMLHttpRequest();
apiRequest.open("GET", "https://api.rainviewer.com/public/weather-maps.json", true);
apiRequest.onload = function(e) {
// store the API response for re-use purposes in memory
apiData = JSON.parse(apiRequest.response);
initialize(apiData, optionKind);
};
apiRequest.send();
loadAlerts();
console.log("Refreshed!")
setTimeout(loop, 60000);
}
loop()
</script>
</body>
</html>