-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflightid.html
187 lines (179 loc) · 6.92 KB
/
flightid.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
flightid API
</title>
<script type="text/javascript"
src="js/jquery-2.0.3.js">
</script>
<script src=http://mrdoob.github.io/three.js/build/three.min.js ></script>
<script src="js/geodesic.js"
type="text/javascript">
</script>
<script src="js/utils.js"
type="text/javascript">
</script>
</head>
<body>
<script>
/* --- data sample ---
{"header":{"code":200,"msg":"OK","request_time":"2014-09-07 02:49:24+0800","request_time_raw":1410029364,"process_time":0.068974018096924},
"data":
{"flightid":5068255,"callsign":"Quofei","model":"787","start_time":"2013-12-01 10:54:14+08","start_time_raw":1385866454,"end_time":"2013-12-01 11:08:41+08","end_time_raw":1385867321,"duration":"00:14:27","duration_raw":867,
"wpts":88,
"wpt":
[{"time":"2013-12-01 10:54:19+08","time_raw":1385866459,"lat":51.469534,"lon":-0.471783,"alt":85.53846},
{"time":"2013-12-01 10:54:29+08","time_raw":1385866469,"lat":51.469534,"lon":-0.471783,"alt":85.534576},
{"time":"2013-12-01 10:54:39+08","time_raw":1385866479,"lat":51.469534,"lon":-0.471783,"alt":85.534576},
{"time":"2013-12-01 10:54:49+08","time_raw":1385866489,"lat":51.469534,"lon":-0.471783,"alt":85.534576},
{"time":"2013-12-01 10:54:59+08","time_raw":1385866499,"lat":51.469534,"lon":-0.471783,"alt":85.534576},
....
{"time":"2013-12-01 11:08:39+08","time_raw":1385867319,"lat":51.561365,"lon":0.366383,"alt":20350.795887},
{"time":"2013-12-01 11:08:49+08","time_raw":1385867329,"lat":51.561977,"lon":0.370583,"alt":20441.993934}
]
}
}
------------------- */
var start = new Date();
var use_proxy = true;
var tr_url = 'proxy/flightid.php';
var yh_tail = '%22&format=json&callback=';
var yh_url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmpserver15.flightgear.org%2Fmodules%2Ffgtracker%2Finterface.php%3Faction%3Dflight%26flightid%3D';
var yh_url2 = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fmpserver15.flightgear.org%2Fmodules%2Ffgtracker%2Finterface.php%3Faction%3Dlivewaypoints%22&format=json&callback=';
var max_txt = 600; // limit but include first few waypoints
var bgn_req;
function CB_flightid() {
if (this.readyState != 4) {
return;
}
if (this.status != "200") {
return;
}
var text = this.responseText;
var len = text.length;
var data, wpta, wptcnt, alt;
var dnerr = false;
if (use_proxy) {
data = JSON.parse(text);
} else {
try {
file = JSON.parse(text);
data = file.query.results.body.p;
data = JSON.parse( data );
} catch( err ) {
msg = "Got error: "+err.message;
console.log(msg);
$("#msg3").html(msg);
//setStatus(msg);
msg = text;
if (len > max_txt) {
msg = msg.substr(0,max_txt);
}
$("#msg1").html(msg);
console.log(msg);
dnerr = true;
//lto = 55;
}
}
var elap = getElapsed(bgn_req);
msg = 'Fetched '+len+' bytes in '+elap;
if (use_proxy) {
msg += ', using '+tr_url;
} else {
msg += ', using Yahoo!';
}
if (data && data.data && data.data.wpt) {
wpta = data.data.wpt;
wptcnt = wpta.length;
msg += " total " + wptcnt + " waypoints";
var dato = data.data;
// data":{"flightid":5781776,"callsign":"Alpha","model":"BAC-TSR2-model",
// "start_time":"2014-09-09 17:48:00+08","start_time_raw":1410256080,
// "end_time":"2014-09-09 19:22:25+08","end_time_raw":1410261745,
// "duration":"01:34:25","duration_raw":5665,"wpts":568
msg += ', flightid '+dato.flightid+', callsign '+dato.callsign+', model '+dato.model+', duration '+dato.duration;
}
$("#update").html(msg);
if (!dnerr) {
if (len > max_txt) {
text = text.substr(0,max_txt);
}
$("#msg1").html(text);
}
var headers = [];
var html = '<div align="center">';
html += '<table border="0" cellpadding="2" cellspacing="4" align="center">';
if (data && data.data && data.data.wpt) {
wpta = data.data.wpt;
// display the key and value pair
// 1: get keys of the first
$.each(wpta, function(i, v) {
//display the key and value pair
$.each(v, function(j, v2) {
headers.push(j);
});
return false;
});
html += '<tr>';
$.each(headers, function(k,v3) {
html += '<th>' + v3 + '</th>';
});
html += '</tr>';
$.each(wpta, function(i, v) {
html += '<tr>';
$.each(v, function(j, v2) {
if ( j == 'alt' ) {
if (v2 < 5000) {
alt = parseInt(v2);
} else {
alt = 'FL' + parseInt(v2 / 100);
}
html += '<td align="right">' + alt + '</td>';
} else {
html += '<td>' + v2 + '</td>';
}
});
html += '</tr>';
});
html += '</table>';
html += '</div>';
$("#msg3").html(html);
} else {
$("#msg3").html("data failed!");
}
}
function getData(id) {
bgn_req = new Date();
var url;
if (use_proxy) {
url = tr_url + "?id=" + id;
} else {
url = yh_url + id + yh_tail;
//url = yh_url2;
}
getUrlwithCB(url,CB_flightid);
}
function init() {
document.body.style.cssText = ' font: 8pt monospace; margin: 0; overflow: hidden; ';
var info = document.body.appendChild( document.createElement( 'div' ) );
info.style.cssText = 'left: 10px; position: absolute; width: 95%;';
info.innerHTML = '<a href="" ><h1 align="center">' + document.title + '</h1></a> ' +
'<div id=update ></div>' +
'<div id=msg1 ></div>' +
'<div id=msg2 ></div>' +
'<div id=msg3 ></div>' +
'';
var id = gup('id');
if (id.length) {
$("#update").html("Attempting to fetch flightid="+id+"... moment...");
getData(id);
} else {
$("#update").html("No flight id=value found in url parameters! Nothing to do...");
}
}
init();
</script>
</body>
</html>