forked from blueaccounting/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErieStat_Map_tabs_Spring.html
256 lines (224 loc) · 10.7 KB
/
ErieStat_Map_tabs_Spring.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spring SRP Loading in ErieStat Watersheds</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css">
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/esri-leaflet@2.1.3/dist/esri-leaflet.js"></script>
<script src="//code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="js/ba_chart2.js"></script>
<script src="js/export-csv_glc.js"></script>
<link rel="stylesheet" href="css/BA_Style.css">
</head>
<body>
<div>
<div id="map"></div>
<div class="vl"></div>
<div id="right-panel">
<div id="intro"></div>
<div id="narrative-section">
<p id="narrative-caption"></p>
<p id="narrative-content"></p>
</div>
<!-- Tab links -->
<div class="tab">
<button class="tablinks" onclick="openFractionChart(event, 'SRP_S')" id="defaultOpen">Spring SRP Loading and<br> Spring Discharge</button>
<button class="tablinks" onclick="openFractionChart(event, 'SRP_FWMC')">Spring SRP FWMC</button>
<button class="tablinks" onclick="openFractionChart(event, 'TP_S')" >Spring TP Loading and<br> Spring Discharge</button>
<button class="tablinks" onclick="openFractionChart(event, 'TP_FWMC_S')">Spring TP FWMC</button>
</div>
<!-- Tab content -->
<div id="SRP_S" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<div id="chart1" class="charts"></div>
</div>
<div id="SRP_FWMC" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<div>
<div id="chart2" class="charts"></div>
</div>
</div>
<div id="TP_S" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<div id="chart3" class="charts"></div>
</div>
<div id="TP_FWMC_S" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<div id="chart4" class="charts"></div>
</div>
</div>
</div>
<script>
var data;
var serviceURL = "https://gis.glc.org/server/rest/services/ErieStat/SpringSRP/MapServer";
var metric1 = metrics.SRP_L_S;
var metric2 = metrics.SRP_FWMC_S;
var metric3 = metrics.TP_L_S;
var metric4 = metrics.TP_FWMS_S;
var metric_discharge = metrics.Discharge_S;
init();
$.getJSON("data/data.json", function(d){
data = d;
});
var map = L.map("map").setView([42.1, -83.1], 8);
L.esri.basemapLayer("Topographic").addTo(map);
var watersheds = L.esri.dynamicMapLayer({
url: serviceURL,
layers:[0, 1, 2],
f: "image",
opacity: 0.7
}).addTo(map);
var boundary_query = L.esri.query({
url: serviceURL + "/0"
});
boundary_query.bounds(function(error, latlngbounds){
map.fitBounds(latlngbounds);
});
var selectedFeature;
map.on("click", function (e){
if(selectedFeature){
map.removeLayer(selectedFeature);
}
watersheds.identify().on(map).at(e.latlng).layers("visible:1").simplify(map, 0.5).run(function (error, featureCollection){
if(featureCollection.features.length >0){
$("#intro").css("visibility", "hidden");
$(".tab").css("display", "block");
document.getElementById("defaultOpen").click();
for(var i = 0; i < featureCollection.features.length; i++){
selectedFeature = L.geoJSON(featureCollection.features[i]);
selectedFeature.setStyle({
fill: false,
weight: 4,
color: "#F3A51E"
});
selectedFeature.addTo(map);
var name = featureCollection.features[i].properties["Watershed Name"];
if(buildNarratives(name)){
var s1_data = $.map(getWatershedMetric(data, watershedNames[name], metric1), function(el){
return el.Value;
});
var s2_data = $.map(getWatershedMetric(data, watershedNames[name], metric2), function(el){
return el.Value;
});
var s3_data = $.map(getWatershedMetric(data, watershedNames[name], metric3), function(el){
return el.Value;
});
var s4_data = $.map(getWatershedMetric(data, watershedNames[name], metric4), function(el){
return el.Value;
});
var discharge_data = $.map(getWatershedMetric(data, watershedNames[name], metric_discharge), function(el){
return el.Value;
});
if(s1_data.length > 0 /*&& discharge_data.length > 0*/){
var chart1 = Highcharts.chart("chart1", createDualAxesOptions_column_line(watershedNames[name] + " " + metric1 + " and " + metric_discharge,
xAxis,
metric1, s1_data, units[metric1], ColorPicker.blue7,
metric_discharge, discharge_data, units[metric_discharge], ColorPicker.blue6,
null,
(window.innerHeight - $("#narrative-section").height()) * 0.7)
);
if(targets[watershedNames[name]]){
if(targets[watershedNames[name]][metric1]){
addTargetLine(chart1, targets[watershedNames[name]][metric1], metric1);
}
}
chart1.update({
subtitle:{
text: "<i>*SRP: Soluble reactive phosphorus</i>",
}
});
}else{
$("#chart1").html("<i>* Data under development.</i>");
}
if(s2_data.length > 0){
var chart2 = buildChart_line(s2_data, "chart2", watershedNames[name], metric2, units[metric2], null, (window.innerHeight - $("#narrative-section").height()) * 0.7);
chart2.update({
subtitle:{
text: "<i>*SRP: Soluble reactive phosphorus</i><br><i>*FWMC: Flow-weighted mean concentration</i>",
}
});
}
else {
$("#chart2").html("<i>* Data under development.</i>");
}
if(s3_data.length > 0){
var chart3 = Highcharts.chart("chart3", createDualAxesOptions_column_line(watershedNames[name] + " " + metric3 + " and " + metric_discharge,
xAxis,
metric3, s3_data, units[metric3], ColorPicker.blue7,
metric_discharge, discharge_data, units[metric_discharge], ColorPicker.blue6,
null,
(window.innerHeight - $("#narrative-section").height()) * 0.7)
);
if(targets[watershedNames[name]]){
if(targets[watershedNames[name]][metric3]){
addTargetLine(chart3, targets[watershedNames[name]][metric3], metric3);
}
}
chart3.update({
subtitle:{
text: "<i>*TP: Total phosphorus</i>",
}
});
}else{
$("#chart3").html("<i>* Data under development.</i>");
}
if(s4_data.length > 0){
var chart4 = buildChart_line(s4_data, "chart4", watershedNames[name], metric4, units[metric4], null, (window.innerHeight - $("#narrative-section").height()) * 0.75);
chart4.update({
subtitle:{
text: "<i>*TP: Total phosphorus</i><br><i>*FWMC: Flow-weighted mean concentration</i>",
}
})
}else{
$("#chart4").html("<i>* Data under development.</i>");
}
}else{
$(".charts").html("");
}
break;
}
}
})
});
function init(){
// Hide tabs
var tabs = document.getElementsByClassName("tab");
for (i = 0; i < tabs.length; i++) {
tabs[i].style.display = "none";
}
// Show intro
$("#intro").html(intro_SRP);
Highcharts.setOptions({
lang: {
numericSymbols: null,
thousandsSep: ','
}
});
};
function openFractionChart(evt, fraction) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
tablinks[i].id = "";
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(fraction).style.display = "block";
evt.currentTarget.className += " active";
// Maintain current tab open
evt.currentTarget.id = "defaultOpen";
}
</script>
</body>
</html>