-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
296 lines (265 loc) · 11.4 KB
/
index.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
<script src="https://api.mapbox.com/mapbox.js/plugins/arc.js/v0.1.0/arc.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<title>Nebraska Livestock Visualisation
</title>
</head>
<body>
<div id="map" class="map"></div>
<div>
<button id="optionsOverlay" type="button" class="btn btn-primary" onclick="openNav()">Data Options
</button>
</div>
<div id="dataNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×
</a>
<div class="overlay-content">
<!-- <form id="lstock" action="Database.php" method="get"> -->
<!-- <form id="lstock"> -->
<div class="checkbox">
<input class="livestockSelector" type="checkbox" id="l1" value="04 Dairy Prods; Birds Eggs; Honey; Ed Animal Pr Nesoi">
<label>Bovine Animals, Live</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l2" value="0102 Bovine Animals, Live"><label>Swine, Live</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l3" value="0103 Swine, Live"><label>Chickens, Ducks, Geese, Turkeys, And Guineas, Live
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l4" value="0105 Chickens, Ducks, Geese, Turkeys, And Guineas, Live"><label>Corn (maize)
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l5" value="1005 Corn (maize)"><label>Corn (maize) Seed, Certified, Excluding Sweet Corn
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l6" value="100510 Corn (maize) Seed, Certified, Excluding Sweet Corn"><label>Corn (maize), Other Than Seed Corn
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l7" value="100590 Corn (maize), Other Than Seed Corn"><label>Corn (maize) Flour
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l8" value="110220 Corn (maize) Flour"><label>Groats And Meal Of Corn (maize)
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l9" value="110423 Grains Worked (hulld Pearld Sliced Kibbld) Of Corn"><label>Grains (Worked) Of Corn
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l10" value="151521 Corn (maize) Oil, Crude, Not Chemically Modified"><label>Non- chemically modified crude Corn (maize) Oil
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l11" value="151529 Corn (maize) Oil, Refined, & Fractions, Not Modif"><label>Refined and fractions Corn (maize) Oil (Not Modified)
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l12" value="230210 Bran Sharps & Oth Residues Derived Frm Millng Corn"><label>Bran Sharps & Other Residues Derived From Millng Corn
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l13" value="230670 Corn Germ Oilcake Othr Solid Residue Wh/not Ground"><label>Germ Oilcake
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l14" value="110812 Starch, Corn (maize)"><label>Meat And Edible Meat Offal
<label>
<input class="livestockSelector checkbox" type = "checkbox" name ="l14" value="110812 Starch, Corn (maize)">Meat And Edible Meat Offal
</label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l15" value="02 Meat And Edible Meat Offal"><label >Dairy Prods; Birds Eggs; Honey </label>
<br>
<input class="livestockSelector" type = "checkbox" id ="l16" value="110313 Groats And Meal Of Corn (maize)"><label>Starch, Corn (maize)</label>
<br>
</div>
<div class="slider navOptionSlider">
<input id="yearRange" type="range" min="2002" max="2017" value="2002" color="white"/>
<output foo="foo" on forminput="value = foo.valueAsNumber;" />
<p id="yearValue" class="navOptionSlider">
</p>
</div>
<button id="navOptionSubmit" type="submit" onclick="sendYear();">Submit
</button>
</div>
<!-- </form> -->
</div>
</div>
<script>
function openNav() {
document.getElementById("dataNav").style.width = "40%";
}
function closeNav() {
document.getElementById("dataNav").style.width = "0%";
}
</script>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2,
maxZoom: 3
})
});
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#228B22',
width: 2
})
});
//TRY WITH A SIMPLE VERSION OF MAP, NO STYLING
flightsSource = new ol.source.Vector({
wrapX: false,
attributions: 'Flight data by ' +
'<a href="http://openflights.org/data.html">OpenFlights</a>,',
loader: function() {
var url = 'location.json';
fetch(url).then(function(response) {
return response.json();
}).then(function(json) {
var flightsData = json.flights;
for (var i = 0; i < flightsData.length; i++) {
var flight = flightsData[i];
var from = flight[0];
var to = flight[1];
//
// var flightsSource;
// var addLater = function(feature, timeout) {
// window.setTimeout(function() {
// feature.set('start', new Date().getTime());
// flightsSource.addFeature(feature);
// }, timeout);
// };
//
// var pointsPerMs = 0.1;
// var animateFlights = function(event) {
// var vectorContext = event.vectorContext;
// var frameState = event.frameState;
// vectorContext.setStyle(style);
//
// var features = flightsSource.getFeatures();
// for (var i = 0; i < features.length; i++) {
// var feature = features[i];
// if (!feature.get('finished')) {
// // only draw the lines for which the animation has not finished yet
// var coords = feature.getGeometry().getCoordinates();
// var elapsedTime = frameState.time - feature.get('start');
// var elapsedPoints = elapsedTime * pointsPerMs;
//
// if (elapsedPoints >= coords.length) {
// feature.set('finished', true);
// }
//
// var maxIndex = Math.min(elapsedPoints, coords.length);
// var currentLine = new ol.geom.LineString(coords.slice(0, maxIndex));
//
// // directly draw the line with the vector context
// vectorContext.drawGeometry(currentLine);
// }
// }
// // tell OpenLayers to continue the animation
// map.render();
// };
// flightsSource = new ol.source.Vector({
// wrapX: false,
// attributions: 'Flight data by ' +
// '<a href="http://openflights.org/data.html">OpenFlights</a>,',
// loader: function() {
// var url = 'https://openlayers.org/en/v4.6.5/examples/data/openflights/flights.json';
// fetch(url).then(function(response) {
// return response.json();
// }).then(function(json) {
// var flightsData = json.flights;
// for (var i = 0; i < flightsData.length; i++) {
// var flight = flightsData[i];
// var from = flight[0];
// var to = flight[1];
//
// // create an arc circle between the two locations
// var arcGenerator = new arc.GreatCircle(
// {x: from[1], y: from[0]},
// {x: to[1], y: to[0]});
//
// var arcLine = arcGenerator.Arc(100, {offset: 10});
// if (arcLine.geometries.length === 1) {
// var line = new ol.geom.LineString(arcLine.geometries[0].coords);
// line.transform(ol.proj.get('EPSG:4326'), ol.proj.get('EPSG:3857'));
//
// var feature = new ol.Feature({
// geometry: line,
// finished: false
// });
// // add the feature with a delay so that the animation
// // for all features does not start at the same time
// addLater(feature, i * 50);
// }
// }
// map.on('postcompose', animateFlights);
// });
// }
// });
// var flightsLayer = new ol.layer.Vector({
// source: flightsSource,
// style: function(feature) {
// // if the animation is still active for a feature, do not
// // render the feature with the layer style
// if (feature.get('finished')) {
// return style;
// } else {
// return null;
// }
// }
// });
// map.addLayer(flightsLayer);
</script>
<script type="text/javascript">
var slider = document.getElementById("yearRange");
var output = document.getElementById("yearValue");
console.log(slider.value);
output.innerHTML = slider.value;
// Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function() {
output.innerHTML = this.value;
}
// use ajax to pass values to the database.php page
function sendYear(){
console.log(slider.value);
var livestock_string = "(";
var livestock_values = document.getElementsByClassName('livestockSelector');
for (var i=0; i < livestock_values.length; i++){
if(livestock_values[i].checked) {
if (livestock_string.length == 1){
livestock_string = livestock_string + "'" + livestock_values[i].value + "'";
}
else {
livestock_string = livestock_string + ", '" + livestock_values[i].value + "'";
}
}
}
livestock_string = livestock_string + ")";
// console.log(livestock_string);
$.ajax({
type: 'POST',
data: {'val': slider.value, 'livestock': livestock_string},
dataType:'json',
url: './Database.php',
success: function(query_result){
console.log(JSON.parse(query_result));
dataset = JSON.parse(query_result);
// map.addLayer(dataLayer);
},
error: function(error){
console.log(error);
}
})
}
</script>
</body>
</html>