Completed
Push — master ( 25da5c...d1c288 )
by Yannick
08:24
created

live-czml.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('require/class.Connection.php');
3
require_once('require/class.Common.php');
4
require_once('require/class.Spotter.php');
5
require_once('require/class.SpotterLive.php');
6
require_once('require/class.SpotterArchive.php');
7
date_default_timezone_set('UTC');
8
$begintime = microtime(true);
9
$SpotterLive = new SpotterLive();
10
$Spotter = new Spotter();
11
$SpotterArchive = new SpotterArchive();
12
$Common = new Common();
13
14
15
function quaternionrotate($heading, $attitude = 0, $bank = 0) {
16
    // Assuming the angles are in radians.
17
    $c1 = cos($heading/2);
18
    $s1 = sin($heading/2);
19
    $c2 = cos($attitude/2);
20
    $s2 = sin($attitude/2);
21
    $c3 = cos($bank/2);
22
    $s3 = sin($bank/2);
23
    $c1c2 = $c1*$c2;
24
    $s1s2 = $s1*$s2;
25
    $w =$c1c2*$c3 - $s1s2*$s3;
26
    $x =$c1c2*$s3 + $s1s2*$c3;
27
    $y =$s1*$c2*$c3 + $c1*$s2*$s3;
28
    $z =$c1*$s2*$c3 - $s1*$c2*$s3;
29
    return array('x' => $x,'y' => $y,'z' => $z,'w' => $w);
30
//    return array('x' => '0.0','y' => '-0.931','z' => '0.0','w' => '0.365');
31
32
}
33
34
35
if (isset($_GET['download'])) {
36
    if ($_GET['download'] == "true")
37
    {
38
	header('Content-disposition: attachment; filename="flightairmap.json"');
39
    }
40
}
41
header('Content-Type: text/javascript');
42
43
if (!isset($globalJsonCompress)) $compress = true;
44
else $compress = $globalJsonCompress;
45
46
$from_archive = false;
47
$min = false;
48
$allhistory = false;
49
$filter['source'] = array();
50
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
51
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
52
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
53
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs'));
54
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
55
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
56
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
57
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
58
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
59
/*
60
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
61
	$min = true;
62
}
63
64
if (isset($_GET['ident'])) {
65
	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
66
	$spotter_array = $SpotterLive->getLastLiveSpotterDataByIdent($ident);
67
	if (empty($spotter_array)) {
68
		$from_archive = true;
69
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
70
	}
71
	$allhistory = true;
72
} elseif (isset($_GET['flightaware_id'])) {
73
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
74
	$spotter_array = $SpotterLive->getLastLiveSpotterDataById($flightaware_id);
75
	if (empty($spotter_array)) {
76
		$from_archive = true;
77
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
78
	}
79
	$allhistory = true;
80
} elseif (isset($_GET['coord'])) {
81
	$coord = explode(',',$_GET['coord']);
82
	$spotter_array = $SpotterLive->getLiveSpotterDatabyCoord($coord,$filter);
83
} elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
84
	$from_archive = true;
85
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
86
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
87
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
88
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
89
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
90
	$begindate = date('Y-m-d H:i:s',$begindate);
91
	$enddate = date('Y-m-d H:i:s',$enddate);
92
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
93
} elseif ($min) {
94
	//$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
95
	$spotter_array = $SpotterLive->getMinLastLiveSpotterData($filter);
96
#	$min = true;
97
} else {
98
	$spotter_array = $SpotterLive->getLiveSpotterData('','',$filter);
99
}
100
*/
101
if (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
102
	$from_archive = true;
103
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
104
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
105
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
106
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
107
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
108
	$begindate = date('Y-m-d H:i:s',$begindate);
109
	$enddate = date('Y-m-d H:i:s',$enddate);
110
	$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
111
} elseif (isset($_COOKIE['archive']) && isset($_COOKIE['archive_begin']) && isset($_COOKIE['archive_end']) && isset($_COOKIE['archive_speed'])) {
112
	$from_archive = true;
113
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
114
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
115
//	$begindate = filter_var($_COOKIE['archive_begin'],FILTER_SANITIZE_NUMBER_INT);
116
//	$enddate = filter_var($_COOKIE['archive_end'],FILTER_SANITIZE_NUMBER_INT);
117
	$begindate = $_COOKIE['archive_begin'];
118
	$enddate = $_COOKIE['archive_end'];
119
120
	$archivespeed = filter_var($_COOKIE['archive_speed'],FILTER_SANITIZE_NUMBER_INT);
121
	$begindate = date('Y-m-d H:i:s',$begindate);
122
	$enddate = date('Y-m-d H:i:s',$enddate);
123
//	echo 'Begin : '.$begindate.' - End : '.$enddate."\n";
124
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
125
} else {
126
	$spotter_array = $SpotterLive->getMinLastLiveSpotterData($filter);
127
}
128
129
if (!empty($spotter_array)) {
130
	if (isset($_GET['archive'])) {
131
		$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
132
	} else {
133
		$flightcnt = $SpotterLive->getLiveSpotterCount($filter);
134
	}
135
	if ($flightcnt == '') $flightcnt = 0;
136
} else $flightcnt = 0;
137
138
$sqltime = round(microtime(true)-$begintime,2);
139
$minitime = time();
140
$maxitime = 0;
141
142
143
$modelsdb = array();
144
if (file_exists('models/modelsdb')) {
145
	if (($handle = fopen('models/modelsdb','r')) !== FALSE) {
146
		while (($row = fgetcsv($handle,1000)) !== FALSE) {
147
			if (isset($row[1]) ){
148
				$model = $row[0];
149
				$modelsdb[$model] = $row[1];
150
			}
151
		}
152
		fclose($handle);
153
	}
154
}
155
$heightrelative = 'NONE';
156
$j = 0;
157
$prev_flightaware_id = '';
158
$speed = 1;
159
if (isset($archivespeed)) $speed = $archivespeed;
160
$output = '[';
161
$output .= '{"id" : "document", "name" : "fam","version" : "1.0"';
162
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "LOOP_STOP","step": "SYSTEM_CLOCK_MULTIPLIER"}';
163
164
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
165
//$output .= ',"clock": {"currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
166
if ($from_archive === true) {
167
	$output .= ',"clock": {"currentTime" : "%minitime%","multiplier" : '.$speed.',"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER","interval": "%minitime%/%maxitime%"}';
168
} else {
169
	$output .= ',"clock": {"currentTime" : "%minitime%","multiplier" : '.$speed.',"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
170
}
171
172
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"step": "SYSTEM_CLOCK_MULTIPLIER"}';
173
$output .= '},';
174
if (!empty($spotter_array) && is_array($spotter_array))
175
{
176
	foreach($spotter_array as $spotter_item)
177
	{
178
		$j++;
179
		date_default_timezone_set('UTC');
180
		if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
181
		{
182
			$image = $spotter_item['image_thumbnail'];
183
		} else {
184
			$image = "images/placeholder_thumb.png";
185
		}
186
187
188
		if ($prev_flightaware_id != $spotter_item['flightaware_id']) {
189
			if ($prev_flightaware_id != '') {
190
				$output .= ']';
191
				$output .= '}';
192
				//$output .= ', '.$orientation.']}';
193
				$output .= '},';
194
			}
195
			$orientation = '';
196
			$prev_flightaware_id = $spotter_item['flightaware_id'];
197
			$output .= '{';
198
			$output .= '"id": "'.$spotter_item['flightaware_id'].'",';
199
			$output .= '"properties": {';
200
			// Not yet supported in CZML with Cesium
201
			$output .= '},';
202
203
			$output .= '"path" : { ';
204
			$output .= '"show" : false, ';
205
			$output .= '"material" : { ';
206
			$output .= '"polylineOutline" : { ';
207
			$output .= '"color" : { "rgba" : [238, 250, 255, 255] }, ';
208
			$output .= '"outlineColor" : { "rgba" : [200, 209, 214, 255] }, ';
209
			$output .= '"outlineWidth" : 5, ';
210
			$output .= '"polylineGlow" : { "color" : { "rgba" : [214, 208, 214, 255] }, "glowPower" : 3 } ';
211
			$output .= '}';
212
			$output .= '}, ';
213
			$output .= '"heightReference": "'.$heightrelative.'",';
214
			$output .= '"width" : 6, "leadTime" : 0, "trailTime" : 1000000, "resolution" : 10 },';
215
				
216
			//$output .= ' "billboard" : {"image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAfCAYAAACVgY94AAAACXBIWXMAAC4jAAAuIwF4pT92AAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRBy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g6wB76WMB0dALf526foAX8cqUot2pGP8B2Kz+krBeNYjS8636dh/8Beo2deoA9TWp76pd6g0q9cDNwKvAD8A84EfglLRBe2g+JWAfcEF68bPABOCoAl/gIPA5MA64FVgGnNhP292W3r0SeB1YVlJXAjcBP8XwyQUj9AKwAzg2+/fQSsBhoJxBAaALaIzenZGnD911wA7gEDAD2FFSpwOzgDHZ5T7+ZSlGd2d6AXgi5+qAn+O5U0PbBVwKtAD3AHuB8f3YGBUdncCGoQ4LE9XtGRqK9LnduVPRIu2BPqwD65IYbS7Qpql7Ql9YoJcy9bwzkgPrfOCj5G33+h54E/g0PAr5thq4ApgyEgNrc27aWwVaPTA1QJ4BjgTGFvhteV40EgPrgvTP7qlmZqFnl9WD+b2posN83E/NrEkOjlI/U1fkfUYa/pe5IE3qZPW8jFOqiyN7p3pAPX04c7AxYSoDDcAjKT2LgLXA6IR2M3Bviv59wDTgQGTPH84Qd8+HXfHcoUws2zM0HMjuUPep+xP2PWpnwtw0GJsldbBpewQwE/gbeDyt7H1gcW53O7AC+A3Yn6+/W+Ld9SnWA15DAVhc8xK2TuA9YHrCuhV4EngFuBx4YagG6qv8cF+T52kB2Zy+e1I8taUacNV+uBdXO7ABmJwJpwx8XQvF9TUCWM64tiQhbq/oMv+7BwFWpQzNT8vbVQul/wwAGzzdmXU1xuUAAAAASUVORK5CYII=","scale" : 1.5},';
217
			$aircraft_icao = $spotter_item['aircraft_icao'];
218
219
			if (isset($modelsdb[$aircraft_icao])) {
220
				$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_icao].'","scale" : 1.0,"minimumPixelSize": 20 ,';
221
				$output .= '"heightReference": "'.$heightrelative.'"},';
222
			} elseif ($aircraft_icao != '') {
223
				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao);
224
				if (count($aircraft_info) > 0) {
225
					$aircraft_shadow = $aircraft_info[0]['aircraft_shadow'];
226
					$spotter_item['engine_type'] = $aircraft_info[0]['engine_type'];
227
					$spotter_item['wake_category'] = $aircraft_info[0]['wake_category'];
228
					$spotter_item['engine_count'] = $aircraft_info[0]['engine_count'];
229
				} else $aircraft_shadow = '';
230
				if ($aircraft_shadow != '') {
231
					if (isset($modelsdb[$aircraft_shadow])) {
232
						$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_shadow].'","scale" : 1.0,"minimumPixelSize": 20 ,';
233
						$output .= '"heightReference": "'.$heightrelative.'"},';
234
						$modelsdb[$aircraft_icao] = $modelsdb[$aircraft_shadow];
235
					} elseif ($spotter_item['engine_type'] == 'Jet') {
236
						if ($spotter_item['engine_count'] == '1') {
237
							if ($spotter_item['wake_category'] == 'M') {
238
								$model = 'J1M';
239
							} elseif ($spotter_item['wake_category'] == 'L') {
240
								$model = '';
241
							}
242
						} elseif ($spotter_item['engine_count'] == '2') {
243
							if ($spotter_item['wake_category'] == 'M') {
244
								$model = 'J2M';
245
							} elseif ($spotter_item['wake_category'] == 'H') {
246
								$model = 'J2H';
247
							} elseif ($spotter_item['wake_category'] == 'L') {
248
								$model = 'J2L';
249
							}
250
						} elseif ($spotter_item['engine_count'] == '3') {
251
							if ($spotter_item['wake_category'] == 'M') {
252
								$model = 'J3M';
253
							} elseif ($spotter_item['wake_category'] == 'H') {
254
								$model = 'J3H';
255
							}
256
						} elseif ($spotter_item['engine_count'] == '4') {
257
							if ($spotter_item['wake_category'] == 'M') {
258
								$model = 'J4M';
259
							} elseif ($spotter_item['wake_category'] == 'H') {
260
								$model = 'J4H';
261
							}
262
						}
263
						if (isset($modelsdb[$model])) {
264
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20,';
265
							$output .= '"heightReference": "'.$heightrelative.'"},';
266
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
267
						} else {
268
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
269
							$output .= '"heightReference": "'.$heightrelative.'"},';
270
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
271
						}
272
					} elseif ($spotter_item['engine_type'] == 'Turboprop') {
273
						if ($spotter_item['engine_count'] == '1') {
274
							if ($spotter_item['wake_category'] == 'L') {
275
								$model = 'T1L';
276
							}
277
						} elseif ($spotter_item['engine_count'] == '2') {
278
							if ($spotter_item['wake_category'] == 'M') {
279
								$model = 'T2M';
280
							} elseif ($spotter_item['wake_category'] == 'L') {
281
								$model = 'T2L';
282
							}
283
						} elseif ($spotter_item['engine_count'] == '4') {
284
							if ($spotter_item['wake_category'] == 'M') {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
285
							} elseif ($spotter_item['wake_category'] == 'H') {
286
								$model = 'T4H';
287
							}
288
						}
289
						if (isset($modelsdb[$model])) {
290
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20 ,';
291
							$output .= '"heightReference": "'.$heightrelative.'"},';
292
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
293
						} else {
294
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20 ,';
295
							$output .= '"heightReference": "'.$heightrelative.'"},';
296
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
297
						}
298
					} elseif ($spotter_item['engine_type'] == 'Piston') {
299
						if ($spotter_item['engine_count'] == '1') {
300
							if ($spotter_item['wake_category'] == 'L') {
301
								$model = 'P1L';
302
							} elseif ($spotter_item['wake_category'] == 'M') {
303
								$model = 'P1M';
304
							}
305
						} elseif ($spotter_item['engine_count'] == '2') {
306
							if ($spotter_item['wake_category'] == 'M') {
307
								$model = 'P2M';
308
							} elseif ($spotter_item['wake_category'] == 'L') {
309
								$model = 'P2L';
310
							}
311
							// ju52 = P3M
312
						}
313
						if (isset($modelsdb[$model])) {
314
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20 ,';
315
							$output .= '"heightReference": "'.$heightrelative.'"},';
316
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
317
						} else {
318
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20 ,';
319
							$output .= '"heightReference": "'.$heightrelative.'"},';
320
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
321
						}
322
					} else {
323
						$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
324
						$output .= '"heightReference": "'.$heightrelative.'"},';
325
							//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
326
						if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
327
						$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
328
					}
329
				} elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') {
330
					$aircraft_shadow = 'PA18';
331
					$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_shadow].'","scale" : 1.0,"minimumPixelSize": 20 ,';
332
					$output .= '"heightReference": "'.$heightrelative.'"},';
333
					$modelsdb[$aircraft_icao] = $modelsdb[$aircraft_shadow];
334
				} else {
335
					$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
336
					$output .= '"heightReference": "'.$heightrelative.'"},';
337
					//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
338
					if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
339
					$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
340
				}
341
342
			} else {
343
				$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
344
				$output .= '"heightReference": "'.$heightrelative.'"},';
345
				//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
346
				if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
347
				$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
348
			}
349
	//		$output .= '"heightReference": "CLAMP_TO_GROUND",';
350
			$output .= '"heightReference": "'.$heightrelative.'",';
351
	//		$output .= '"heightReference": "NONE",';
352
			$output .= '"position": {';
353
			$output .= '"interpolationAlgorithm":"HERMITE","interpolationDegree":3,';
354
			$output .= '"type": "Point",';
355
	//		$output .= '"interpolationAlgorithm" : "LAGRANGE",';
356
	//		$output .= '"interpolationDegree" : 5,';
357
	//		$output .= '"epoch" : "'.date("c",strtotime($spotter_item['date'])).'", ';
358
			$output .= '"cartographicDegrees": [';
359
			if ($minitime > strtotime($spotter_item['date'])) $minitime = strtotime($spotter_item['date']);
360
			if ($maxitime < strtotime($spotter_item['date'])) $maxitime = strtotime($spotter_item['date']);
361
			$output .= '"'.date("c",strtotime($spotter_item['date'])).'", ';
362
			$output .= $spotter_item['longitude'].', ';
363
			$output .= $spotter_item['latitude'].', ';
364
			$prevlong = $spotter_item['longitude'];
365
			$prevlat = $spotter_item['latitude'];
366
			$output .= round($spotter_item['altitude']*30.48);
367
			$prevalt = round($spotter_item['altitude']*30.48);
368
			//$orientation = '"orientation" : { ';
369
			//$orientation .= '"unitQuaternion": [';
370
			//$quat = quaternionrotate(deg2rad($spotter_item['heading']),deg2rad(0),deg2rad(0));
371
			//$orientation .= '"'.date("c",strtotime($spotter_item['date'])).'",'.$quat['x'].','.$quat['y'].','.$quat['z'].','.$quat['w'];
372
		} else {
373
			$output .= ',"'.date("c",strtotime($spotter_item['date'])).'", ';
374
			if ($maxitime < strtotime($spotter_item['date'])) $maxitime = strtotime($spotter_item['date']);
375
			if ($spotter_item['ground_speed'] == 0) {
376
				$output .= $prevlong.', ';
377
				$output .= $prevlat.', ';
378
				$output .= $prevalt;
379
			} else {
380
				$output .= $spotter_item['longitude'].', ';
381
				$output .= $spotter_item['latitude'].', ';
382
				if ($spotter_item['altitude'] == '') {
383
					if ($prevalt != '') {
384
						$output .= $prevalt;
385
					} else {
386
						$output .= 0;
387
					}
388
				} else {
389
					$output .= round($spotter_item['altitude']*30.48);
390
				}
391
			}
392
			//$quat = quaternionrotate(deg2rad($spotter_item['heading']),deg2rad(0),deg2rad(0));
393
			//$orientation .= ',"'.date("c",strtotime($spotter_item['date'])).'",'.$quat['x'].','.$quat['y'].','.$quat['z'].','.$quat['w'];
394
		}
395
	}
396
	$output  = substr($output, 0, -1);
397
	$output .= ']}}';
398
} else {
399
	$output  = substr($output, 0, -1);
400
}
401
$output .= ']';
402
$output = str_replace('%minitime%',date("c",$minitime),$output);
403
$output = str_replace('%maxitime%',date("c",$maxitime),$output);
404
print $output;
405
?>
406