Merge pull request #456 from Struart88/patch-2
[FlightAirMap.git] / atc-geojson.php
blob06fc3459d0b335977fb0642fd0936c69cbde2eb1
1 <?php
2 require_once('require/class.Connection.php');
3 require_once('require/class.ATC.php');
5 if (isset($_GET['download']))
7 header('Content-disposition: attachment; filename="atc.geojson"');
9 header('Content-Type: text/javascript');
10 $ATC=new ATC();
11 if (isset($_GET['coord']))
13 //$coords = explode(',',$_GET['coord']);
14 $spotter_array = $ATC->getAll();
15 } else {
16 $spotter_array = $ATC->getAll();
19 $output = '{"type": "FeatureCollection","features": [';
20 if (!empty($spotter_array))
22 foreach($spotter_array as $spotter_item)
24 date_default_timezone_set('UTC');
25 //waypoint plotting
26 $output .= '{"type": "Feature",';
27 $output .= '"properties": {';
28 $output .= '"ref": "'.$spotter_item['atc_id'].'",';
29 $output .= '"ident": "'.$spotter_item['ident'].'",';
30 $output .= '"frequency": "'.$spotter_item['frequency'].'",';
31 $output .= '"atc_range": "0",';
32 $output .= '"ivao_id": "'.$spotter_item['ivao_id'].'",';
33 $output .= '"ivao_name": "'.$spotter_item['ivao_name'].'",';
34 $output .= '"info": "'.$spotter_item['info'].'",';
35 $output .= '"type": "'.$spotter_item['type'].'",';
36 if ($spotter_item['type'] == 'Delivery') {
37 $output .= '"icon": "images/atc_del.png"';
38 } else if ($spotter_item['type'] == 'Ground') {
39 $output .= '"icon": "images/atc_gnd.png"';
40 } else if ($spotter_item['type'] == 'Tower') {
41 $output .= '"icon": "images/atc_twr.png"';
42 } else if ($spotter_item['type'] == 'Approach') {
43 $output .= '"icon": "images/atc_app.png"';
44 } else if ($spotter_item['type'] == 'Departure') {
45 $output .= '"icon": "images/atc_dep.png"';
46 } else if ($spotter_item['type'] == 'Observer') {
47 $output .= '"icon": "images/atc.png"';
48 } else if ($spotter_item['type'] == 'Control Radar or Centre') {
49 $output .= '"icon": "images/atc_ctr.png"';
50 } else {
51 $output .= '"icon": "images/atc.png"';
53 $output .= '},';
54 $output .= '"geometry": {';
55 $output .= '"type": "Point",';
56 $output .= '"coordinates": [';
57 $output .= $spotter_item['longitude'].', '.$spotter_item['latitude'];
58 $output .= ']';
59 $output .= '}';
60 $output .= '},';
61 $radius = $spotter_item['atc_range']*100;
62 if ($radius > 0) {
63 $output .= '{"type": "Feature",';
64 $output .= '"properties": {';
65 $output .= '"ref": "'.$spotter_item['atc_id'].'",';
66 $output .= '"ident": "'.$spotter_item['ident'].'",';
67 $output .= '"frequency": "'.$spotter_item['frequency'].'",';
68 $output .= '"atc_range": "'.$radius.'",';
69 $output .= '"ivao_id": "'.$spotter_item['ivao_id'].'",';
70 $output .= '"ivao_name": "'.$spotter_item['ivao_name'].'",';
71 $output .= '"info": "'.$spotter_item['info'].'",';
72 $output .= '"type": "'.$spotter_item['type'].'",';
73 if ($spotter_item['type'] == 'Delivery') {
74 $output .= '"atccolor": "#781212"';
75 } else if ($spotter_item['type'] == 'Ground') {
76 $output .= '"atccolor": "#682213"';
77 } else if ($spotter_item['type'] == 'Tower') {
78 $output .= '"atccolor": "#583214"';
79 } else if ($spotter_item['type'] == 'Approach') {
80 $output .= '"atccolor": "#484215"';
81 } else if ($spotter_item['type'] == 'Departure') {
82 $output .= '"atccolor": "#385216"';
83 } else if ($spotter_item['type'] == 'Observer') {
84 $output .= '"atccolor": "#286217"';
85 } else if ($spotter_item['type'] == 'Control Radar or Centre') {
86 $output .= '"atccolor": "#187218"';
87 } else {
88 $output .= '"atccolor": "#888219"';
90 $output .= '},';
91 $output .= '"geometry": {';
92 $output .= '"type": "Point",';
93 $output .= '"coordinates": [';
94 $output .= $spotter_item['longitude'].', '.$spotter_item['latitude'];
95 $output .= ']';
96 $output .= '}';
97 $output .= '},';
100 $output = substr($output, 0, -1);
101 } else {
102 $output .= '[';
104 $output .= ']}';
106 print $output;