forked from Ysurac/FlightAirMap
/
live-geojson.php
349 lines (327 loc) · 16.2 KB
/
live-geojson.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
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
<?php
require('require/class.Connection.php');
require('require/class.Spotter.php');
require('require/class.SpotterLive.php');
require('require/class.SpotterArchive.php');
$SpotterLive = new SpotterLive();
$Spotter = new Spotter();
$SpotterArchive = new SpotterArchive();
if (isset($_GET['download'])) {
if ($_GET['download'] == "true")
{
header('Content-disposition: attachment; filename="flightairmap.json"');
}
}
header('Content-Type: text/javascript');
$from_archive = false;
$min = false;
$allhistory = false;
$filter= array();
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['ShowVATSIM']) && $_COOKIE['ShowVATSIM']) $filter = array_merge($filter,array('vatsimtxt'));
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['ShowIVAO']) && $_COOKIE['ShowIVAO']) $filter = array_merge($filter,array('whazzup'));
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) $min = true;
if (isset($_GET['ident'])) {
$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
$spotter_array = $SpotterLive->getLastLiveSpotterDataByIdent($ident);
if (empty($spotter_array)) {
$from_archive = true;
$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
}
$allhistory = true;
} elseif (isset($_GET['flightaware_id'])) {
$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
$spotter_array = $SpotterLive->getLastLiveSpotterDataById($flightaware_id);
if (empty($spotter_array)) {
$from_archive = true;
$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
}
$allhistory = true;
} elseif (isset($_GET['coord']) && (!isset($globalMapPopup) || $globalMapPopup || (isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true'))) {
//if (isset($_GET['coord'])) {
$coord = explode(',',$_GET['coord']);
$spotter_array = $SpotterLive->getLiveSpotterDatabyCoord($coord,$filter);
#} elseif (isset($globalMapPopup) && !$globalMapPopup) {
} elseif ($min) {
$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
# $min = true;
} else {
$spotter_array = $SpotterLive->getLiveSpotterData('','',$filter);
}
if (!empty($spotter_array)) {
$flightcnt = $SpotterLive->getLiveSpotterCount($filter);
if ($flightcnt == '') $flightcnt = 0;
} else $flightcnt = 0;
$output = '{';
$output .= '"type": "FeatureCollection",';
if ($min) $output .= '"minimal": "true",';
else $output .= '"minimal": "false",';
if (!empty($spotter_array) && is_array($spotter_array))
{
$output .= '"features": [';
foreach($spotter_array as $spotter_item)
{
date_default_timezone_set('UTC');
if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
{
$image = $spotter_item['image_thumbnail'];
} else {
$image = "images/placeholder_thumb.png";
}
//waypoint plotting
/*
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"flightaware_id": "'.$spotter_item['flightaware_id'].'",';
$output .= '"callsign": "'.$spotter_item['ident'].'",';
$output .= '"registration": "'.$spotter_item['registration'].'",';
$output .= '"aircraft_name": "'.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')",';
$output .= '"airline_name": "'.$spotter_item['airline_name'].'",';
$output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",';
$output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",';
$output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",';
$output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",';
$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
$output .= '"latitude": "'.$spotter_item['latitude'].'",';
$output .= '"longitude": "'.$spotter_item['longitude'].'",';
$output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",';
$output .= '"altitude": "'.$spotter_item['altitude'].'",';
$output .= '"heading": "'.$spotter_item['heading'].'",';
$output .= '"image": "'.$image.'",';
$output .= '"type": "route"';
$output .= '},';
$output .= '"geometry": {';
$output .= '"type": "LineString",';
$output .= '"coordinates": [';
$waypoint_pieces = explode(' ', $spotter_item['waypoints']);
$waypoint_pieces = array_chunk($waypoint_pieces, 2);
foreach ($waypoint_pieces as $waypoint_coordinate)
{
$output .= '[';
$output .= $waypoint_coordinate[1].', ';
$output .= $waypoint_coordinate[0];
$output .= '],';
}
$output = substr($output, 0, -1);
$output .= ']';
$output .= '}';
$output .= '},';
*/
//location of aircraft
// print_r($spotter_item);
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"flightaware_id": "'.$spotter_item['flightaware_id'].'",';
$output .= '"flight_cnt": "'.$flightcnt.'",';
/*
if ($min) $output .= '"minimal": "true",';
else $output .= '"minimal": "false",';
*/
//$output .= '"flight_cnt": "'.$spotter_item['nb'].'",';
if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
$output .= '"callsign": "'.$spotter_item['ident'].'",';
} else {
$output .= '"callsign": "NA",';
}
if (isset($spotter_item['registration'])) $output .= '"registration": "'.$spotter_item['registration'].'",';
if (isset($spotter_item['aircraft_name']) && isset($spotter_item['aircraft_type'])) {
$output .= '"aircraft_name": "'.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')",';
$output .= '"aircraft_wiki": "http://'.strtolower($globalLanguage).'.wikipedia.org/wiki/'.urlencode(str_replace(' ','_',$spotter_item['aircraft_name'])).'",';
} elseif (isset($spotter_item['aircraft_type'])) {
$output .= '"aircraft_name": "NA ('.$spotter_item['aircraft_type'].')",';
} elseif (!$min) {
$output .= '"aircraft_name": "NA",';
}
if (!isset($spotter_item['aircraft_shadow'])) {
if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
else {
$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
else $spotter_item['aircraft_shadow'] = '';
}
}
if ($spotter_item['aircraft_shadow'] == '') {
$output .= '"aircraft_shadow": "default.png",';
} else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
if (isset($spotter_item['airline_name'])) {
$output .= '"airline_name": "'.$spotter_item['airline_name'].'",';
} elseif (!$min) {
$output .= '"airline_name": "NA",';
}
if (isset($spotter_item['departure_airport'])) {
$output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",';
}
if (isset($spotter_item['departure_airport_city'])) {
$output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",';
}
if (isset($spotter_item['departure_airport_time'])) {
$output .= '"departure_airport_time": "'.$spotter_item['departure_airport_time'].'",';
}
if (isset($spotter_item['arrival_airport_time'])) {
$output .= '"arrival_airport_time": "'.$spotter_item['arrival_airport_time'].'",';
}
if (isset($spotter_item['arrival_airport'])) {
$output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",';
}
if (isset($spotter_item['arrival_airport_city'])) {
$output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",';
}
if (isset($spotter_item['date_iso_8601'])) {
$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
}
$output .= '"latitude": "'.$spotter_item['latitude'].'",';
$output .= '"longitude": "'.$spotter_item['longitude'].'",';
$output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",';
$output .= '"altitude": "'.$spotter_item['altitude'].'",';
$output .= '"heading": "'.$spotter_item['heading'].'",';
if (!$min) $output .= '"image": "'.$image.'",';
if (isset($spotter_item['image_copyright']) && $spotter_item['image_copyright'] != '') {
$output .= '"image_copyright": "'.str_replace('"',"'",trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$spotter_item['image_copyright']))).'",';
}
if (isset($spotter_item['image_source_website'])) {
$output .= '"image_source_website": "'.urlencode($spotter_item['image_source_website']).'",';
}
if (isset($spotter_item['squawk'])) {
$output .= '"squawk": "'.$spotter_item['squawk'].'",';
}
if (isset($spotter_item['squawk_usage'])) {
$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
}
if (isset($spotter_item['pilot_id'])) {
$output .= '"pilot_id": "'.$spotter_item['pilot_id'].'",';
}
if (isset($spotter_item['pilot_name'])) {
$output .= '"pilot_name": "'.$spotter_item['pilot_name'].'",';
}
if (isset($spotter_item['waypoints']) && $spotter_item['waypoints'] != '') {
$output .= '"waypoints": "'.$spotter_item['waypoints'].'",';
}
if (isset($spotter_item['acars'])) {
$output .= '"acars": "'.trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), '<br />',$spotter_item['acars']['message'])).'",';
}
// FIXME : type when not aircraft ?
$output .= '"type": "aircraft"';
$output .= '},';
$output .= '"geometry": {';
$output .= '"type": "Point",';
$output .= '"coordinates": [';
$output .= $spotter_item['longitude'].', ';
$output .= $spotter_item['latitude'];
$output .= ']';
$output .= '}';
$output .= '},';
/*
//previous location history of aircraft
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"callsign": "'.$spotter_item['ident'].'",';
$output .= '"type": "history"';
$output .= '},';
$output .= '"geometry": {';
$output .= '"type": "LineString",';
$output .= '"coordinates": [';
//$spotter_history_array = SpotterLive::getAllLiveSpotterDataByIdent($spotter_item['ident']);
if ($from_archive) {
$spotter_history_array = SpotterArchive::getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
} else {
$spotter_history_array = SpotterLive::getAllLiveSpotterDataById($spotter_item['flightaware_id']);
}
$d = false;
$neg = false;
$history_output = '';
foreach ($spotter_history_array as $key => $spotter_history)
{
if (abs($spotter_history['longitude']-$spotter_item['longitude']) > 200 || $d==true) {
if ($d == false) $d = true;
} else {
$history_output .= '[';
$history_output .= $spotter_history['longitude'].', ';
$history_output .= $spotter_history['latitude'].',';
$history_output .= $spotter_history['altitude'];
$history_output .= '],';
}
}
if ($history_output != '') $output .= substr($history_output, 0, -1);
$output .= ']';
$output .= '}';
$output .= '},';
}
*/
if ((isset($_COOKIE['flightpath']) && $_COOKIE['flightpath'] == 'true') || (!isset($_COOKIE['flightpath']) && (!isset($globalMapHistory) || $globalMapHistory || $allhistory) || (isset($_GET['history']) && ($_GET['history'] == $spotter_item['ident'] || $_GET['history'] == $spotter_item['flightaware_id'])))) {
if ($from_archive) {
$spotter_history_array = $SpotterArchive->getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
} else {
$spotter_history_array = $SpotterLive->getAllLiveSpotterDataById($spotter_item['flightaware_id']);
}
$d = false;
foreach ($spotter_history_array as $key => $spotter_history)
{
if (abs($spotter_history['longitude']-$spotter_item['longitude']) > 200 || $d==true) {
if ($d == false) $d = true;
} else {
$alt = round($spotter_history['altitude']/10)*10;
if (!isset($prev_alt) || $prev_alt != $alt) {
if (isset($prev_alt)) {
//$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].','.$spotter_history['altitude'].']';
$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].']';
$output_history .= ']}},';
$output .= $output_history;
}
$output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history","altitude": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
}
$output_history .= '[';
$output_history .= $spotter_history['longitude'].', ';
$output_history .= $spotter_history['latitude'];
//$output_history .= $spotter_history['altitude'];
$output_history .= '],';
$prev_alt = $alt;
}
}
if (isset($output_history)) {
$output_history = substr($output_history, 0, -1);
$output_history .= ']}},';
$output .= $output_history;
unset($prev_alt);
unset($output_history);
}
}
if (isset($_GET['history']) && $_GET['history'] == $spotter_item['ident'] && isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA' && isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA' && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") || (!isset($_COOKIE['MapRoute']) && (!isset($globalMapRoute) || (isset($globalMapRoute) && $globalMapRoute))))) {
$output_air = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "route"},"geometry": {"type": "LineString","coordinates": [';
if (isset($spotter_item['departure_airport_latitude'])) {
$output_air .= '['.$spotter_item['departure_airport_longitude'].','.$spotter_item['departure_airport_latitude'].'],';
} elseif (isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA') {
$dairport = $Spotter->getAllAirportInfo($spotter_item['departure_airport']);
//print_r($dairport);
//echo $spotter_item['departure_airport'];
if (isset($dairport[0]['latitude'])) {
$output_air .= '['.$dairport[0]['longitude'].','.$dairport[0]['latitude'].'],';
}
}
if (isset($spotter_item['arrival_airport_latitude'])) {
$output_air .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].']';
} elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
//print_r($aairport);
$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
if (isset($aairport[0]['latitude'])) {
$output_air .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].']';
}
}
$output_air .= ']}},';
$output .= $output_air;
unset($output_air);
}
}
$output = substr($output, 0, -1);
$output .= ']';
} else {
$output .= '"features": ';
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"flight_cnt": "'.$flightcnt.'"}}';
}
$output .= '}';
print $output;
?>