var Map = null; var CenterLat = 45.0; var CenterLon = 9.0; var ZoomLvl = 5; var Planes = {}; var PlanesOnMap = 0; var PlanesOnGrid = 0; var Selected = null; var iSortCol=-1; var bSortASC=true; var bDefaultSortASC=true; var iDefaultSortCol=3; if (localStorage['CenterLat']) { CenterLat = Number(localStorage['CenterLat']); } if (localStorage['CenterLon']) { CenterLon = Number(localStorage['CenterLon']); } if (localStorage['ZoomLvl']) { ZoomLvl = Number(localStorage['ZoomLvl']); } function getIconForPlane(plane, deselect) { var selected = false; var track = 0; var r = 255, g = 255, b = 0; var maxalt = 40000; // Max altitude in the average case var invalt = 0; // If there is plane object if (plane) { invalt = maxalt-plane.altitude; if (Selected == plane.hex && !deselect) { selected = true; } track = plane.track; } if (invalt < 0) invalt = 0; b = parseInt(255/maxalt*invalt); return { strokeWeight: (selected ? 2 : 1), path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW, scale: 5, fillColor: 'rgb('+r+','+g+','+b+')', fillOpacity: 0.9, rotation: track }; } /* Gets hex code of selected plane as string or nothing. * * Select not valid ICAO24 (hex) address to clear selection. */ function selectPlane(selectedPlane) { if (selectedPlane.length) this.planehex = selectedPlane; // Deselect planes if (!Planes[this.planehex]) { if (Planes[Selected].marker) { Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected], true)); } Selected = null; refreshSelectedInfo(); refreshTableInfo(); return; } var old = Selected; Selected = this.planehex; if (Planes[old] && Planes[old].validposition) { // Remove the highlight in the previously selected plane. Planes[old].marker.setIcon(getIconForPlane(Planes[old])); } if (Planes[Selected].validposition) { Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected])); } refreshSelectedInfo(); refreshTableInfo(); } function refreshGeneralInfo() { var i = document.getElementById('geninfo'); i.innerHTML = PlanesOnMap + ' planes on the map. '; i.innerHTML += PlanesOnGrid + ' planes on the grid.'; } function refreshSelectedInfo() { var i = document.getElementById('selinfo'); var p = Planes[Selected]; // If no plane is selected if (!p) { p = {}; p.flight = ""; p.hex = ""; p.squawk = ""; p.altitude = "0"; p.speed = "0"; p.lat = "lat"; p.lon = "lon"; p.messages = "0"; p.seen = "0"; } var html = ''; if (p.flight != "") { html += ''; } else { html += ''; } html += ''; if (p.squawk != "0000") { html += ''; } else { html += ''; } html += ''; html += ''; if (p.validposition) { html += ''; } else { html += ''; } html += ''; html += ''; html += '
'+p.flight+'  '; html += '[FlightStats]
 
ICAO:'+p.hex+'
Squawk:'+p.squawk+'
Squawk:n/a
Altitude:'+p.altitude+' feet
Speed:'+p.speed+' knots
Coordinates:'+p.lat+', '+p.lon+'
Coordinates:n/a
Messages:'+p.messages+'
Seen:'+p.seen+' sec
'; i.innerHTML = html; } function refreshTableInfo() { var html = ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; for (var p in Planes) { var specialStyle = ""; if (p == Selected) { html += ''; } else { html += ''; } if (Planes[p].validposition) { specialStyle = 'bold'; } html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; } html += '
hexFlightSquawkAltitudeSpeedTrackMsgsSeen
' + Planes[p].hex + '' + Planes[p].flight + '' + Planes[p].squawk + '' + Planes[p].altitude + '' + Planes[p].speed + '' + Planes[p].track + '' + Planes[p].messages + '' + Planes[p].seen + '
'; document.getElementById('tabinfo').innerHTML = html; // Click event for table - lags sometimes for some reason? $('#tableinfo').find('tr').click( function(){ var hex = $(this).find('td:first').text(); selectPlane(hex); }); sortTable("tableinfo"); } // Credit goes to a co-worker that needed a similar functions for something else // we get a copy of it free ;) function setASC_DESC(iCol) { if(iSortCol==iCol) { bSortASC=!bSortASC; } else { bSortASC=bDefaultSortASC; } } function sortTable(szTableID,iCol) { //if iCol was not provided, and iSortCol is not set, assign default value if (typeof iCol==='undefined'){ if(iSortCol!=-1){ var iCol=iSortCol; } else { var iCol=iDefaultSortCol; } } //retrieve passed table element var oTbl=document.getElementById(szTableID).tBodies[0]; var aStore=[]; //If supplied col # is greater than the actual number of cols, set sel col = to last col if (oTbl.rows[0].cells.length<=iCol) iCol=(oTbl.rows[0].cells.length-1); //store the col # iSortCol=iCol; //determine if we are delaing with numerical, or alphanumeric content bNumeric=!isNaN(parseFloat(oTbl.rows[0].cells[iSortCol].textContent||oTbl.rows[0].cells[iSortCol].innerText))?true:false; //loop through the rows, storing each one inro aStore for (var i=0,iLen=oTbl.rows.length;i