Completed
Push — master ( cf2b25...fb7f07 )
by Yannick
06:18
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
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
60
/*
61
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
62
	$min = true;
63
}
64
65
if (isset($_GET['ident'])) {
66
	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
67
	$spotter_array = $SpotterLive->getLastLiveSpotterDataByIdent($ident);
68
	if (empty($spotter_array)) {
69
		$from_archive = true;
70
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
71
	}
72
	$allhistory = true;
73
} elseif (isset($_GET['flightaware_id'])) {
74
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
75
	$spotter_array = $SpotterLive->getLastLiveSpotterDataById($flightaware_id);
76
	if (empty($spotter_array)) {
77
		$from_archive = true;
78
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
79
	}
80
	$allhistory = true;
81
} elseif (isset($_GET['coord'])) {
82
	$coord = explode(',',$_GET['coord']);
83
	$spotter_array = $SpotterLive->getLiveSpotterDatabyCoord($coord,$filter);
84
} elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
85
	$from_archive = true;
86
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
87
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
88
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
89
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
90
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
91
	$begindate = date('Y-m-d H:i:s',$begindate);
92
	$enddate = date('Y-m-d H:i:s',$enddate);
93
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
94
} elseif ($min) {
95
	//$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
96
	$spotter_array = $SpotterLive->getMinLastLiveSpotterData($filter);
97
#	$min = true;
98
} else {
99
	$spotter_array = $SpotterLive->getLiveSpotterData('','',$filter);
100
}
101
*/
102
if (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
103
	$from_archive = true;
104
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
105
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
106
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
107
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
108
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
109
	$begindate = date('Y-m-d H:i:s',$begindate);
110
	$enddate = date('Y-m-d H:i:s',$enddate);
111
	$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
112
} elseif (isset($_COOKIE['archive']) && isset($_COOKIE['archive_begin']) && isset($_COOKIE['archive_end']) && isset($_COOKIE['archive_speed'])) {
113
	$from_archive = true;
114
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
115
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
116
//	$begindate = filter_var($_COOKIE['archive_begin'],FILTER_SANITIZE_NUMBER_INT);
117
//	$enddate = filter_var($_COOKIE['archive_end'],FILTER_SANITIZE_NUMBER_INT);
118
	$begindate = $_COOKIE['archive_begin'];
119
	$enddate = $_COOKIE['archive_end'];
120
121
	$archivespeed = filter_var($_COOKIE['archive_speed'],FILTER_SANITIZE_NUMBER_INT);
122
	$begindate = date('Y-m-d H:i:s',$begindate);
123
	$enddate = date('Y-m-d H:i:s',$enddate);
124
//	echo 'Begin : '.$begindate.' - End : '.$enddate."\n";
125
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
126
} else {
127
	$spotter_array = $SpotterLive->getMinLastLiveSpotterData($filter);
128
}
129
130
if (!empty($spotter_array)) {
131
	if (isset($_GET['archive'])) {
132
		$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
133
	} else {
134
		$flightcnt = $SpotterLive->getLiveSpotterCount($filter);
135
	}
136
	if ($flightcnt == '') $flightcnt = 0;
137
} else $flightcnt = 0;
138
139
$sqltime = round(microtime(true)-$begintime,2);
140
$minitime = time();
141
$maxitime = 0;
142
143
144
$modelsdb = array();
145
if (file_exists('models/modelsdb')) {
146
	if (($handle = fopen('models/modelsdb','r')) !== FALSE) {
147
		while (($row = fgetcsv($handle,1000)) !== FALSE) {
148
			if (isset($row[1]) ){
149
				$model = $row[0];
150
				$modelsdb[$model] = $row[1];
151
			}
152
		}
153
		fclose($handle);
154
	}
155
}
156
$heightrelative = 'NONE';
157
$j = 0;
158
$prev_flightaware_id = '';
159
$speed = 1;
160
if (isset($archivespeed)) $speed = $archivespeed;
161
$output = '[';
162
$output .= '{"id" : "document", "name" : "fam","version" : "1.0"';
163
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "LOOP_STOP","step": "SYSTEM_CLOCK_MULTIPLIER"}';
164
165
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
166
//$output .= ',"clock": {"currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
167
if ($from_archive === true) {
168
	$output .= ',"clock": {"currentTime" : "%minitime%","multiplier" : '.$speed.',"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER","interval": "%minitime%/%maxitime%"}';
169
} else {
170
	$output .= ',"clock": {"currentTime" : "%minitime%","multiplier" : '.$speed.',"range" : "UNBOUNDED","step": "SYSTEM_CLOCK_MULTIPLIER"}';
171
}
172
173
//	$output .= ',"clock": {"interval" : "'.date("c",time()-$globalLiveInterval).'/'.date("c").'","currentTime" : "'.date("c",time() - $globalLiveInterval).'","multiplier" : 1,"step": "SYSTEM_CLOCK_MULTIPLIER"}';
174
$output .= '},';
175
if (!empty($spotter_array) && is_array($spotter_array))
176
{
177
	foreach($spotter_array as $spotter_item)
178
	{
179
		$j++;
180
		date_default_timezone_set('UTC');
181
		if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
182
		{
183
			$image = $spotter_item['image_thumbnail'];
184
		} else {
185
			$image = "images/placeholder_thumb.png";
186
		}
187
188
189
		if ($prev_flightaware_id != $spotter_item['flightaware_id']) {
190
			if ($prev_flightaware_id != '') {
191
				$output .= ']';
192
				$output .= '}';
193
				//$output .= ', '.$orientation.']}';
194
				$output .= '},';
195
			}
196
			$orientation = '';
197
			$prev_flightaware_id = $spotter_item['flightaware_id'];
198
			$output .= '{';
199
			$output .= '"id": "'.$spotter_item['flightaware_id'].'",';
200
			$output .= '"properties": {';
201
			// Not yet supported in CZML with Cesium
202
			$output .= '},';
203
204
			$output .= '"path" : { ';
205
			$output .= '"show" : false, ';
206
			$output .= '"material" : { ';
207
			$output .= '"polylineOutline" : { ';
208
			$output .= '"color" : { "rgba" : [238, 250, 255, 255] }, ';
209
			$output .= '"outlineColor" : { "rgba" : [200, 209, 214, 255] }, ';
210
			$output .= '"outlineWidth" : 5, ';
211
			$output .= '"polylineGlow" : { "color" : { "rgba" : [214, 208, 214, 255] }, "glowPower" : 3 } ';
212
			$output .= '}';
213
			$output .= '}, ';
214
			$output .= '"heightReference": "'.$heightrelative.'",';
215
			$output .= '"width" : 6, "leadTime" : 0, "trailTime" : 1000000, "resolution" : 10 },';
216
				
217
			//$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/T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y7kL1b3q4fzJQQGck5z6Nb97kxujblWf64HXov7Vl/E4YXWccP9AAd6dAx+ox/WTArNzY1t64B0f8K0DyLXuUvRGZfcpCo1VX4tg6wB76WMB0dALf526foAX8cqUot2pGP8B2Kz+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},';
218
			$aircraft_icao = $spotter_item['aircraft_icao'];
219
220
			if (isset($modelsdb[$aircraft_icao])) {
221
				$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_icao].'","scale" : 1.0,"minimumPixelSize": 20 ,';
222
				$output .= '"heightReference": "'.$heightrelative.'"},';
223
			} elseif ($aircraft_icao != '') {
224
				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_icao);
225
				if (count($aircraft_info) > 0) {
226
					$aircraft_shadow = $aircraft_info[0]['aircraft_shadow'];
227
					$spotter_item['engine_type'] = $aircraft_info[0]['engine_type'];
228
					$spotter_item['wake_category'] = $aircraft_info[0]['wake_category'];
229
					$spotter_item['engine_count'] = $aircraft_info[0]['engine_count'];
230
				} else $aircraft_shadow = '';
231
				if ($aircraft_shadow != '') {
232
					if (isset($modelsdb[$aircraft_shadow])) {
233
						$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_shadow].'","scale" : 1.0,"minimumPixelSize": 20 ,';
234
						$output .= '"heightReference": "'.$heightrelative.'"},';
235
						$modelsdb[$aircraft_icao] = $modelsdb[$aircraft_shadow];
236
					} elseif ($spotter_item['engine_type'] == 'Jet') {
237
						if ($spotter_item['engine_count'] == '1') {
238
							if ($spotter_item['wake_category'] == 'M') {
239
								$model = 'J1M';
240
							} elseif ($spotter_item['wake_category'] == 'L') {
241
								$model = '';
242
							}
243
						} elseif ($spotter_item['engine_count'] == '2') {
244
							if ($spotter_item['wake_category'] == 'M') {
245
								$model = 'J2M';
246
							} elseif ($spotter_item['wake_category'] == 'H') {
247
								$model = 'J2H';
248
							} elseif ($spotter_item['wake_category'] == 'L') {
249
								$model = 'J2L';
250
							}
251
						} elseif ($spotter_item['engine_count'] == '3') {
252
							if ($spotter_item['wake_category'] == 'M') {
253
								$model = 'J3M';
254
							} elseif ($spotter_item['wake_category'] == 'H') {
255
								$model = 'J3H';
256
							}
257
						} elseif ($spotter_item['engine_count'] == '4') {
258
							if ($spotter_item['wake_category'] == 'M') {
259
								$model = 'J4M';
260
							} elseif ($spotter_item['wake_category'] == 'H') {
261
								$model = 'J4H';
262
							}
263
						}
264
						if (isset($modelsdb[$model])) {
265
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20,';
266
							$output .= '"heightReference": "'.$heightrelative.'"},';
267
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
268
						} else {
269
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
270
							$output .= '"heightReference": "'.$heightrelative.'"},';
271
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
272
						}
273
					} elseif ($spotter_item['engine_type'] == 'Turboprop') {
274
						if ($spotter_item['engine_count'] == '1') {
275
							if ($spotter_item['wake_category'] == 'L') {
276
								$model = 'T1L';
277
							}
278
						} elseif ($spotter_item['engine_count'] == '2') {
279
							if ($spotter_item['wake_category'] == 'M') {
280
								$model = 'T2M';
281
							} elseif ($spotter_item['wake_category'] == 'L') {
282
								$model = 'T2L';
283
							}
284
						} elseif ($spotter_item['engine_count'] == '4') {
285
							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...
286
							} elseif ($spotter_item['wake_category'] == 'H') {
287
								$model = 'T4H';
288
							}
289
						}
290
						if (isset($modelsdb[$model])) {
291
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20 ,';
292
							$output .= '"heightReference": "'.$heightrelative.'"},';
293
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
294
						} else {
295
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20 ,';
296
							$output .= '"heightReference": "'.$heightrelative.'"},';
297
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
298
						}
299
					} elseif ($spotter_item['engine_type'] == 'Piston') {
300
						if ($spotter_item['engine_count'] == '1') {
301
							if ($spotter_item['wake_category'] == 'L') {
302
								$model = 'P1L';
303
							} elseif ($spotter_item['wake_category'] == 'M') {
304
								$model = 'P1M';
305
							}
306
						} elseif ($spotter_item['engine_count'] == '2') {
307
							if ($spotter_item['wake_category'] == 'M') {
308
								$model = 'P2M';
309
							} elseif ($spotter_item['wake_category'] == 'L') {
310
								$model = 'P2L';
311
							}
312
							// ju52 = P3M
313
						}
314
						if (isset($modelsdb[$model])) {
315
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$model].'","scale" : 1.0,"minimumPixelSize": 20 ,';
316
							$output .= '"heightReference": "'.$heightrelative.'"},';
317
							$modelsdb[$aircraft_icao] = $modelsdb[$model];
318
						} else {
319
							$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20 ,';
320
							$output .= '"heightReference": "'.$heightrelative.'"},';
321
							$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
322
						}
323
					} else {
324
						$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
325
						$output .= '"heightReference": "'.$heightrelative.'"},';
326
							//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
327
						if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
328
						$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
329
					}
330
				} elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') {
331
					$aircraft_shadow = 'PA18';
332
					$output .= '"model": {"gltf" : "'.$globalURL.'/models/'.$modelsdb[$aircraft_shadow].'","scale" : 1.0,"minimumPixelSize": 20 ,';
333
					$output .= '"heightReference": "'.$heightrelative.'"},';
334
					$modelsdb[$aircraft_icao] = $modelsdb[$aircraft_shadow];
335
				} else {
336
					$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
337
					$output .= '"heightReference": "'.$heightrelative.'"},';
338
					//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
339
					if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
340
					$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
341
				}
342
343
			} else {
344
				$output .= '"model": {"gltf" : "'.$globalURL.'/models/Cesium_Air.glb","scale" : 1.0,"minimumPixelSize": 20,';
345
				$output .= '"heightReference": "'.$heightrelative.'"},';
346
				//if ($spotter_item['aircraft_shadow'] != '') $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
347
				if ($spotter_item['aircraft_icao'] != '') $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
348
				$modelsdb[$aircraft_icao] = 'Cesium_Air.glb';
349
			}
350
	//		$output .= '"heightReference": "CLAMP_TO_GROUND",';
351
			$output .= '"heightReference": "'.$heightrelative.'",';
352
	//		$output .= '"heightReference": "NONE",';
353
			$output .= '"position": {';
354
			$output .= '"interpolationAlgorithm":"HERMITE","interpolationDegree":3,';
355
			$output .= '"type": "Point",';
356
	//		$output .= '"interpolationAlgorithm" : "LAGRANGE",';
357
	//		$output .= '"interpolationDegree" : 5,';
358
	//		$output .= '"epoch" : "'.date("c",strtotime($spotter_item['date'])).'", ';
359
			$output .= '"cartographicDegrees": [';
360
			if ($minitime > strtotime($spotter_item['date'])) $minitime = strtotime($spotter_item['date']);
361
			if ($maxitime < strtotime($spotter_item['date'])) $maxitime = strtotime($spotter_item['date']);
362
			$output .= '"'.date("c",strtotime($spotter_item['date'])).'", ';
363
			$output .= $spotter_item['longitude'].', ';
364
			$output .= $spotter_item['latitude'].', ';
365
			$prevlong = $spotter_item['longitude'];
366
			$prevlat = $spotter_item['latitude'];
367
			$output .= round($spotter_item['altitude']*30.48);
368
			$prevalt = round($spotter_item['altitude']*30.48);
369
			//$orientation = '"orientation" : { ';
370
			//$orientation .= '"unitQuaternion": [';
371
			//$quat = quaternionrotate(deg2rad($spotter_item['heading']),deg2rad(0),deg2rad(0));
372
			//$orientation .= '"'.date("c",strtotime($spotter_item['date'])).'",'.$quat['x'].','.$quat['y'].','.$quat['z'].','.$quat['w'];
373
		} else {
374
			$output .= ',"'.date("c",strtotime($spotter_item['date'])).'", ';
375
			if ($maxitime < strtotime($spotter_item['date'])) $maxitime = strtotime($spotter_item['date']);
376
			if ($spotter_item['ground_speed'] == 0) {
377
				$output .= $prevlong.', ';
378
				$output .= $prevlat.', ';
379
				$output .= $prevalt;
380
			} else {
381
				$output .= $spotter_item['longitude'].', ';
382
				$output .= $spotter_item['latitude'].', ';
383
				if ($spotter_item['altitude'] == '') {
384
					if ($prevalt != '') {
385
						$output .= $prevalt;
386
					} else {
387
						$output .= 0;
388
					}
389
				} else {
390
					$output .= round($spotter_item['altitude']*30.48);
391
				}
392
			}
393
			//$quat = quaternionrotate(deg2rad($spotter_item['heading']),deg2rad(0),deg2rad(0));
394
			//$orientation .= ',"'.date("c",strtotime($spotter_item['date'])).'",'.$quat['x'].','.$quat['y'].','.$quat['z'].','.$quat['w'];
395
		}
396
	}
397
	$output  = substr($output, 0, -1);
398
	$output .= ']}}';
399
} else {
400
	$output  = substr($output, 0, -1);
401
}
402
$output .= ']';
403
$output = str_replace('%minitime%',date("c",$minitime),$output);
404
$output = str_replace('%maxitime%',date("c",$maxitime),$output);
405
print $output;
406
?>
407