// Define our global variables var GoogleMap = null; var Planes = {}; var PlanesOnMap = 0; var PlanesOnTable = 0; var PlanesToReap = 0; var SelectedPlane = null; var iSortCol=-1; var bSortASC=true; var bDefaultSortASC=true; var iDefaultSortCol=3; // Get current map settings CenterLat = Number(localStorage['CenterLat']) || CONST_CENTERLAT; CenterLon = Number(localStorage['CenterLon']) || CONST_CENTERLON; ZoomLvl = Number(localStorage['ZoomLvl']) || CONST_ZOOMLVL; function fetchData() { $.getJSON('/dump1090/data.json', function(data) { PlanesOnMap = 0 // Loop through all the planes in the data packet for (var j=0; j < data.length; j++) { // Do we already have this plane object in Planes? // If not make it. if (Planes[data[j].hex]) { var plane = Planes[data[j].hex]; } else { var plane = jQuery.extend(true, {}, planeObject); } // Call the function update plane.funcUpdateData(data[j]); // Copy the plane into Planes Planes[plane.icao] = plane; } PlanesOnTable = data.length; /* For special squawk tests */ //Planes['867840'].squawk = '7700'; }); } // Initalizes the map and starts up our timers to call various functions function initialize() { // Make a list of all the available map IDs var mapTypeIds = []; for(var type in google.maps.MapTypeId) { mapTypeIds.push(google.maps.MapTypeId[type]); } // Push OSM on to the end mapTypeIds.push("OSM"); mapTypeIds.push("dark_map"); // Styled Map to outline airports and highways var styles = [ { "featureType": "administrative", "stylers": [ { "visibility": "off" } ] },{ "featureType": "landscape", "stylers": [ { "visibility": "off" } ] },{ "featureType": "poi", "stylers": [ { "visibility": "off" } ] },{ "featureType": "road", "stylers": [ { "visibility": "off" } ] },{ "featureType": "transit", "stylers": [ { "visibility": "off" } ] },{ "featureType": "landscape", "stylers": [ { "visibility": "on" }, { "weight": 8 }, { "color": "#000000" } ] },{ "featureType": "water", "stylers": [ { "lightness": -74 } ] },{ "featureType": "transit.station.airport", "stylers": [ { "visibility": "on" }, { "weight": 8 }, { "invert_lightness": true }, { "lightness": 27 } ] },{ "featureType": "road.highway", "stylers": [ { "visibility": "simplified" }, { "invert_lightness": true }, { "gamma": 0.3 } ] },{ "featureType": "road", "elementType": "labels", "stylers": [ { "visibility": "off" } ] } ] // Add our styled map var styledMap = new google.maps.StyledMapType(styles, {name: "Dark Map"}); // Define the Google Map var mapOptions = { center: new google.maps.LatLng(CenterLat, CenterLon), zoom: ZoomLvl, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControlOptions: { mapTypeIds: mapTypeIds, } }; GoogleMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); //Define OSM map type pointing at the OpenStreetMap tile server GoogleMap.mapTypes.set("OSM", new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; }, tileSize: new google.maps.Size(256, 256), name: "OpenStreetMap", maxZoom: 18 })); GoogleMap.mapTypes.set("dark_map", styledMap); // Add home marker if requested if (SiteShow && (typeof SiteLat !== 'undefined' || typeof SiteLon !== 'undefined')) { var siteMarker = new google.maps.LatLng(SiteLat, SiteLon); var markerImage = new google.maps.MarkerImage( 'http://maps.google.com/mapfiles/kml/pal4/icon57.png', new google.maps.Size(32, 32), // Image size new google.maps.Point(0, 0), // Origin point of image new google.maps.Point(16, 16)); // Position where marker should point var marker = new google.maps.Marker({ position: siteMarker, map: GoogleMap, icon: markerImage, title: 'My Radar Site' }); if (SiteCircles) { for (var i=0;i 300000) { // Reap it. delete Planes[reap]; } PlanesToReap++; } }; } // Refresh the detail window about the plane function refreshSelected() { var selected = false; if (typeof SelectedPlane !== 'undefined' && SelectedPlane != "ICAO" && SelectedPlane != null) { selected = Planes[SelectedPlane]; } var columns = 2; var html = ''; if (selected) { html += ''; } else { html += '
'; } // Flight header line including squawk if needed if (selected && selected.flight == "") { html += ''; if (selected) { if (Metric) { html += ''; } else { html += ''; } } else { html += ''; } if (selected && selected.squawk != '0000') { html += ''; } else { html += ''; } html += ''; if (selected) { html += ''; } else { html += ''; // Something is wrong if we are here } html += ''; html += ''; // Let's show some extra data if we have site coordinates if (SiteShow) { var siteLatLon = new google.maps.LatLng(SiteLat, SiteLon); var planeLatLon = new google.maps.LatLng(selected.latitude, selected.longitude); var dist = google.maps.geometry.spherical.computeDistanceBetween (siteLatLon, planeLatLon); if (Metric) { dist /= 1000; } else { dist /= 1852; } dist = (Math.round((dist)*10)/10).toFixed(1); html += ''; } // End of SiteShow } else { if (SiteShow) { html += ''; } else { html += 'n/a'; } } html += '
N/A (' + selected.icao + ')'; } else if (selected && selected.flight != "") { html += '
' + selected.flight + ''; } else { html += '
DUMP1090'; } if (selected && selected.squawk == 7500) { // Lets hope we never see this... Aircraft Hijacking html += '  Squawking: Aircraft Hijacking '; } else if (selected && selected.squawk == 7600) { // Radio Failure html += '  Squawking: Radio Failure '; } else if (selected && selected.squawk == 7700) { // General Emergency html += '  Squawking: General Emergency '; } else if (selected && selected.flight != '') { html += ' [FlightStats]'; } html += '
Altitude: ' + Math.round(selected.altitude / 3.2828) + ' m
Altitude: ' + selected.altitude + ' ft
Altitude: n/aSquawk: ' + selected.squawk + '
Squawk: n/a
Speed: ' if (selected) { if (Metric) { html += Math.round(selected.speed * 1.852) + ' km/h'; } else { html += selected.speed + ' kt'; } } else { html += 'n/a'; } html += 'ICAO (hex): ' + selected.icao + '
ICAO (hex): n/a
Track: ' if (selected && selected.vTrack) { html += selected.track + ' (' + normalizeTrack(selected.track, selected.vTrack)[1] +')'; } else { html += 'n/a'; } html += ' 
Lat/Long: '; if (selected && selected.vPosition) { html += selected.latitude + ', ' + selected.longitude + '
Distance from Site: ' + dist + (Metric ? ' km' : ' NM') + '
Distance from Site: n/a ' + (Metric ? ' km' : ' NM') + '
'; document.getElementById('plane_detail').innerHTML = html; } // Right now we have no means to validate the speed is good // Want to return (n/a) when we dont have it // TODO: Edit C code to add a valid speed flag // TODO: Edit js code to use said flag function normalizeSpeed(speed, valid) { return speed } // Returns back a long string, short string, and the track if we have a vaild track path function normalizeTrack(track, valid){ x = [] if ((track > -1) && (track < 22.5)) { x = ["North", "N", track] } if ((track > 22.5) && (track < 67.5)) { x = ["North East", "NE", track] } if ((track > 67.5) && (track < 112.5)) { x = ["East", "E", track] } if ((track > 112.5) && (track < 157.5)) { x = ["South East", "SE", track] } if ((track > 157.5) && (track < 202.5)) { x = ["South", "S", track] } if ((track > 202.5) && (track < 247.5)) { x = ["South West", "SW", track] } if ((track > 247.5) && (track < 292.5)) { x = ["West", "W", track] } if ((track > 292.5) && (track < 337.5)) { x = ["North West", "NW", track] } if ((track > 337.5) && (track < 361)) { x = ["North", "N", track] } if (!valid) { x = [" ", "n/a", ""] } return x } // Refeshes the larger table of all the planes function refreshTableInfo() { var html = ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; 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) { html += ''; } else { html += ''; } html += ''; html += ''; if (tableplane.squawk != '0000' ) { html += ''; } else { html += ''; } if (Metric) { html += ''; html += ''; } else { html += ''; html += ''; } html += ''; html += ''; html += ''; html += ''; } } html += '
ICAOFlightSquawkAltitudeSpeedTrackMsgsSeen
' + tableplane.icao + '' + tableplane.flight + '' + tableplane.squawk + ' ' + Math.round(tableplane.altitude / 3.2828) + '' + Math.round(tableplane.speed * 1.852) + '' + tableplane.altitude + '' + tableplane.speed + ''; if (tableplane.vTrack) { html += normalizeTrack(tableplane.track, tableplane.vTrack)[2]; html += ' (' + normalizeTrack(tableplane.track, tableplane.vTrack)[1] + ')'; } else { html += ' '; } html += '' + tableplane.messages + '' + tableplane.seen + '
'; document.getElementById('planes_table').innerHTML = html; // Click event for table $('#planes_table').find('tr').click( function(){ var hex = $(this).find('td:first').text(); if (hex != "ICAO") { selectPlaneByHex(hex); refreshTableInfo(); refreshSelected(); } }); 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 (typeof oTbl.rows[0] !== 'undefined' && 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 var bNumeric = false; if ((typeof oTbl.rows[0] !== 'undefined') && (!isNaN(parseFloat(oTbl.rows[0].cells[iSortCol].textContent || oTbl.rows[0].cells[iSortCol].innerText)))) { bNumeric = true; } //loop through the rows, storing each one inro aStore for (var i=0,iLen=oTbl.rows.length;i