-
Notifications
You must be signed in to change notification settings - Fork 4
/
x-datarequest.html
69 lines (66 loc) · 2.61 KB
/
x-datarequest.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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<link rel="shortcut icon" href="resources/favicon.ico" />
<meta name="description" content="A light-weight data viewer for hydrologic data" />
<meta name="author" content="Martin Roberge" />
<meta name="keywords" content="HydroCloud, hydrology, stream gauges, USGS, data" />
<link href='https://fonts.googleapis.com/css?family=Vollkorn:700italic' rel='stylesheet' type='text/css'>
<title>HydroCloud hydrograph demo</title>
<body>
<label for="selectRes">Resource request:</label>
<select name="selectRes" id="selectRes">
<option value="default" disabled="disabled" selected="selected" style="display:none;">Please select a resource.</option>
<option value="01584050">USGS site 01584050</option>
<option value="01585200">USGS site 01585200</option>
<option value="01583500">USGS site 01583500</option>
<option value="local">local data (same origin)</option>
</select>
<button id="submitReq" onclick="dataReq();">
Submit request
</button>
<script src="lib/jquery/jquery-2.0.2.js"></script>
<script src="lib/d3/d3.min.js"></script>
<script src="src/oldHydroGraph.js"></script>
<script type="text/javascript">
function dataReq() {
console.log("dataReq");
var select = document.getElementById('selectRes');
var siteID = select.options[select.selectedIndex].value;
getUSGS(siteID);
}
function getUSGS(id) {
if (id == "local") {
var filename = "resources/USGSshort.txt";
} else {
var filename = "https://waterservices.usgs.gov/nwis/iv/?format=json&sites=" + id + "&period=P30D¶meterCd=00060";
}
d3.json(filename, function(error, json) {
if (error) {
if (error.status === 0) {
alert("CORS is not enabled.");
}
return console.warn(error);
}
//if (!json.value.timeSeries[0].values[0].value){console.warn("there is no data for this site")};
temp = json.value.timeSeries[0].values[0].value;
//I need to check if this even has a value!!
//MR Create a new array of objects from the JSON.
data = [];
//Clear out the array.
temp.forEach(function(d, index, array) {
d.date = new Date(d.dateTime);
d.value = +d.value;
data[index] = {
date : d.date,
value : d.value
};
});
//checkState();
d3.select("svg").remove();
hydrograph("Hydrograph");
});
}
</script>
</body>
</html>