2013-05-09 20:57:33 +02:00
|
|
|
Map = null;
|
2013-05-09 16:59:26 +02:00
|
|
|
CenterLat = 45.0;
|
|
|
|
CenterLon = 9.0;
|
|
|
|
ZoomLvl = 5;
|
2013-05-09 20:57:33 +02:00
|
|
|
Planes = {};
|
|
|
|
PlanesOnMap = 0;
|
|
|
|
PlanesOnGrid = 0;
|
|
|
|
Selected = null;
|
2013-05-09 16:59:26 +02:00
|
|
|
|
|
|
|
if (localStorage['CenterLat']) { CenterLat = Number(localStorage['CenterLat']); }
|
|
|
|
if (localStorage['CenterLon']) { CenterLon = Number(localStorage['CenterLon']); }
|
|
|
|
if (localStorage['ZoomLvl']) { ZoomLvl = Number(localStorage['ZoomLvl']); }
|
|
|
|
|
2013-05-12 14:15:18 +02:00
|
|
|
function getIconForPlane(plane, deselect) {
|
|
|
|
var selected = false;
|
|
|
|
var track = 0;
|
2013-05-09 16:59:26 +02:00
|
|
|
var r = 255, g = 255, b = 0;
|
2013-05-09 20:57:33 +02:00
|
|
|
var maxalt = 40000; // Max altitude in the average case
|
2013-05-12 14:15:18 +02:00
|
|
|
var invalt = 0;
|
|
|
|
|
|
|
|
// If there is plane object
|
|
|
|
if (plane) {
|
|
|
|
invalt = maxalt-plane.altitude;
|
|
|
|
if (Selected == plane.hex && !deselect) {
|
|
|
|
selected = true;
|
|
|
|
}
|
|
|
|
track = plane.track;
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
if (invalt < 0) invalt = 0;
|
|
|
|
b = parseInt(255/maxalt*invalt);
|
2013-05-12 14:15:18 +02:00
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
return {
|
|
|
|
strokeWeight: (selected ? 2 : 1),
|
|
|
|
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
|
|
|
|
scale: 5,
|
|
|
|
fillColor: 'rgb('+r+','+g+','+b+')',
|
|
|
|
fillOpacity: 0.9,
|
2013-05-12 14:15:18 +02:00
|
|
|
rotation: track
|
2013-05-09 16:59:26 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-05-12 14:15:18 +02:00
|
|
|
/* Gets hex code of selected plane as string or nothing. *
|
|
|
|
* Select not valid ICAO24 (hex) address to clear selection. */
|
2013-05-11 16:04:23 +02:00
|
|
|
function selectPlane(selectedPlane) {
|
|
|
|
if (selectedPlane.length) this.planehex = selectedPlane;
|
2013-05-12 14:15:18 +02:00
|
|
|
|
2013-05-14 11:55:16 +02:00
|
|
|
// Deselect planes
|
2013-05-12 14:15:18 +02:00
|
|
|
if (!Planes[this.planehex]) {
|
2013-05-14 11:55:16 +02:00
|
|
|
if (Planes[Selected].marker) {
|
|
|
|
Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected], true));
|
|
|
|
}
|
2013-05-12 14:15:18 +02:00
|
|
|
Selected = null;
|
|
|
|
refreshSelectedInfo();
|
|
|
|
refreshTableInfo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
var old = Selected;
|
|
|
|
Selected = this.planehex;
|
2013-05-12 14:15:18 +02:00
|
|
|
|
2013-05-14 11:55:16 +02:00
|
|
|
if (Planes[old] && Planes[old].validposition) {
|
2013-05-12 14:15:18 +02:00
|
|
|
// Remove the highlight in the previously selected plane.
|
2013-05-09 16:59:26 +02:00
|
|
|
Planes[old].marker.setIcon(getIconForPlane(Planes[old]));
|
|
|
|
}
|
2013-05-14 11:55:16 +02:00
|
|
|
|
|
|
|
if (Planes[Selected].validposition) {
|
|
|
|
Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected]));
|
|
|
|
}
|
2013-05-11 16:04:23 +02:00
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
refreshSelectedInfo();
|
2013-05-11 16:04:23 +02:00
|
|
|
refreshTableInfo();
|
2013-05-09 16:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshGeneralInfo() {
|
|
|
|
var i = document.getElementById('geninfo');
|
2013-05-11 12:15:09 +02:00
|
|
|
|
2013-05-14 12:04:31 +02:00
|
|
|
i.innerHTML = PlanesOnMap + ' planes on map.<br>';
|
|
|
|
i.innerHTML += PlanesOnGrid + ' planes on grid.';
|
2013-05-09 16:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshSelectedInfo() {
|
|
|
|
var i = document.getElementById('selinfo');
|
|
|
|
var p = Planes[Selected];
|
2013-05-11 16:04:23 +02:00
|
|
|
|
2013-05-12 14:15:18 +02:00
|
|
|
// If no plane is selected
|
2013-05-11 16:04:23 +02:00
|
|
|
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";
|
2013-05-09 16:59:26 +02:00
|
|
|
}
|
2013-05-11 16:04:23 +02:00
|
|
|
|
|
|
|
var html = '<table id="selectedinfo">';
|
|
|
|
html += '<tr><td colspan=2><b>'+p.flight+' </b></td></tr>';
|
|
|
|
html += '<tr><td>ICAO:</td><td>'+p.hex+'</td></tr>';
|
2013-05-14 11:55:16 +02:00
|
|
|
if (p.squawk != "0000") {
|
|
|
|
html += '<tr><td>Squawk:</td><td>'+p.squawk+'</td></tr>';
|
|
|
|
} else {
|
|
|
|
html += '<tr><td>Squawk:</td><td>n/a</td></tr>';
|
|
|
|
}
|
2013-05-11 16:04:23 +02:00
|
|
|
html += '<tr><td>Altitude:</td><td>'+p.altitude+' feet</td></tr>';
|
|
|
|
html += '<tr><td>Speed:</td><td>'+p.speed+' knots</td></tr>';
|
2013-05-14 11:55:16 +02:00
|
|
|
if (p.validposition) {
|
|
|
|
html += '<tr><td>Coordinates:</td><td>'+p.lat+', '+p.lon+'</td></tr>';
|
|
|
|
} else {
|
|
|
|
html += '<tr><td>Coordinates:</td><td>n/a</td></tr>';
|
|
|
|
}
|
2013-05-11 16:04:23 +02:00
|
|
|
html += '<tr><td>Messages:</td><td>'+p.messages+'</td></tr>';
|
|
|
|
html += '<tr><td>Seen:</td><td>'+p.seen+' sec</td></tr>';
|
|
|
|
html += '</table>';
|
2013-05-09 16:59:26 +02:00
|
|
|
i.innerHTML = html;
|
|
|
|
}
|
|
|
|
|
2013-05-11 12:15:09 +02:00
|
|
|
function refreshTableInfo() {
|
|
|
|
var html = '<table id="tableinfo" width="100%">';
|
2013-05-11 16:04:23 +02:00
|
|
|
html += '<thead style="background-color: #CCCCCC;">';
|
2013-05-12 14:15:18 +02:00
|
|
|
html += '<td>hex</td><td>Flight</td><td align="right">Squawk</td><td align="right">Altitude</td>';
|
|
|
|
html += '<td align="right">Speed</td><td align="right">Track</td>';
|
|
|
|
html += '<td align="right">Msgs</td><td align="right">Seen</td></thead>';
|
2013-05-11 12:15:09 +02:00
|
|
|
for (var p in Planes) {
|
2013-05-14 11:55:16 +02:00
|
|
|
var specialStyle = "";
|
2013-05-11 12:15:09 +02:00
|
|
|
if (p == Selected) {
|
2013-05-12 14:15:18 +02:00
|
|
|
html += '<tr id="tableinforow" style="background-color: #E0E0E0;">';
|
2013-05-11 12:15:09 +02:00
|
|
|
} else {
|
2013-05-12 14:15:18 +02:00
|
|
|
html += '<tr id="tableinforow">';
|
2013-05-11 12:15:09 +02:00
|
|
|
}
|
2013-05-14 11:55:16 +02:00
|
|
|
if (Planes[p].validposition) {
|
|
|
|
specialStyle = 'bold';
|
|
|
|
}
|
|
|
|
html += '<td class="' + specialStyle + '">' + Planes[p].hex + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '">' + Planes[p].flight + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].squawk + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].altitude + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].speed + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].track + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].messages + '</td>';
|
|
|
|
html += '<td class="' + specialStyle + '" align="right">' + Planes[p].seen + '</td>';
|
2013-05-11 12:15:09 +02:00
|
|
|
html += '</tr>';
|
|
|
|
}
|
|
|
|
html += '</table>';
|
2013-05-12 14:15:18 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2013-05-11 12:15:09 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
function fetchData() {
|
2013-05-14 11:55:16 +02:00
|
|
|
$.getJSON('data.json', function(data) {
|
|
|
|
// Planes that are still with us, and set map count to 0
|
|
|
|
var stillhere = {}
|
|
|
|
PlanesOnMap = 0;
|
2013-05-09 16:59:26 +02:00
|
|
|
|
2013-05-14 11:55:16 +02:00
|
|
|
// Loop through all the planes in the data packet
|
|
|
|
for (var j=0; j < data.length; j++) {
|
|
|
|
|
|
|
|
// Set plane to be this particular plane in the data set
|
|
|
|
var plane = data[j];
|
|
|
|
// Add to the still here list
|
|
|
|
stillhere[plane.hex] = true;
|
|
|
|
plane.flight = $.trim(plane.flight);
|
|
|
|
|
|
|
|
// Set the marker to null, for now
|
|
|
|
var marker = null;
|
|
|
|
|
|
|
|
// Either update the data or add it
|
|
|
|
if (Planes[plane.hex]) {
|
|
|
|
// Declare our plane that we are working with from our old data set
|
|
|
|
var myplane = Planes[plane.hex];
|
|
|
|
|
2013-05-14 12:04:31 +02:00
|
|
|
// If the has valid position, we should make a marker for it
|
|
|
|
if (plane.validposition) {
|
2013-05-14 11:55:16 +02:00
|
|
|
if (myplane.marker != null) {
|
|
|
|
marker = myplane.marker;
|
|
|
|
var icon = marker.getIcon();
|
|
|
|
var newpos = new google.maps.LatLng(plane.lat, plane.lon);
|
|
|
|
marker.setPosition(newpos);
|
|
|
|
marker.setIcon(getIconForPlane(plane));
|
|
|
|
PlanesOnMap++;
|
|
|
|
} else {
|
|
|
|
// Add new plane to map, dont ask me why this is needed here now...
|
|
|
|
marker = new google.maps.Marker({
|
|
|
|
position: new google.maps.LatLng(plane.lat, plane.lon),
|
|
|
|
map: Map,
|
|
|
|
icon: getIconForPlane(plane)
|
|
|
|
});
|
|
|
|
myplane.marker = marker;
|
|
|
|
marker.planehex = plane.hex;
|
|
|
|
PlanesOnMap++;
|
|
|
|
|
|
|
|
// Trap clicks for this marker.
|
|
|
|
google.maps.event.addListener(marker, 'click', selectPlane);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all the other information
|
|
|
|
myplane.altitude = plane.altitude;
|
|
|
|
myplane.speed = plane.speed;
|
|
|
|
myplane.lat = plane.lat;
|
|
|
|
myplane.lon = plane.lon;
|
|
|
|
myplane.track = plane.track;
|
|
|
|
myplane.flight = plane.flight;
|
|
|
|
myplane.seen = plane.seen;
|
|
|
|
myplane.messages = plane.messages;
|
|
|
|
myplane.squawk = plane.squawk;
|
|
|
|
myplane.validposition = plane.validposition;
|
|
|
|
myplane.validtrack = plane.validtrack;
|
|
|
|
|
|
|
|
// If this is a selected plane, refresh its data outside of the table
|
|
|
|
if (myplane.hex == Selected)
|
|
|
|
refreshSelectedInfo();
|
|
|
|
} else {
|
|
|
|
// This is a new plane
|
|
|
|
// Do we have a lat/long that is not 0?
|
2013-05-14 12:04:31 +02:00
|
|
|
if (plane.validposition) {
|
2013-05-14 11:55:16 +02:00
|
|
|
// Add new plane to map
|
|
|
|
marker = new google.maps.Marker({
|
|
|
|
position: new google.maps.LatLng(plane.lat, plane.lon),
|
|
|
|
map: Map,
|
|
|
|
icon: getIconForPlane(plane)
|
|
|
|
});
|
|
|
|
plane.marker = marker;
|
|
|
|
marker.planehex = plane.hex;
|
|
|
|
PlanesOnMap++;
|
|
|
|
|
|
|
|
// Trap clicks for this marker.
|
|
|
|
google.maps.event.addListener(marker, 'click', selectPlane);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the plane into Planes
|
|
|
|
Planes[plane.hex] = plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have lat/long, we must have a marker, so lets set the marker title
|
2013-05-14 12:04:31 +02:00
|
|
|
if (plane.validposition) {
|
2013-05-14 11:55:16 +02:00
|
|
|
if (plane.flight.length == 0) {
|
|
|
|
marker.setTitle(plane.hex)
|
|
|
|
} else {
|
|
|
|
marker.setTitle(plane.flight+' ('+plane.hex+')')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// How many planes have we heard from?
|
|
|
|
PlanesOnGrid = data.length;
|
|
|
|
|
|
|
|
/* Remove idle planes. */
|
|
|
|
for (var p in Planes) {
|
|
|
|
if (!stillhere[p]) {
|
|
|
|
if (Planes[p].marker != null)
|
|
|
|
Planes[p].marker.setMap(null);
|
|
|
|
delete Planes[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshTableInfo();
|
|
|
|
refreshSelectedInfo();
|
|
|
|
});
|
2013-05-09 16:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkTime(i) {
|
|
|
|
if (i < 10) {
|
|
|
|
return "0" + i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
function printTime() {
|
|
|
|
var currentTime = new Date();
|
|
|
|
var hours = checkTime(currentTime.getUTCHours());
|
|
|
|
var minutes = checkTime(currentTime.getUTCMinutes());
|
|
|
|
var seconds = checkTime(currentTime.getUTCSeconds());
|
|
|
|
|
|
|
|
if (document.getElementById) {
|
|
|
|
document.getElementById('utcTime').innerHTML =
|
|
|
|
hours + ":" + minutes + ":" + seconds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-14 11:55:16 +02:00
|
|
|
function placeFooter() {
|
|
|
|
var windHeight = $(window).height();
|
|
|
|
var footerHeight = $('#info_footer').height();
|
|
|
|
var offset = parseInt(windHeight) - parseInt(footerHeight);
|
|
|
|
|
|
|
|
var footerWidth = parseInt($('#info_footer').width());
|
|
|
|
var infoWidth = parseInt($('#info').width());
|
|
|
|
var marginLeft = parseInt((infoWidth / 2) - (footerWidth / 2));
|
|
|
|
|
|
|
|
$('#info_footer').css('top', offset);
|
|
|
|
$('#info_footer').css('margin-left', marginLeft);
|
|
|
|
}
|
|
|
|
|
2013-05-09 20:57:33 +02:00
|
|
|
function resetMap() {
|
|
|
|
localStorage['CenterLat'] = 45.0;
|
|
|
|
localStorage['CenterLon'] = 9.0;
|
|
|
|
localStorage['ZoomLvl'] = 5;
|
|
|
|
Map.setZoom(parseInt(localStorage['ZoomLvl']));
|
|
|
|
Map.setCenter(new google.maps.LatLng(parseInt(localStorage['CenterLat']), parseInt(localStorage['CenterLon'])));
|
|
|
|
Selected = null;
|
2013-05-14 11:55:16 +02:00
|
|
|
refreshSelectedInfo();
|
2013-05-11 16:04:23 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
function initialize() {
|
2013-05-11 12:15:09 +02:00
|
|
|
var mapTypeIds = [];
|
|
|
|
for(var type in google.maps.MapTypeId) {
|
|
|
|
mapTypeIds.push(google.maps.MapTypeId[type]);
|
|
|
|
}
|
|
|
|
mapTypeIds.push("OSM");
|
|
|
|
|
2013-05-09 16:59:26 +02:00
|
|
|
var mapOptions = {
|
|
|
|
center: new google.maps.LatLng(CenterLat, CenterLon),
|
|
|
|
zoom: ZoomLvl,
|
2013-05-11 12:15:09 +02:00
|
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
|
|
mapTypeControlOptions: {
|
|
|
|
mapTypeIds: mapTypeIds,
|
|
|
|
}
|
2013-05-09 16:59:26 +02:00
|
|
|
};
|
|
|
|
Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
2013-05-11 12:15:09 +02:00
|
|
|
|
|
|
|
//Define OSM map type pointing at the OpenStreetMap tile server
|
|
|
|
Map.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
|
|
|
|
}));
|
2013-05-09 16:59:26 +02:00
|
|
|
|
2013-05-14 11:55:16 +02:00
|
|
|
// show footer at info-area
|
|
|
|
$(function(){
|
|
|
|
$(window).resize(function(e){
|
|
|
|
placeFooter();
|
|
|
|
});
|
|
|
|
placeFooter();
|
|
|
|
// hide it before it's positioned
|
|
|
|
$('#info_footer').css('display','inline');
|
2013-05-09 16:59:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Listener for newly created Map
|
|
|
|
google.maps.event.addListener(Map, 'center_changed', function() {
|
|
|
|
localStorage['CenterLat'] = Map.getCenter().lat();
|
|
|
|
localStorage['CenterLon'] = Map.getCenter().lng();
|
|
|
|
});
|
|
|
|
|
|
|
|
google.maps.event.addListener(Map, 'zoom_changed', function() {
|
|
|
|
localStorage['ZoomLvl'] = Map.getZoom();
|
|
|
|
});
|
2013-05-11 16:04:23 +02:00
|
|
|
|
|
|
|
google.maps.event.addListener(Map, 'click', function() {
|
2013-05-12 14:15:18 +02:00
|
|
|
if (Selected) {
|
|
|
|
selectPlane("xyzxyz"); // Select not valid ICAO24 (hex) address to clear selection.
|
|
|
|
}
|
2013-05-11 16:04:23 +02:00
|
|
|
Selected = null;
|
|
|
|
refreshSelectedInfo();
|
|
|
|
refreshTableInfo();
|
|
|
|
});
|
2013-05-09 16:59:26 +02:00
|
|
|
|
|
|
|
// Setup our timer to poll from the server.
|
|
|
|
window.setInterval(function() {
|
|
|
|
fetchData();
|
|
|
|
refreshGeneralInfo();
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
// Faster timer, smoother things
|
|
|
|
window.setInterval(function() {
|
|
|
|
printTime();
|
|
|
|
}, 250);
|
2013-05-11 16:04:23 +02:00
|
|
|
|
|
|
|
refreshGeneralInfo();
|
|
|
|
refreshSelectedInfo();
|
2013-05-12 14:15:18 +02:00
|
|
|
refreshTableInfo();
|
2013-05-09 16:59:26 +02:00
|
|
|
}
|