Adding country flags to DUMP1090-Mutability v1.14

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.

**For those running stock dump1090 here is another way to accomplish it

Open script.js with nano or another editor

Add the red part near the top of the file under**

// Define our global variables
var GoogleMap = null;
var Planes = {};
var PlanesOnMap = 0;
var PlanesOnTable = 0;
var PlanesToReap = 0;
var SelectedPlane = null;
var SpecialSquawk = false;
var GotCenter = false;

var iSortCol=-1;
var bSortASC=true;
var bDefaultSortASC=true;
var iDefaultSortCol=3;

// 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”]];

Make the following changes in red under the area in which they occur

    // Flight header line including squawk if needed
    if (selected && selected.flight == "") {
        html += '<tr><td colspan="' + columns + '" id="selectedinfotitle"><b>N/A (' +
            selected.icao + ')</b><img style="vertical-align:middle" src=' + icaoFlag(selected.icao) + '>';
    } else if (selected && selected.flight != "") {
        html += '<tr><td colspan="' + columns + '" id="selectedinfotitle"><b>' +
            selected.flight + '</b><img style="vertical-align:middle" src=' + icaoFlag(selected.icao) + '>';
    } else {
        html += '<tr><td colspan="' + columns + '" id="selectedinfotitle"><b>DUMP1090</b>';
    }

function refreshTableInfo() {
var html = ‘’;
for (var tablep in Planes) {
var tableplane = Planes[tablep]
if (!tableplane.reapable) {
var specialStyle = “”;
// Is this the plane we selected?
if (tableplane.icao == SelectedPlane) {
specialStyle += " selected";
}
// Lets hope we never see this… Aircraft Hijacking
if (tableplane.squawk == 7500) {
specialStyle += " squawk7500";
}
// Radio Failure
if (tableplane.squawk == 7600) {
specialStyle += " squawk7600";
}
// Emergancy
if (tableplane.squawk == 7700) {
specialStyle += " squawk7700";
}

                    if (tableplane.vPosition == true) {
                            if (tableplane.mlat == true) {
                                    html += '<tr onclick="planeTRclick(\''+tableplane.icao+'\')" class="plane_table_row mlat' + specialStyle + '">';
                            } else {
                                    html += '<tr onclick="planeTRclick(\''+tableplane.icao+'\')" class="plane_table_row vPosition' + specialStyle + '">';
                            }      
                    } else {
                            html += '<tr onclick="planeTRclick(\''+tableplane.icao+'\')" class="plane_table_row ' + specialStyle + '">';
                }

                    html += '<td>' + tableplane.icao + '<img style="height: 1.2em;float:right;" src=' + icaoFlag(tableplane.icao) + '></td>';
                    html += '<td>' + tableplane.flight + '</td>';

Put these functions at the bottom of the file like so

// Process the flag filename
function escapeHtml(str) {
var flag = null;
flag = ‘flags-tiny/’ + str + ‘.png’;
return flag;
};

// Find the flag
function icaoFlag(str) {
var icao_flag,icao_dec = null;
// Convert the hex to integer
icao_dec = parseInt(str,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]) {
icao_flag = Icao_Codes*[2];
}}
if (icao_flag == null) {
icao_flag = “error”;
}
return escapeHtml(icao_flag);
}; ***

// Bind grippie actions
$(function() {
var handleClick = function(e) {
e.preventDefault();
$(“#sidebar_container”).toggle();
$(“#map_canvas, #grippie”).toggleClass(“fullscreen”);
google.maps.event.trigger(GoogleMap, “resize”);
};

    $("#grippie").click(handleClick);    

});

Drop the image files under /usr/share/dump1090/public_html/flags-tiny/
You can adjust part highlighted under green to change the flag size in the table.

Tested at dump1090 by FR24 fork from Malcolm Robb’s branch. Working fine. Slightly increased CPU load.
Is it possible to increase the update interval of the data?

I like it. Very nice! :smiley:

Need a little refinement script to add validation for an indefinite ICAO. Now print broken image “undefined”

Good idea to add some validation for undefined ICAO addresses. I haven’t seen any yet in my tables but the flights I track only include a dozen countries at the most.

ICAO registration address ranges
libhomeradar.org/databaseque … ations.php
I found absent code for Yugoslavia aircraft “undefined”. Code added to script.

I’m bad at javascript and programming in general. Added a catch all check for stuff not in the array so dump1090 won’t crash anymore. Add an icon for error.png in the flags-tiny folder and replace the function with the one below. I also updated the code above for this check

// Find the flag
function icaoFlag(str) {
var icao_flag,icao_dec = null;
// Convert the hex to integer
icao_dec = parseInt(str,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]) {
icao_flag = Icao_Codes*[2];
}}
if (icao_flag == null) {
icao_flag = “error”;
}
return escapeHtml(icao_flag);
};***

Very nice modification. Thanks for sharing it, it looks good on my screen

– Allan

Dump1090 MalcolmRobb version with a piece of code “return escapeHtml(icao_flag)” the flags were not displayed at all. Returned as it was before - “return icao_flag;” Please check it.

I had some trouble finding the right flags. I could not find them at http://www.iconarchive.com. I have downloaded the Free Country Flags Pack 1 from http://www.free-country-flags.com. (12 x 20 pixels)

I have extracted it in /usr/share/dump1090-mutability/html/flags-tiny:


pi@ted1090-1 /usr/share/dump1090-mutability/html/flags-tiny $ ll
total 896
-rw-rw-r-- 1 pi pi 3096 Jan  9  2008 Afghanistan.png
-rw-rw-r-- 1 pi pi 3038 Jan  9  2008 Albania.png
-rw-rw-r-- 1 pi pi 3075 Jan  9  2008 Algeria.png
-rw-rw-r-- 1 pi pi 3312 Jan  9  2008 American_Samoa.png
-rw-rw-r-- 1 pi pi 3070 Jan  9  2008 Andorra.png
-rw-rw-r-- 1 pi pi 3049 Jan  9  2008 Angola.png
-rw-rw-r-- 1 pi pi 3300 Jan  9  2008 Anguilla.png
-rw-rw-r-- 1 pi pi 3261 Jan  9  2008 Antigua_and_Barbuda.png
-rw-rw-r-- 1 pi pi 2965 Jan  9  2008 Argentina.png
-rw-rw-r-- 1 pi pi 2908 Jan  9  2008 Armenia.png
-rw-rw-r-- 1 pi pi 2956 Jan  9  2008 Aruba.png
-rw-rw-r-- 1 pi pi 3378 Jan  9  2008 Australia.png
-rw-rw-r-- 1 pi pi 2835 Jan  9  2008 Austria.png
-rw-rw-r-- 1 pi pi 3042 Jan  9  2008 Azerbaijan.png
-rw-rw-r-- 1 pi pi 3018 Jan  9  2008 Bahamas.png
-rw-rw-r-- 1 pi pi 2924 Jan  9  2008 Bahrain.png
-rw-rw-r-- 1 pi pi 3076 Jan  9  2008 Bangladesh.png
etc......

This one seems to work okay.

I hope this helps others.

Here my result with the dump10980-Mutability v1.15 dev:
https://dl.dropboxusercontent.com/u/17865731/dump1090-mutability.20150816/flags.png

Thanks a lot DinoM!
Ted

Thank you DinoM and tedsluis.

I made some improvements to this code while integrating it into my fork.

github.com/toverfield/dump1090

Looks great… I was struggling with a few things which your update has solved!

It’s taken shape!

Thanks!

Added the code and the flags seems to increase every second.

http://vgy.me/kQGSEm.png

Using Dump1090-Mutability 1.15 Dev

I’ve made modifications for 1.15dev until it hopefully gets pulled into the master. Instead of listing the code here you can check out the files at
https://github.com/Dynomity/dump1090-mutability-1.15dev-flags

The only modified files are the config.js, script.js and gmap.html as well as the addition of flags.js and the ‘flags-tiny’ folder and its contents.

You may wish the compare the files and backup your existing files if you choose to replace them.

Hopefully this help…

Dino

Not working :frowning: .
I’ll just wait for the changes to be pulled into the master.

Cheers!

The mod has now been merged into the repository master branch for 1.15dev at
https://github.com/mutability/dump1090

Thanks, Oliver!

congratulations on your first official contribution! :wink:

Any idea when a v1.15 package will released for Raspberry Pi which includes this?

Could the code also be added to give MLAT aircraft a different outline to ADS-B ones?