cleaning up code and plane table

This commit is contained in:
Dynomity 2015-08-21 18:38:38 -06:00
parent 1babb5b55c
commit baddeb9034
3 changed files with 21 additions and 26 deletions

View file

@ -98,3 +98,6 @@ ShowClocks = true;
// Controls page title, righthand pane when nothing is selected // Controls page title, righthand pane when nothing is selected
PageName = "DUMP1090"; PageName = "DUMP1090";
// Path to country flags subfolder
flag_dir = "flags-tiny";

View file

@ -144,7 +144,7 @@
<tr class="infoblock_body"> <tr class="infoblock_body">
<td colspan=1>Position: <span id="selected_position">n/a</span></td> <td colspan=1>Position: <span id="selected_position">n/a</span></td>
<td>Country: <span id="selected_country">n/a</span></td> <td>Country: <span id="selected_flag">n/a</span><span id="selected_country">n/a</span></td>
</tr> </tr>
<tr class="infoblock_body"> <tr class="infoblock_body">
@ -156,6 +156,7 @@
<table id="tableinfo" width="100%"> <table id="tableinfo" width="100%">
<thead style="background-color: #BBBBBB; cursor: pointer;"> <thead style="background-color: #BBBBBB; cursor: pointer;">
<td id="icao" onclick="sortByICAO();">ICAO</td> <td id="icao" onclick="sortByICAO();">ICAO</td>
<td id="flag" align="center">Country</td>
<td id="flight" onclick="sortByFlight();">Flight</td> <td id="flight" onclick="sortByFlight();">Flight</td>
<td id="squawk" onclick="sortBySquawk();" align="right">Squawk</td> <td id="squawk" onclick="sortBySquawk();" align="right">Squawk</td>
<td id="altitude" onclick="sortByAltitude();" align="right">Altitude</td> <td id="altitude" onclick="sortByAltitude();" align="right">Altitude</td>
@ -168,6 +169,7 @@
<tbody> <tbody>
<tr id="plane_row_template" class="plane_table_row hidden"> <tr id="plane_row_template" class="plane_table_row hidden">
<td>ICAO</td> <td>ICAO</td>
<td align="center">COUNTRY</td>
<td>FLIGHT</td> <td>FLIGHT</td>
<td align="right">SQUAWK</td> <td align="right">SQUAWK</td>
<td align="right">ALTITUDE</td> <td align="right">ALTITUDE</td>

View file

@ -71,29 +71,25 @@ function processReceiverUpdate(data) {
plane.tr = PlaneRowTemplate.cloneNode(true); plane.tr = PlaneRowTemplate.cloneNode(true);
// Lookup ICAO country flag // Lookup ICAO country flag
var img = document.createElement('img');
var hexa = +("0x" + hex); var hexa = +("0x" + hex);
for (var i = 0; i < ICAO_Codes.length; i++) { for (var i = 0; i < ICAO_Codes.length; i++) {
if ( hexa >= ICAO_Codes[i].start && hexa <= ICAO_Codes[i].end) { if ( hexa >= ICAO_Codes[i].start && hexa <= ICAO_Codes[i].end) {
img.src = escapeHtml(ICAO_Codes[i].icon_fn);
img.style.margin = "1px 2px";
img.style.cssFloat = "right";
img.title = ICAO_Codes[i].Country;
plane.Country = ICAO_Codes[i].Country; plane.Country = ICAO_Codes[i].Country;
plane.Flag = img; plane.Flag = '<div><img src="' + flag_dir + '/' + ICAO_Codes[i].icon_fn + '" title="' + ICAO_Codes[i].Country + '\"></div>';
} }
} }
// end of flag lookup // end of flag lookup
if (hex[0] === '~') { if (hex[0] === '~') {
// Non-ICAO address // Non-ICAO address
plane.tr.cells[0].textContent = hex.substring(1); plane.tr.cells[0].textContent = hex.substring(1);
$(plane.tr).css('font-style', 'italic'); $(plane.tr).css('font-style', 'italic');
plane.tr.cells[1].textContent = ("");
} else { } else {
plane.tr.cells[0].textContent = hex; plane.tr.cells[0].textContent = (hex);
//append the flag plane.tr.cells[1].innerHTML = (plane.Flag);
plane.tr.cells[0].appendChild(plane.Flag);
} }
plane.tr.addEventListener('click', selectPlaneByHex.bind(undefined,hex,false)); plane.tr.addEventListener('click', selectPlaneByHex.bind(undefined,hex,false));
@ -680,14 +676,14 @@ function refreshTableInfo() {
} }
// ICAO doesn't change // ICAO doesn't change
tableplane.tr.cells[1].textContent = (tableplane.flight !== null ? tableplane.flight : ""); tableplane.tr.cells[2].textContent = (tableplane.flight !== null ? tableplane.flight : "");
tableplane.tr.cells[2].textContent = (tableplane.squawk !== null ? tableplane.squawk : ""); tableplane.tr.cells[3].textContent = (tableplane.squawk !== null ? tableplane.squawk : "");
tableplane.tr.cells[3].textContent = format_altitude_brief(tableplane.altitude, tableplane.vert_rate); tableplane.tr.cells[4].textContent = format_altitude_brief(tableplane.altitude, tableplane.vert_rate);
tableplane.tr.cells[4].textContent = format_speed_brief(tableplane.speed); tableplane.tr.cells[5].textContent = format_speed_brief(tableplane.speed);
tableplane.tr.cells[5].textContent = format_distance_brief(tableplane.sitedist); tableplane.tr.cells[6].textContent = format_distance_brief(tableplane.sitedist);
tableplane.tr.cells[6].textContent = format_track_brief(tableplane.track); tableplane.tr.cells[7].textContent = format_track_brief(tableplane.track);
tableplane.tr.cells[7].textContent = tableplane.messages; tableplane.tr.cells[8].textContent = tableplane.messages;
tableplane.tr.cells[8].textContent = tableplane.seen.toFixed(0); tableplane.tr.cells[9].textContent = tableplane.seen.toFixed(0);
tableplane.tr.className = classes; tableplane.tr.className = classes;
@ -866,9 +862,3 @@ function drawCircle(marker, distance) {
}); });
circle.bindTo('center', marker, 'position'); circle.bindTo('center', marker, 'position');
} }
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode('flags-tiny/' + str));
return div.innerHTML;
};