-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracking.js
360 lines (274 loc) · 8.82 KB
/
tracking.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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
var service;
var map;
var infowindow;
var chart1;
var chart2;
var flightCoordinates = [];
var file;
var file_write_name;
var CoordinateArray = [];
var valtozo;
google.load('visualization', '1', {packages: ['columnchart']});
google.setOnLoadCallback(plotElevation);
//FUNCTION 'INITIALIZE' IS CALLED EVERY TIME THE PAGE IS LOADED. IT CALLS EVERY OTHER FUNCTION
function initialize()
{
file = document.getElementById("myFile").files[0].name;
readDataFromTxtFile(file);
var mapOptions = {
center: new google.maps.LatLng(CoordinateArray[0].latitude, CoordinateArray[0].longitude),
zoom: 15,
//type: HYBRID ROADMAP SATELLITE TERRAIN
mapTypeId: 'hybrid'
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
for(var i=0; i<CoordinateArray.length; i = i+100)
{
flightCoordinates.push(new google.maps.LatLng(CoordinateArray[i].latitude, CoordinateArray[i].longitude));
}
var flightRoute = new google.maps.Polyline({
path: flightCoordinates,
geodesic: true,
strokeColor: '#00FF00',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightRoute.setMap(map);
var positionalRequest = {
'locations': flightCoordinates
}
//Create a new ElevationService
service = new google.maps.ElevationService();
service.getElevationForLocations(positionalRequest, function(results, status) {
if(status == google.maps.ElevationStatus.OK)
{
if(results[0])
{
infowindow = new google.maps.InfoWindow();
var latlong = new google.maps.LatLng(CoordinateArray[0].latitude, CoordinateArray[0].longitude, true);
infowindow.setContent('Elevation is:' + results[0].elevation + 'meters.');
infowindow.setPosition(latlong);
infowindow.open(map);
}
else{
alert('No results found');
}
}
else
{
alert('Elevation service failed due to: ' + status);
}
});
google.maps.event.addListener(map, 'click', printElevation);
flightRoute.setMap(map);
drawPath();
var file_name_parts = file.split("_");
file_write_name = "GPS_CORR_" + file_name_parts[1] + "_" + file_name_parts[2] + ".txt";
}
//-------------------------------------------------------------------------------------------------------------------------
function printElevation(event)
{
var locations = [];
locations.push(event.latLng);
var positionalRequest = {
'locations': locations
}
service.getElevationForLocations(positionalRequest, function(results, status){
if (status == google.maps.ElevationStatus.OK)
{
if(results[0])
{
var infowindow_clicked = new google.maps.InfoWindow();
var latlong = new google.maps.LatLng(47.590225, 19.101005, true);
infowindow.setContent('Elevation is: ' + results[0].elevation + 'meters.');
infowindow.setPosition(event.latLng);
infowindow.open(map);
}
else
{
alert('No results found');
}
}
else
{
alert('Elevation service failed due to: ' + status);
}
});
}
function drawPath()
{
chart1 = new google.visualization.ColumnChart(document.getElementById('measuredAltitude_chart'));
chart2 = new google.visualization.ColumnChart(document.getElementById('googleMapsElevation_chart'));
chart3 = new google.visualization.ColumnChart(document.getElementById('altitudeFromGround_chart'));
chart4 = new google.visualization.ColumnChart(document.getElementById('satellitesInView_chart'));
var pathRequest = {
'path': flightCoordinates,
'samples': 100
}
service.getElevationAlongPath(pathRequest, plotElevation);
}
function plotElevation(results, status)
{
if (status != google.maps.ElevationStatus.OK)
{return;}
var scale = CoordinateArray.length / results.length;
var iterator = 0;
//Setting and plotting measured altitude chart
var data1 = new google.visualization.DataTable();
data1.addColumn('string', 'Sample');
data1.addColumn('number', 'Elevation');
for (var i=0; i< CoordinateArray.length; i++)
{
if( i%10 == 0)
{
data1.addRow(['', CoordinateArray[i].measured_altitude]);
}
}
var options1 = {
title: "Altitude measured by GPS",
titleTextStyle: {fontName: "Times-Roman", fontSize: 40},
legend: "none",
titleY: "Altitude (m)"
};
chart1.draw(data1, options1);
//Setting and plotting google maps elevation chart
var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'Sample');
data2.addColumn('number', 'Elevation');
for (var i=0; i< results.length; i++)
{
data2.addRow(['', results[i].elevation]);
}
var options2 = {
title: "Elevation sampled on route",
titleTextStyle: {fontName: "Times-Roman", fontSize: 40},
legend: "none",
titleY: "Elevation (m)"
};
chart2.draw(data2, options2);
//Setting and plotting altitude from ground chart
var data3 = new google.visualization.DataTable();
data3.addColumn('string', 'Sample');
data3.addColumn('number', 'Elevation');
for(var i=0; i<CoordinateArray.length; i++)
{
iterator = parseInt(i / scale);
CoordinateArray[i].altitude_from_ground = CoordinateArray[i].measured_altitude - results[iterator].elevation;
if( i%10 == 0)
{
data3.addRow(['', CoordinateArray[i].altitude_from_ground]);
}
}
var options3 = {
title: "Elevation over ground sampled on route",
titleTextStyle: {fontName: "Times-Roman", fontSize: 40},
legend: "none",
titleY: "Elevation (m)"
};
chart3.draw(data3, options3);
//Plotting satellites in view
var data4 = new google.visualization.DataTable();
data4.addColumn('string', 'Sample');
data4.addColumn('number', 'Satellites');
for(var i=0; i<CoordinateArray.length; i++)
{
if( i%10 == 0)
{
data4.addRow(['', CoordinateArray[i].satellites_in_view]);
}
}
var options4 = {
title: "Satellites in view. Positive are differentially corrected, negatives are autonomous",
titleTextStyle: {fontName: "Times-Roman", fontSize: 40},
legend: "none",
titleY: "Number of satellites"
};
chart4.draw(data4, options4);
writeDataToTxtFile(file_write_name);
}
function readDataFromTxtFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status === 0)
{
var allText = rawFile.responseText;
var lines = allText.split("\n");
var iterator = 0;
for (var i=0; i<lines.length; i++)
{
var line = lines[i];
var lineData = line.split(",");
if( lineData[0] === "$GPRMC")
{
var time;
var date;
var latitude = 0;
var longitude = 0;
time = lineData[1];
date = lineData[9];
var latitudeDM = parseFloat(lineData[3]);
var latitudeInt = parseInt(latitudeDM);
var latitudeD = parseInt( latitudeInt / 100 );
var latitudeM = latitudeDM - latitudeD*100;
latitude = latitudeD + (latitudeM / 60);
if(lineData[4] === "S")
{
latitude = latitude * (-1);
}
var longitudeDM = parseFloat(lineData[5]);
var longitudeInt = parseInt(longitudeDM);
var longitudeD = parseInt( longitudeInt / 100 );
var longitudeM = longitudeDM - longitudeD*100;
longitude = longitudeD + (longitudeM / 60);
if(lineData[6] === "W")
{
longitude = longitude * (-1);
}
var text = '{"time":' + time +', "date":' + date +', "latitude":' + latitude + ', "longitude":' + longitude + ', "measured_altitude":' + 0.0 + ', "satellites_in_view":' + 0 + ', "altitude_from_ground":' + 0.0 + '}';
var newCoordinate = JSON.parse(text);
CoordinateArray.push(newCoordinate);
}
if( lineData[0] === "$GPGGA")
{
var altitude = parseFloat(lineData[9]);
var satellites = parseInt(lineData[7]);
if( parseInt(lineData[6]) == 1 )
{
satellites *= -1;
}
CoordinateArray[iterator].measured_altitude = altitude;
CoordinateArray[iterator].satellites_in_view = satellites;
iterator++;
}
}
}
}
}
rawFile.send(null);
}
function writeDataToTxtFile(file)
{
var url = "get_data.php"
var http = new XMLHttpRequest();
for(var i=0; i < CoordinateArray.length ; i++)
{
var http = new XMLHttpRequest();
http.open("POST", url, false);
data = "date=" + String(CoordinateArray[i].date) + "&time=" + String(CoordinateArray[i].time*100) + "&altitude=" + String(CoordinateArray[i].altitude_from_ground) + "";
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//http.setRequestHeader("Content-length", data.length);
//http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200)
{
}
}
http.send(data);
}
}
google.maps.event.addDomListener(window, 'resize', drawPath );