Added resetMap()-function to web-view.
+ some small tweaks. modified: dump1090.c modified: public_html/script.js
This commit is contained in:
parent
6968bf92a6
commit
c5fdde64e4
|
@ -3051,6 +3051,7 @@ int decodeHexMessage(struct client *c) {
|
||||||
|
|
||||||
/* Return a description of planes in json. */
|
/* Return a description of planes in json. */
|
||||||
char *aircraftsToJson(int *len) {
|
char *aircraftsToJson(int *len) {
|
||||||
|
time_t now = time(NULL);
|
||||||
struct aircraft *a = Modes.aircrafts;
|
struct aircraft *a = Modes.aircrafts;
|
||||||
int buflen = 1024; /* The initial buffer is incremented as needed. */
|
int buflen = 1024; /* The initial buffer is incremented as needed. */
|
||||||
char *buf = (char *) malloc(buflen), *p = buf;
|
char *buf = (char *) malloc(buflen), *p = buf;
|
||||||
|
@ -3070,9 +3071,9 @@ char *aircraftsToJson(int *len) {
|
||||||
l = snprintf(p,buflen,
|
l = snprintf(p,buflen,
|
||||||
"{\"hex\":\"%06x\", \"squawk\":\"%04x\", \"flight\":\"%s\", \"lat\":%f, "
|
"{\"hex\":\"%06x\", \"squawk\":\"%04x\", \"flight\":\"%s\", \"lat\":%f, "
|
||||||
"\"lon\":%f, \"altitude\":%d, \"track\":%d, "
|
"\"lon\":%f, \"altitude\":%d, \"track\":%d, "
|
||||||
"\"speed\":%d},\n",
|
"\"speed\":%d, \"messages\":%ld, \"seen\":%d},\n",
|
||||||
a->addr, a->modeA, a->flight, a->lat, a->lon, a->altitude, a->track,
|
a->addr, a->modeA, a->flight, a->lat, a->lon, a->altitude, a->track,
|
||||||
a->speed);
|
a->speed, a->messages, (int)(now - a->seen));
|
||||||
p += l; buflen -= l;
|
p += l; buflen -= l;
|
||||||
|
|
||||||
/* Resize if needed. */
|
/* Resize if needed. */
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
Map = null;
|
Map = null;
|
||||||
CenterLat = 45.0;
|
CenterLat = 45.0;
|
||||||
CenterLon = 9.0;
|
CenterLon = 9.0;
|
||||||
ZoomLvl = 5;
|
ZoomLvl = 5;
|
||||||
Planes={};
|
Planes = {};
|
||||||
NumPlanes = 0;
|
PlanesOnMap = 0;
|
||||||
Selected=null
|
PlanesOnGrid = 0;
|
||||||
|
Selected = null;
|
||||||
|
|
||||||
if (localStorage['CenterLat']) { CenterLat = Number(localStorage['CenterLat']); }
|
if (localStorage['CenterLat']) { CenterLat = Number(localStorage['CenterLat']); }
|
||||||
if (localStorage['CenterLon']) { CenterLon = Number(localStorage['CenterLon']); }
|
if (localStorage['CenterLon']) { CenterLon = Number(localStorage['CenterLon']); }
|
||||||
|
@ -12,7 +13,7 @@ if (localStorage['ZoomLvl']) { ZoomLvl = Number(localStorage['ZoomLvl']); }
|
||||||
|
|
||||||
function getIconForPlane(plane) {
|
function getIconForPlane(plane) {
|
||||||
var r = 255, g = 255, b = 0;
|
var r = 255, g = 255, b = 0;
|
||||||
var maxalt = 40000; /* Max altitude in the average case */
|
var maxalt = 40000; // Max altitude in the average case
|
||||||
var invalt = maxalt-plane.altitude;
|
var invalt = maxalt-plane.altitude;
|
||||||
var selected = (Selected == plane.hex);
|
var selected = (Selected == plane.hex);
|
||||||
|
|
||||||
|
@ -42,8 +43,9 @@ function selectPlane() {
|
||||||
|
|
||||||
function refreshGeneralInfo() {
|
function refreshGeneralInfo() {
|
||||||
var i = document.getElementById('geninfo');
|
var i = document.getElementById('geninfo');
|
||||||
|
|
||||||
i.innerHTML = NumPlanes+' planes on screen.';
|
i.innerHTML = PlanesOnGrid + ' planes on grid.<br>';
|
||||||
|
i.innerHTML += PlanesOnMap + ' planes on map.';
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshSelectedInfo() {
|
function refreshSelectedInfo() {
|
||||||
|
@ -58,53 +60,69 @@ function refreshSelectedInfo() {
|
||||||
html += 'Altitude: '+p.altitude+' feet<br>';
|
html += 'Altitude: '+p.altitude+' feet<br>';
|
||||||
html += 'Speed: '+p.speed+' knots<br>';
|
html += 'Speed: '+p.speed+' knots<br>';
|
||||||
html += 'Coordinates: '+p.lat+', '+p.lon+'<br>';
|
html += 'Coordinates: '+p.lat+', '+p.lon+'<br>';
|
||||||
|
html += 'Messages: '+p.messages+'<br>';
|
||||||
|
html += 'Seen: '+p.seen+' sec<br>';
|
||||||
i.innerHTML = html;
|
i.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchData() {
|
function fetchData() {
|
||||||
$.getJSON('/data.json', function(data) {
|
$.getJSON('/data.json', function(data) {
|
||||||
var stillhere = {}
|
var stillhere = {}
|
||||||
|
PlanesOnMap = 0;
|
||||||
|
|
||||||
for (var j=0; j < data.length; j++) {
|
for (var j=0; j < data.length; j++) {
|
||||||
var plane = data[j];
|
var plane = data[j];
|
||||||
var marker = null;
|
|
||||||
stillhere[plane.hex] = true;
|
stillhere[plane.hex] = true;
|
||||||
plane.flight = $.trim(plane.flight);
|
plane.flight = $.trim(plane.flight);
|
||||||
|
|
||||||
|
if (plane.lat != 0 && plane.lon != 0) {
|
||||||
|
// Show only planes with position
|
||||||
|
var marker = null;
|
||||||
|
PlanesOnMap++;
|
||||||
|
|
||||||
|
if (Planes[plane.hex]) {
|
||||||
|
// Move and refresh old plane on map
|
||||||
|
var myplane = Planes[plane.hex];
|
||||||
|
marker = myplane.marker;
|
||||||
|
var icon = marker.getIcon();
|
||||||
|
var newpos = new google.maps.LatLng(plane.lat, plane.lon);
|
||||||
|
marker.setPosition(newpos);
|
||||||
|
marker.setIcon(getIconForPlane(plane));
|
||||||
|
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;
|
||||||
|
if (myplane.hex == Selected)
|
||||||
|
refreshSelectedInfo();
|
||||||
|
} else {
|
||||||
|
// 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;
|
||||||
|
Planes[plane.hex] = plane;
|
||||||
|
|
||||||
if (Planes[plane.hex]) {
|
// Trap clicks for this marker.
|
||||||
var myplane = Planes[plane.hex];
|
google.maps.event.addListener(marker, 'click', selectPlane);
|
||||||
marker = myplane.marker;
|
}
|
||||||
var icon = marker.getIcon();
|
|
||||||
var newpos = new google.maps.LatLng(plane.lat, plane.lon);
|
if (plane.flight.length == 0) {
|
||||||
marker.setPosition(newpos);
|
marker.setTitle(plane.hex)
|
||||||
marker.setIcon(getIconForPlane(plane));
|
} else {
|
||||||
myplane.altitude = plane.altitude;
|
marker.setTitle(plane.flight+' ('+plane.hex+')')
|
||||||
myplane.speed = plane.speed;
|
}
|
||||||
myplane.lat = plane.lat;
|
|
||||||
myplane.lon = plane.lon;
|
|
||||||
myplane.track = plane.track;
|
|
||||||
myplane.flight = plane.flight;
|
|
||||||
if (myplane.hex == Selected)
|
|
||||||
refreshSelectedInfo();
|
|
||||||
} else {
|
|
||||||
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;
|
|
||||||
Planes[plane.hex] = plane;
|
|
||||||
|
|
||||||
/* Trap clicks for this marker. */
|
|
||||||
google.maps.event.addListener(marker, 'click', selectPlane);
|
|
||||||
}
|
}
|
||||||
if (plane.flight.length == 0)
|
|
||||||
marker.setTitle(plane.hex)
|
|
||||||
else
|
|
||||||
marker.setTitle(plane.flight+' ('+plane.hex+')')
|
|
||||||
}
|
}
|
||||||
NumPlanes = data.length;
|
|
||||||
|
|
||||||
|
PlanesOnGrid = data.length;
|
||||||
|
|
||||||
/* Remove idle planes. */
|
/* Remove idle planes. */
|
||||||
for (var p in Planes) {
|
for (var p in Planes) {
|
||||||
if (!stillhere[p]) {
|
if (!stillhere[p]) {
|
||||||
|
@ -143,8 +161,18 @@ function placeFooter() {
|
||||||
var infoWidth = parseInt($('#info').width());
|
var infoWidth = parseInt($('#info').width());
|
||||||
var marginLeft = parseInt((infoWidth / 2) - (footerWidth / 2));
|
var marginLeft = parseInt((infoWidth / 2) - (footerWidth / 2));
|
||||||
|
|
||||||
$('#info_footer').css('top',offset);
|
$('#info_footer').css('top', offset);
|
||||||
$('#info_footer').css('margin-left',marginLeft);
|
$('#info_footer').css('margin-left', marginLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
document.getElementById('selinfo').innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
|
Loading…
Reference in a new issue