-
Notifications
You must be signed in to change notification settings - Fork 3
/
DublinBUS.js
246 lines (184 loc) · 5.62 KB
/
DublinBUS.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
231
232
233
234
235
236
237
238
239
240
241
242
var map;
var marker;
var table;
var row;
var cell1;
var cell2;
var cell3;
var cell4;
var cell5;
function populateTable(markerName, markerAvailabele, markerTotal) {
console.log(markerName);
console.log(markerAvailabele);
console.log(markerTotal);
cell3.innerHTML = " Average Waiting Time at the Stop ";
cell4.innerHTML = " " + markerTotal + " ";
cell1.innerHTML = " Total Buses Due ";
cell2.innerHTML = " " + markerAvailabele + " ";
cell5.innerHTML = " " + markerName + " ";
}
function openNav(markerName, markerAvailabele, markerTotal) {
populateTable(markerName, markerAvailabele, markerTotal);
document.getElementById("mySidenav").style.display = "block";
google.charts.setOnLoadCallback(drawBasic(markerName));
}
function closeNav() {
document.getElementById("mySidenav").style.display = "none";
}
function drawBasic(markerName) {
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Time of Day');
data.addColumn('number', 'Motivation Level');
data.addRows([
[{v: [8, 0, 0], f: '8 am'}, 1],
[{v: [9, 0, 0], f: '9 am'}, 2],
[{v: [10, 0, 0], f:'10 am'}, 3],
[{v: [11, 0, 0], f: '11 am'}, 4],
[{v: [12, 0, 0], f: '12 pm'}, 5],
[{v: [13, 0, 0], f: '1 pm'}, 6],
[{v: [14, 0, 0], f: '2 pm'}, 7],
[{v: [15, 0, 0], f: '3 pm'}, 8],
[{v: [16, 0, 0], f: '4 pm'}, 9],
[{v: [17, 0, 0], f: '5 pm'}, 10],
]);
var options = {
title: markerName,
hAxis: {
title: 'Time of Day',
format: 'h:mm a',
viewWindow: {
min: [7, 30, 0],
max: [17, 30, 0]
}
},
vAxis: {
title: 'Rating (scale of 1-10)'
}
};
var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));
chart.draw(data, options);
}
function initialize() {
google.charts.load('current', {packages: ['corechart', 'bar']});
table = document.getElementById("bikeStationTable");
row = table.insertRow(0);
cell1 = row.insertCell(0);
cell2 = row.insertCell(1);
row = table.insertRow(0);
cell3 = row.insertCell(0);
cell4 = row.insertCell(1);
row = table.insertRow(0);
cell5 = row.insertCell(0);
var mapOptions = {
zoom:12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: {lat: 53.353584, lng: -6.251495}
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
showHeatMap();
showJson();
}
function showJson()
{
request = new XMLHttpRequest();
request.open('GET', 'http://ec2-34-243-117-230.eu-west-1.compute.amazonaws.com:8080/poll/bus/data', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
var data = JSON.parse(request.responseText);
for(var i = 0; i < data.length; i++) {
(function(datas){
if(parseInt(datas.stopid) < 100100)
{
var start = {lat: parseFloat(datas.lattitude), lng: parseFloat(datas.longitude)};
if(datas.due_count == 0)
{
marker = new google.maps.Marker({
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5,
fillColor: "#20B2AA",
fillOpacity: 0.9,
strokeWeight: 0.1
},
position: start,
map: map
});
google.maps.event.addListener(marker, 'click', function () {
openNav(datas.stopid, datas.due_count, datas.waiting_time);
});
}
else
{
marker = new google.maps.Marker({
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5,
fillColor: "#FF0000",
fillOpacity: 0.9,
strokeWeight: 0.1
},
position: start,
map: map
});
google.maps.event.addListener(marker, 'click', function () {
openNav(datas.stopid, datas.due_count, datas.waiting_time);
});
}
}
} )(data[i]);
}
} else {
// We reached our target server, but it returned an error
console.log("Server returned error")
}
};
request.onerror = function() {
};
request.send();
}
function showHeatMap()
{
map2 = L.map('heatmap-canvas').setView([53.343584,-6.261495], 13);
mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapLink + ' Contributors',
maxZoom: 23,
}).addTo(map2);
var array = [];
var heatpoints = [];
window.stationname = [];
// request.onload = function() {
$.getJSON('http://ec2-34-243-117-230.eu-west-1.compute.amazonaws.com:8080/poll/bus/data', function(data) {
var myJsonString = JSON.stringify(data);
var mydata1 = JSON.parse(myJsonString);
for(var i = 0; i < mydata1.length; i++) {
if(parseInt(mydata1[i].stopid) < 100100)
{
var start = {lat: parseFloat(mydata1[i].lattitude), lng: parseFloat(mydata1[i].longitude)};
if(mydata1[i].due_count == 0)
{
array.push([parseFloat(mydata1[i].lattitude), parseFloat(mydata1[i].longitude),0.5]);
}
else
{
// console.log("Inside due count loop2");
array.push([parseFloat(mydata1[i].lattitude), parseFloat(mydata1[i].longitude),parseFloat(mydata1[i].due_count)+0.5]);
}
}
}
});
var heat = L.heatLayer(array
,{
radius: 18,
blur: 15,
maxZoom: 10,
}).addTo(map2);
}
function logout()
{
window.location = "Login.html";
}