Adding a few lines of code to the script.js file from dump1090-mutabilty version 1.14 on the Raspberry Pi will display the country flag of each aircraft based on the ICAO registration code.
I don’t profess to being a programmer so if you can improve on this or find there’s a better way of doing it, then please share.
Please back up your original script.js file before making any changes.
http://www.dmnet.ca/pix/flags.jpg
The script file can be downloaded here: https://github.com/Dynomity/dump1090-mutability-web-interface
You’ll need to download the country flags from somewhere. I think I got them from http://www.iconarchive.com/category/flag-icons.html Flag images are 12x20 pixels.
Add the following to the script.js file (additions in RED):
…
var NBSP=‘\u00a0’;
var DEGREES=‘\u00b0’
var UP_TRIANGLE=‘\u25b2’; // U+25B2 BLACK UP-POINTING TRIANGLE
var DOWN_TRIANGLE=‘\u25bc’; // U+25BC BLACK DOWN-POINTING TRIANGLE
// Declare ICAO registration address ranges in decimal and country
// install the flag images in flags-tiny subdirectory.
var Icao_Codes = [7340032,7344128,“Afghanistan”],[5246976,5248000,“Albania”],[655360,688128,“Algeria”],[589824,593920,“Angola”],[827392,828416,“Antigua_and_Barbuda”],[14680064,14942208,“Argentina”],[6291456,6292480,“Armenia”],[8126464,8388608,“Australia”],[4456448,4489216,“Austria”],[6293504,6294528,“Azerbaijan”],[688128,692224,“Bahamas”],[8994816,8998912,“Bahrain”],[7348224,7352320,“Bangladesh”],[696320,697344,“Barbados”],[5308416,5309440,“Belarus”],[4489216,4521984,“Belgium”],[700416,701440,“Belize”],[606208,607232,“Benin”],[4194432,4194751,“Bermuda”],[4341760,4342015,“Bermuda”],[6815744,6816768,“Bhutan”],[15286272,15290368,“Bolivia”],[5320704,5321728,“Bosnia”],[196608,197632,“Botswana”],[14942208,15204352,“Brazil”],[8998912,8999936,“Brunei”],[4521984,4554752,“Bulgaria”],[638976,643072,“Burkina_Faso”],[204800,208896,“Burundi”],[229376,233472,“CoÌ‚te_d’Ivoire”],[7397376,7401472,“Cambodia”],[212992,217088,“Cameroon”],[12582912,12845056,“Canada”],[614400,615424,“Cape_Verde”],[442368,446464,“Central_African_Republic”],[540672,544768,“Chad”],[15204352,15208448,“Chile”],[7864320,8126464,“China”],[704512,708608,“Colombia”],[217088,218112,“Comoros”],[221184,225280,“Democratic_Republic_of_the_Congo”],[9441280,9442304,“Cook_Islands”],[712704,716800,“Costa_Rica”],[5250048,5251072,“Croatia”],[720896,724992,“Cuba”],[5013504,5014528,“Cyprus”],[4816896,4849664,“Czech_Republic”],[7471104,7503872,“South_Korea”],[573440,577536,“Democratic_Republic_of_the_Congo”],[4554752,4587520,“Denmark”],[622592,623616,“Djibouti”],[802816,806912,“Dominican_Republic”],[15220736,15224832,“Ecuador”],[65536,98304,“Egypt”],[729088,733184,“El_Salvador”],[270336,274432,“Equatorial_Guinea”],[2105344,2106368,“Eritrea”],[5312512,5313536,“Estonia”],[262144,266240,“Ethiopia”],[13139968,13144064,“Fiji”],[4587520,4620288,“Finland”],[3670016,3932160,“France”],[253952,258048,“Gabon”],[630784,634880,“Gambia”],[5324800,5325824,“Georgia”],[3932160,4194304,“Germany”],[278528,282624,“Ghana”],[4620288,4653056,“Greece”],[835584,836608,“Grenada”],[737280,741376,“Guatemala”],[286720,290816,“Guinea”],[294912,295936,“Guinea_Bissau”],[745472,749568,“Guyana”],[753664,757760,“Haiti”],[761856,765952,“Honduras”],[4653056,4685824,“Hungary”],[15728640,15761408,“ICAO”],[15765504,15766528,“ICAO”],[5029888,5033984,“Iceland”],[8388608,8650752,“India”],[9043968,9076736,“Indonesia”],[7536640,7569408,“Iran”],[7503872,7536640,“Iraq”],[5021696,5025792,“Ireland”],[7569408,7602176,“Israel”],[3145728,3407872,“Italy”],[778240,782336,“Jamaica”],[8650752,8912896,“Japan”],[7602176,7634944,“Jordan”],[6828032,6829056,“Kazakhstan”],[311296,315392,“Kenya”],[13164544,13165568,“Kiribati”],[7364608,7368704,“Kuwait”],[6295552,6296576,“Kyrgyzstan”],[7372800,7376896,“Laos”],[5254144,5255168,“Latvia”],[7634944,7667712,“Lebanon”],[303104,304128,“Lesotho”],[327680,331776,“Liberia”],[98304,131072,“Libya”],[5258240,5259264,“Lithuania”],[5046272,5047296,“Luxembourg”],[344064,348160,“Madagascar”],[360448,364544,“Malawi”],[7667712,7700480,“Malaysia”],[368640,369664,“Maldives”],[376832,380928,“Mali”],[5054464,5055488,“Malta”],[9437184,9438208,“Marshall_Islands”],[385024,386048,“Mauritania”],[393216,394240,“Mauritius”],[851968,884736,“Mexico”],[6819840,6820864,“Micronesia”],[5062656,5063680,“Monaco”],[6823936,6824960,“Mongolia”],[5332992,5334016,“Serbia_and_Montenegro”],[131072,163840,“Morocco”],[24576,28672,“Mozambique”],[7356416,7360512,“Myanmar”],[2101248,2102272,“Namibia”],[13148160,13149184,“Nauru”],[7380992,7385088,“Nepal”],[4718592,4751360,“Netherlands”],[13107200,13139968,“New_Zealand”],[786432,790528,“Nicaragua”],[401408,405504,“Niger”],[409600,413696,“Nigeria”],[4685824,4718592,“Norway”],[7389184,7390208,“Oman”],[7733248,7766016,“Pakistan”],[6832128,6833152,“Palau”],[794624,798720,“Panama”],[9011200,9015296,“Papua_New_Guinea”],[15237120,15241216,“Paraguay”],[15253504,15257600,“Peru”],[7700480,7733248,“Philippines”],[4751360,4784128,“Poland”],[4784128,4816896,“Portugal”],[434176,435200,“Qatar”],[7438336,7471104,“South_Korea”],[5262336,5263360,“Moldova”],[4849664,4882432,“Romania”],[1048576,2097152,“Russian_Federation”],[450560,454656,“Rwanda”],[13156352,13157376,“Saint_Lucia”],[770048,771072,“Saint_Vicent_and_the_Grenadines”],[9445376,9446400,“Samoa”],[5242880,5243904,“San_Marino”],[7405568,7438336,“Saudi_Arabia”],[458752,462848,“Senegal”],[475136,476160,“Seychelles”],[483328,484352,“Sierra_Leone”],[7766016,7798784,“Singapore”],[5266432,5267456,“Slovakia”],[5270528,5271552,“Slovenia”],[491520,495616,“Somalia”],[32768,65536,“South_Africa”],[3407872,3670016,“Spain”],[7798784,7831552,“Sri_Lanka”],[507904,512000,“Sudan”],[819200,823296,“Suriname”],[499712,500736,“Swaziland”],[4882432,4915200,“Sweden”],[4915200,4947968,“Switzerland”],[7831552,7864320,“Syria”],[9015296,9016320,“Taiwan”],[5328896,5329920,“Tajikistan”],[8912896,8945664,“Thailand”],[557056,561152,“Togo”],[13160448,13161472,“Tonga”],[811008,815104,“Trinidad_and_Tobago”],[163840,196608,“Tunisia”],[4947968,4980736,“Turkey”],[6297600,6298624,“Turkmenistan”],[425984,430080,“Uganda”],[5275648,5308416,“Ukraine”],[9003008,9007104,“UAE”],[4194304,4456448,“United_Kingdom”],[10485760,11534336,“United_States_of_America”],[15269888,15273984,“Uruguay”],[5274624,5275648,“Uzbekistan”],[13172736,13173760,“Vanuatu”],[884736,917504,“Venezuela”],[8945664,8978432,“Vietnam”],[8978432,8982528,“Yemen”],[16384,17408,“Zimbabwe”]];
function processReceiverUpdate(data) {
// Loop through all the planes in the data packet
var now = data.now;
var acs = data.aircraft;
…
function processReceiverUpdate(data) {
// Loop through all the planes in the data packet
var now = data.now;
var acs = data.aircraft;
// Detect stats reset
if (MessageCountHistory.length > 0 && MessageCountHistory[MessageCountHistory.length-1].messages > data.messages) {
MessageCountHistory = {'time' : MessageCountHistory[MessageCountHistory.length-1].time,
'messages' : 0}];
}
// Note the message count in the history
MessageCountHistory.push({ 'time' : now, 'messages' : data.messages});
// .. and clean up any old values
if ((now - MessageCountHistory[0].time) > 30)
MessageCountHistory.shift();
for (var j=0; j < acs.length; j++) {
var ac = acs[j];
var hex = ac.hex;
var plane = null;
// Lookup ICAO country flag
var icao_dec = 0;
var img = document.createElement(‘img’);
var i;
// Convert the hex to integer
icao_dec = parseInt(hex,16);
// Look up the country of registration from icao address in array
for (i = 0; i < Icao_Codes.length; i++) {
if (icao_dec > Icao_Codes*[0] && icao_dec < Icao_Codes*[1]) {
img.src = escapeHtml(Icao_Codes*[2]);
img.title = Icao_Codes*[2].replace(/_/g, ' ');
img.style.margin = "1px 2px";
img.style.cssFloat = "right";
}
}
// Do we already have this plane object in Planes?
// If not make it.
if (Planes[hex]) {
plane = Planes[hex];
} else {
plane = new PlaneObject(hex);
plane.tr = PlaneRowTemplate.cloneNode(true);
if (hex[0] === '~') {
// Non-ICAO address
plane.tr.cells[0].textContent = hex.substring(1);
$(plane.tr).css('font-style', 'italic');
} else {
plane.tr.cells[0].textContent = hex;
}
plane.tr.addEventListener('click', selectPlaneByHex.bind(undefined,hex,false));
plane.tr.addEventListener('dblclick', selectPlaneByHex.bind(undefined,hex,true));
Planes[hex] = plane;
PlanesOrdered.push(plane);
//append the flag
plane.tr.cells[0].appendChild(img);
}
// Call the function update
plane.updateData(now, ac);
}
}
…
$('#selected_track').text(format_track_long(selected.track));
if (selected.seen <= 1) {
$('#selected_seen').text('now');
} else {
$('#selected_seen').text(selected.seen.toFixed(1) + 's');
}
// add the country and flag
var flagtag = document.createElement(‘img’);
var icao_dec, i = 0;
var CountryName = null;
// Convert the hex to integer
icao_dec = parseInt(selected.icao,16);
// Look up the country of registration from icao address in array
for (i = 0; i < Icao_Codes.length; i++) {
if (icao_dec > Icao_Codes*[0] && icao_dec < Icao_Codes*[1]) {
CountryName = Icao_Codes*[2];
CountryName = CountryName.replace(/_/g, ' ');
$('#selected_country').text(CountryName);
flagtag.src = escapeHtml(Icao_Codes*[2]);
flagtag.title = Icao_Codes*[2];
flagtag.style.margin = "0px 10px";
flagtag.style.cssFloat = "none";
}
}*****
document.getElementById('selected_icao').appendChild(flagtag);
if (selected.position === null) {
$('#selected_position').text('n/a');
$('#selected_follow').addClass('hidden');
} else {
if (selected.seen_pos > 1) {
$('#selected_position').text(format_latlng(selected.position) + " (" + selected.seen_pos.toFixed(1) + "s)");
} else {
$('#selected_position').text(format_latlng(selected.position));
}
$('#selected_follow').removeClass('hidden');
if (FollowSelected) {
$('#selected_follow').css('font-weight', 'bold');
GoogleMap.panTo(selected.position);
} else {
$('#selected_follow').css('font-weight', 'normal');
}
}
**…
**
append to the end of the file a new function:
// Process the flag filename
function escapeHtml(str) {
var div = document.createElement(‘div’);
div.appendChild(document.createTextNode(‘flags-tiny/’ + str + ‘.png’));
return div.innerHTML;
};
(Optional) In the gmap.html file, to display the country in the selected aircraft section add:
…
<tr class="infoblock_body">
<td colspan=1>Position: <span id="selected_position">n/a</span></td>
<td>ICAO: <span id="selected_country">n/a</span></td>
</tr>
Hopefully, I’ve captured all the modifications to recreate what I did. The other modifications to the dump1090 web interface you see above are out of scope for this post and are mostly localization modifications.