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. */
|
||||||
|
|
|
@ -3,8 +3,9 @@ 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);
|
||||||
|
|
||||||
|
@ -43,7 +44,8 @@ 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,19 +60,28 @@ 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]) {
|
if (Planes[plane.hex]) {
|
||||||
|
// Move and refresh old plane on map
|
||||||
var myplane = Planes[plane.hex];
|
var myplane = Planes[plane.hex];
|
||||||
marker = myplane.marker;
|
marker = myplane.marker;
|
||||||
var icon = marker.getIcon();
|
var icon = marker.getIcon();
|
||||||
|
@ -83,9 +94,12 @@ function fetchData() {
|
||||||
myplane.lon = plane.lon;
|
myplane.lon = plane.lon;
|
||||||
myplane.track = plane.track;
|
myplane.track = plane.track;
|
||||||
myplane.flight = plane.flight;
|
myplane.flight = plane.flight;
|
||||||
|
myplane.seen = plane.seen;
|
||||||
|
myplane.messages = plane.messages;
|
||||||
if (myplane.hex == Selected)
|
if (myplane.hex == Selected)
|
||||||
refreshSelectedInfo();
|
refreshSelectedInfo();
|
||||||
} else {
|
} else {
|
||||||
|
// Add new plane to map
|
||||||
marker = new google.maps.Marker({
|
marker = new google.maps.Marker({
|
||||||
position: new google.maps.LatLng(plane.lat, plane.lon),
|
position: new google.maps.LatLng(plane.lat, plane.lon),
|
||||||
map: Map,
|
map: Map,
|
||||||
|
@ -95,15 +109,19 @@ function fetchData() {
|
||||||
marker.planehex = plane.hex;
|
marker.planehex = plane.hex;
|
||||||
Planes[plane.hex] = plane;
|
Planes[plane.hex] = plane;
|
||||||
|
|
||||||
/* Trap clicks for this marker. */
|
// Trap clicks for this marker.
|
||||||
google.maps.event.addListener(marker, 'click', selectPlane);
|
google.maps.event.addListener(marker, 'click', selectPlane);
|
||||||
}
|
}
|
||||||
if (plane.flight.length == 0)
|
|
||||||
|
if (plane.flight.length == 0) {
|
||||||
marker.setTitle(plane.hex)
|
marker.setTitle(plane.hex)
|
||||||
else
|
} else {
|
||||||
marker.setTitle(plane.flight+' ('+plane.hex+')')
|
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) {
|
||||||
|
@ -147,6 +165,16 @@ function placeFooter() {
|
||||||
$('#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() {
|
||||||
var mapOptions = {
|
var mapOptions = {
|
||||||
center: new google.maps.LatLng(CenterLat, CenterLon),
|
center: new google.maps.LatLng(CenterLat, CenterLon),
|
||||||
|
|
Loading…
Reference in a new issue