-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolcano.js
230 lines (174 loc) · 6.8 KB
/
volcano.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
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
// const volc_all_cb = document.getElementById ('volc_all_cb');
const volc_green_cb = document.getElementById('volc_green_cb') ;
const volc_yellow_cb = document.getElementById('volc_yellow_cb') ;
const volc_orange_cb = document.getElementById('volc_orange_cb') ;
const volc_red_cb = document.getElementById('volc_red_cb') ;
let orange_flag = false ;
let green_flag = true ;
let yellow_flag = false ;
let red_flag = false ;
let volcHeadings=['Name','Alert Level','Lat','Lon','Date'];
// monitored volcanoes
// volcurl = 'https://volcanoes.usgs.gov/hans-public/api/volcano/getMonitoredVolcanoes';
$( document ).ready(function(){
$("#volc_event_type").on("change", "input:checkbox", function(){
//$("#formname").submit();
console.log("We get here") ;
getFlags();
loadVolcs() ;
});
});
let markerOptions = {
title: "1",
clickable : true ,
draggable: false ,
};
let volcBlkIcon = L.icon({
iconUrl: 'data/icons8-volc_black.png',
iconSize: [32,32]
});
let volcGreenIcon = L.icon({
iconUrl: 'data/icons8-volc_green.png',
iconSize: [32,32]
});
let volcYellowIcon = L.icon({
iconUrl: 'data/icons8-volc_yellow.png',
iconSize: [32,32]
});
let volcOrangeIcon = L.icon({
iconUrl: 'data/icons8-volc_orange.png',
iconSize: [32,32]
});
let volcRedIcon = L.icon({
iconUrl: 'data/icons8-volc_red.png',
iconSize: [32,32]
});
function getFlags(){
console.log('and here') ;
green_flag = volc_green_cb.checked ;
yellow_flag = volc_yellow_cb.checked ;
orange_flag = volc_orange_cb.checked ;
red_flag = volc_red_cb.checked ;
// all_flag = volc_all_cb.checked ;
}
function addMarker (volc, marker) {
let qdate = volc.alertDate ;
let qplace = volc.noticeSynopsis ;
let qlink = volc.vUrl;
marker.bindPopup ("<b>"+volc.vName+"</b><br>"+qdate+"<br>"+qplace+"<br>"+"<a target='_blank' href="+qlink+">Website</href>") ;
volcmarks.push(marker);
marker.addTo(map) ;
}
function clearVolcs(){
for (marknum in volcmarks) {
map.removeLayer (volcmarks[marknum]);
}
volcmarks=[] ;
}
function loadVolcs (){
console.log("And here too");
clearVolcs() ;
fetch ('https://volcanoes.usgs.gov/vsc/api/volcanoApi/vhpstatus').then(res=>res.json())
.then (volcdata=>{
for (var i in volcdata){
let volc = volcdata[i];
//console.log(volcdata[i]);
// if (volcdata[i].alertLevel!='UNASSIGNED' && all_flag) {
// markerOptions.icon= volcBlkIcon ;
// marker = L.marker([volc.lat,volc.long],markerOptions);
// addMarker(volc,marker);
// }
if (volc.colorCode=='GREEN' && green_flag){
markerOptions.icon= volcGreenIcon ;
marker = L.marker([volc.lat,volc.long],markerOptions);
addMarker(volc,marker);
}
if (volc.colorCode=='YELLOW' && yellow_flag){
markerOptions.icon= volcYellowIcon ;
marker = L.marker([volc.lat,volc.long],markerOptions);
addMarker(volc,marker);
}
if (volc.colorCode=='ORANGE' && orange_flag){
markerOptions.icon= volcOrangeIcon ;
marker = L.marker([volc.lat,volc.long],markerOptions);
addMarker(volc,marker);
}
if (volc.colorCode=='RED' && red_flag){
markerOptions.icon= volcRedIcon ;
marker = L.marker([volc.lat,volc.long],markerOptions);
addMarker(volc,marker);
}
}
if (tableMode==1) {
loadVolcTable (volcdata);
}
});
}
function loadVolcTable(volcdata) {
console.log("creating volc table") ;
let tableEl = document.getElementById('toptable') ;
tableEl.innerHTML="";
theadEl.innerHTML="" ;
tbodyEl.innerHTML="" ;
let myTr = document.createElement("tr") ;
myTr.classList.add('tr-head') ;
for (i in volcHeadings) {
let myTh = document.createElement('th') ;
myTh.innerHTML = volcHeadings[i] ;
if (i==2 || i==3){
myTh.classList.add('priority-low');
}
myTr.appendChild(myTh) ;
}
theadEl.appendChild(myTr) ;
for (i in volcdata){
if (volcdata[i].alertLevel == 'ADVISORY' || volcdata[i].alertLevel == 'WATCH' || volcdata[i].alertLevel == 'WARNING' ){
console.log(volcdata[i]);
let myTr = document.createElement("tr") ;
let myTd0 = document.createElement('td') ;
myTd0.innerHTML = "<a target='_blank' href="+volcdata[i].vUrl+">"+volcdata[i].vName+"</href>" ;
// myTd0.innerHTML = qdata.features[i].properties.place ;
myTr.appendChild(myTd0);
myTd0 = document.createElement('td') ;
myTd0.innerHTML = volcdata[i].colorCode ;
myTr.appendChild(myTd0);
myTd0 = document.createElement('td') ;
myTd0.innerHTML = volcdata[i].lat ;
myTr.appendChild(myTd0);
myTd0 = document.createElement('td') ;
myTd0.innerHTML = volcdata[i].long ;
myTr.appendChild(myTd0);
myTd0 = document.createElement('td') ;
myTd0.innerHTML = volcdata[i].alertDate ;
myTr.appendChild(myTd0);
// myTd0 = document.createElement('td') ;
// myTd0.innerHTML = "<a target='_blank' href="+qdata.features[i].properties.url+">"+qdata.features[i].properties.place+"</href>"
// // myTd0.innerHTML = qdata.features[i].properties.place ;
// myTr.appendChild(myTd0);
tbodyEl.appendChild(myTr) ;
}
}
tableEl.appendChild(theadEl) ;
tableEl.appendChild(tbodyEl) ;
}
// function get_volcanoes(ndays,minmag) {
// let days = getdays(ndays) ;
// let day0 = days[0].toISOString().slice(0,10) ;
// let day1 = days[1].toISOString().slice(0,10) ;
// volcurl = 'https://volcanoes.usgs.gov/hans-public/ap(i/volcano/getMonitoredVolcanoes';
//console.log(marker.length);
// for (marknum in marks) {
// map.removeLayer (marks[marknum]);
// }
// for (i=0; i<nquakes; i++){
// let quake = qdata.features[i] ;
// marker = L.marker([quake.geometry.coordinates[1],quake.geometry.coordinates[0]]);
// let qdate = new Date (quake.properties.time).toISOString() ;
// let qplace = quake.properties.place ;
// marker.bindPopup ("<b>"+quake.properties.mag+"</b><br>"+qdate+"<br>"+qplace);
// marks.push(marker);
// marker.addTo(map) ;
// }
// });
getFlags() ;
loadVolcs() ;