1var screenAirportMain = { 2 pos: nil, 3 apt_coord: nil, 4 apt: nil, 5 searched: 0, 6 oaci: nil, 7 search: func { 8 me.apt = me.oaci != nil ? airportinfo(me.oaci) : airportinfo(); 9 if (me.apt != nil) { 10 #glide_slope_tunnel.complement_runways(me.apt); 11 return 1; 12 } 13 else 14 return 0; 15 }, 16 right : func { 17 }, 18 enter : func { #add to route 19 add_waypoint(me.apt.id, me.apt.name, "APT", 20 [me.apt_coord.lat(), me.apt_coord.lon(), 21 me.apt_coord.alt()*alt_conv[1][0]]); 22 }, 23 escape : func { 24 me.searched = 0; 25 me.oaci = nil; 26 }, 27 start : func { #add bookmark, enter turnpoint mode 28 add_bookmark(me.apt.id, me.apt.name, "APT", 29 [me.apt_coord.lat(), me.apt_coord.lon(), 30 me.apt_coord.alt()*alt_conv[1][0]]); 31 screenTurnpointSelect.selected = screenTurnpointSelect.n - 1; 32 screenTurnpointSelect.start(); 33 }, 34 lines : func { 35 if (me.search() == 1) { #FIXME: THE SEARCH SHOULD BE DONE ONLY ONE TIME, 36 # BUT IT SEEMS TO BE EXECUTED 3 TIMES/SEC 37 # I DON'T KNOW YET WHY... :/ 38 var rwy = glide_slope_tunnel.best_runway(me.apt); 39 me.pos = geo.Coord.new(geo.aircraft_position()); 40 me.apt_coord = geo.Coord.new().set_latlon(rwy.lat, rwy.lon); 41 var ac_to_apt = [me.pos.distance_to(me.apt_coord), me.pos.course_to(me.apt_coord)]; 42 var ete = ac_to_apt[0] / getprop("instrumentation/gps/indicated-ground-speed-kt") * 3600 * 1852; 43 display([ 44 sprintf("%s APT: %s", me.searched != 0 ? "SEARCHED" : "NEAREST", me.apt.id), 45 sprintf("ELEV: %d %s", me.apt.elevation * alt_conv[1][alt_unit],alt_unit_short_name[alt_unit]), 46 sprintf("DIST: %d %s",ac_to_apt[0] * dist_conv[2][dist_unit],dist_unit_short_name[dist_unit]), 47 sprintf("BRG: %d° RWY: %02d",ac_to_apt[1], int(rwy.heading) / 10), 48 sprintf("ETE: %s",seconds_to_string(ete)) 49 ]); 50 } 51 else 52 display([ 53 "", 54 " ! ERROR !", 55 "NO AIRPORT", 56 " FOUND", 57 "" 58 ]); 59 } 60}; 61 62var screenAirportInfos = { 63 page : 0, 64 rwylist: [], 65 right : func { 66 np = int(size(me.rwylist) / 4) + (math.mod(size(me.rwylist),4) ? 1 : 0); 67 me.page = cycle(np, me.page, arg[0]); 68 }, 69 enter : func { 70 }, 71 escape : func { 72 }, 73 start : func { 74 }, 75 lines : func { 76 me.rwylist = []; 77 foreach (var r; keys(screenAirportMain.apt.runways)) { 78 string.isdigit(r[0]) or continue; 79 var number = math.mod(num(substr(r, 0, 2)) + 18, 36); 80 var side = substr(r, 2, 1); 81 var comp = sprintf("%02d%s", number, side == "R" ? "L" : side == "L" ? "R" : side); 82 append(me.rwylist, [r, comp, 83 screenAirportMain.apt.runways[r].length, 84 screenAirportMain.apt.runways[r].width]); 85 } 86 line[0].setValue(sprintf("%s", screenAirportMain.apt.name)); #TODO check length to truncate if too long 87 rwyindex = me.page * 4; 88 for (var l = 1; l < LINES; l += 1) { 89 rwyindex += 1; 90 if (rwyindex < size(me.rwylist)) 91 line[l].setValue(sprintf("%s - %s [%dm / %dm]", 92 me.rwylist[rwyindex][0], 93 me.rwylist[rwyindex][1], 94 me.rwylist[rwyindex][2], 95 me.rwylist[rwyindex][3])); 96 else 97 line[l].setValue(""); 98 } 99 } 100}; 101 102var screenSearchAirport = { 103 right : func { 104 }, 105 enter : func { 106 }, 107 escape : func { 108 }, 109 start : func { 110 screenAirportMain.oaci = arg[0]; 111 var found = screenAirportMain.search(); 112 if (found != 0) { 113 screenAirportMain.searched = 1; 114 screenEdit.previous_page = 0; 115 return 1; 116 } 117 else 118 return 0; 119 }, 120 lines : func { 121 EditMode(4, "AIRPORT CODE", "SEARCH"); 122 } 123}; 124 125 126