2013-01-13 08:39:29 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
2020-02-03 01:18:27 +08:00
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
|
2013-01-13 08:39:29 +08:00
|
|
|
<style type="text/css">
|
|
|
|
html { height: 100% }
|
|
|
|
body { height: 100%; margin: 0; padding: 0 }
|
2020-02-03 01:18:27 +08:00
|
|
|
.plane-icon {
|
|
|
|
padding:0px;
|
|
|
|
margin:0px;
|
|
|
|
}
|
2013-01-13 08:39:29 +08:00
|
|
|
#map_canvas { height: 100% }
|
2013-01-27 08:37:05 +08:00
|
|
|
#info {
|
|
|
|
position: absolute;
|
|
|
|
width:20%;
|
|
|
|
height:100%;
|
|
|
|
bottom:0px;
|
|
|
|
right:0px;
|
|
|
|
top:0px;
|
|
|
|
background-color: white;
|
|
|
|
border-left:1px #666 solid;
|
|
|
|
font-family:Helvetica;
|
|
|
|
}
|
|
|
|
#info div {
|
|
|
|
padding:0px;
|
|
|
|
padding-left:10px;
|
|
|
|
margin:0px;
|
|
|
|
}
|
|
|
|
#info div h1 {
|
|
|
|
margin-top:10px;
|
|
|
|
font-size:16px;
|
|
|
|
}
|
|
|
|
#info div p {
|
|
|
|
font-size:14px;
|
|
|
|
color:#333;
|
|
|
|
}
|
2013-01-13 08:39:29 +08:00
|
|
|
</style>
|
2020-02-03 01:18:27 +08:00
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
|
|
|
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
|
2013-01-13 08:39:29 +08:00
|
|
|
<script type="text/javascript">
|
|
|
|
Map=null;
|
2013-01-17 03:25:28 +08:00
|
|
|
CenterLat=45.0;
|
2013-01-13 08:39:29 +08:00
|
|
|
CenterLon=9.0;
|
|
|
|
Planes={};
|
2013-01-27 08:37:05 +08:00
|
|
|
NumPlanes = 0;
|
|
|
|
Selected=null
|
2013-01-13 08:39:29 +08:00
|
|
|
|
|
|
|
function getIconForPlane(plane) {
|
2013-01-17 03:25:28 +08:00
|
|
|
var r = 255, g = 255, b = 0;
|
|
|
|
var maxalt = 40000; /* Max altitude in the average case */
|
|
|
|
var invalt = maxalt-plane.altitude;
|
2013-01-27 08:37:05 +08:00
|
|
|
var selected = (Selected == plane.hex);
|
2013-01-17 03:25:28 +08:00
|
|
|
|
|
|
|
if (invalt < 0) invalt = 0;
|
|
|
|
b = parseInt(255/maxalt*invalt);
|
2020-02-03 01:18:27 +08:00
|
|
|
|
2020-02-04 06:45:23 +08:00
|
|
|
/* As Icon we use the plane emoji, this is a simple solution but
|
|
|
|
is definitely a compromise: we expect the icon to be rotated
|
|
|
|
45 degrees facing north-east by default, this is true in most
|
|
|
|
systems but not all. */
|
2020-02-03 01:18:27 +08:00
|
|
|
var he = document.createElement("P");
|
|
|
|
he.innerHTML = '>';
|
2020-02-03 06:02:56 +08:00
|
|
|
var rotation = 45+360-plane.track;
|
2020-02-04 06:37:18 +08:00
|
|
|
var selhtml = '';
|
2020-02-04 06:45:23 +08:00
|
|
|
|
|
|
|
/* Give a border to the selected plane. */
|
2020-02-04 06:37:18 +08:00
|
|
|
if (Selected == plane.hex) {
|
|
|
|
selhtml = 'border:1px dotted #0000aa; border-radius:10px;';
|
|
|
|
} else {
|
|
|
|
selhtml = '';
|
|
|
|
}
|
|
|
|
he = '<div style="transform: rotate(-'+rotation+'deg); '+selhtml+'">✈️</div>';
|
2020-02-03 01:18:27 +08:00
|
|
|
var icon = L.divIcon({html: he, className: 'plane-icon'});
|
|
|
|
return icon;
|
2013-01-13 08:39:29 +08:00
|
|
|
}
|
|
|
|
|
2020-02-03 06:26:08 +08:00
|
|
|
function selectPlane(planehex) {
|
|
|
|
if (!Planes[planehex]) return;
|
2013-01-27 08:37:05 +08:00
|
|
|
var old = Selected;
|
2020-02-03 06:26:08 +08:00
|
|
|
Selected = planehex;
|
2013-01-27 08:37:05 +08:00
|
|
|
if (Planes[old]) {
|
|
|
|
/* Remove the highlight in the previously selected plane. */
|
|
|
|
Planes[old].marker.setIcon(getIconForPlane(Planes[old]));
|
|
|
|
}
|
|
|
|
Planes[Selected].marker.setIcon(getIconForPlane(Planes[Selected]));
|
|
|
|
refreshSelectedInfo();
|
|
|
|
}
|
2020-02-04 06:37:18 +08:00
|
|
|
|
2020-02-04 06:45:23 +08:00
|
|
|
/* Return a closure to caputure the 'hex' argument. This way we don't
|
|
|
|
have to care about how Leaflet passes the object to the callback. */
|
2020-02-04 06:37:18 +08:00
|
|
|
function selectPlaneCallback(hex) {
|
|
|
|
return function() {
|
|
|
|
return selectPlane(hex);
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 08:37:05 +08:00
|
|
|
|
|
|
|
function refreshGeneralInfo() {
|
|
|
|
var i = document.getElementById('geninfo');
|
|
|
|
|
|
|
|
i.innerHTML = NumPlanes+' planes on screen.';
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshSelectedInfo() {
|
|
|
|
var i = document.getElementById('selinfo');
|
|
|
|
var p = Planes[Selected];
|
|
|
|
|
|
|
|
if (!p) return;
|
|
|
|
var html = 'ICAO: '+p.hex+'<br>';
|
|
|
|
if (p.flight.length) {
|
|
|
|
html += '<b>'+p.flight+'</b><br>';
|
|
|
|
}
|
2013-02-05 06:09:05 +08:00
|
|
|
html += 'Altitude: '+p.altitude+' feet<br>';
|
2013-01-27 08:37:05 +08:00
|
|
|
html += 'Speed: '+p.speed+' knots<br>';
|
2013-02-05 06:09:05 +08:00
|
|
|
html += 'Coordinates: '+p.lat+', '+p.lon+'<br>';
|
2013-01-27 08:37:05 +08:00
|
|
|
i.innerHTML = html;
|
|
|
|
}
|
|
|
|
|
2013-01-13 08:39:29 +08:00
|
|
|
function fetchData() {
|
|
|
|
$.getJSON('/data.json', function(data) {
|
|
|
|
var stillhere = {}
|
|
|
|
for (var j=0; j < data.length; j++) {
|
|
|
|
var plane = data[j];
|
2013-01-17 03:25:28 +08:00
|
|
|
var marker = null;
|
2013-01-13 08:39:29 +08:00
|
|
|
stillhere[plane.hex] = true;
|
2013-01-17 03:25:28 +08:00
|
|
|
plane.flight = $.trim(plane.flight);
|
2013-01-13 08:39:29 +08:00
|
|
|
|
|
|
|
if (Planes[plane.hex]) {
|
|
|
|
var myplane = Planes[plane.hex];
|
2013-01-17 03:25:28 +08:00
|
|
|
marker = myplane.marker;
|
2020-02-03 01:18:27 +08:00
|
|
|
marker.setLatLng([plane.lat,plane.lon]);
|
2013-01-13 08:39:29 +08:00
|
|
|
marker.setIcon(getIconForPlane(plane));
|
2013-01-27 08:37:05 +08:00
|
|
|
myplane.altitude = plane.altitude;
|
|
|
|
myplane.speed = plane.speed;
|
|
|
|
myplane.lat = plane.lat;
|
|
|
|
myplane.lon = plane.lon;
|
2013-02-02 23:32:00 +08:00
|
|
|
myplane.track = plane.track;
|
2013-02-04 06:20:29 +08:00
|
|
|
myplane.flight = plane.flight;
|
2013-01-27 08:37:05 +08:00
|
|
|
if (myplane.hex == Selected)
|
|
|
|
refreshSelectedInfo();
|
2013-01-13 08:39:29 +08:00
|
|
|
} else {
|
2020-02-03 01:18:27 +08:00
|
|
|
var icon = getIconForPlane(plane);
|
|
|
|
var marker = L.marker([plane.lat, plane.lon], {icon: icon}).addTo(Map);
|
2020-02-03 06:26:08 +08:00
|
|
|
var hex = plane.hex;
|
2020-02-04 06:37:18 +08:00
|
|
|
marker.on('click',selectPlaneCallback(plane.hex));
|
2013-01-13 08:39:29 +08:00
|
|
|
plane.marker = marker;
|
2013-01-27 08:37:05 +08:00
|
|
|
marker.planehex = plane.hex;
|
2013-01-13 08:39:29 +08:00
|
|
|
Planes[plane.hex] = plane;
|
|
|
|
}
|
2020-02-03 01:18:27 +08:00
|
|
|
|
|
|
|
// FIXME: Set the title
|
|
|
|
// if (plane.flight.length == 0)
|
|
|
|
// marker.setTitle(plane.hex)
|
|
|
|
// else
|
|
|
|
// marker.setTitle(plane.flight+' ('+plane.hex+')')
|
2013-01-13 08:39:29 +08:00
|
|
|
}
|
2013-01-27 08:37:05 +08:00
|
|
|
NumPlanes = data.length;
|
2013-01-13 08:39:29 +08:00
|
|
|
|
|
|
|
/* Remove idle planes. */
|
|
|
|
for (var p in Planes) {
|
|
|
|
if (!stillhere[p]) {
|
2020-02-03 01:18:27 +08:00
|
|
|
Map.removeLayer(Planes[p].marker);
|
2013-01-13 08:39:29 +08:00
|
|
|
delete Planes[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initialize() {
|
2020-02-03 01:18:27 +08:00
|
|
|
Map = L.map('map_canvas').setView([37.0, 13.0], 8);
|
|
|
|
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
|
|
maxZoom: 18,
|
|
|
|
id: 'mapbox/streets-v11',
|
|
|
|
accessToken: 'your.mapbox.access.token'
|
|
|
|
}).addTo(Map);
|
2013-01-13 08:39:29 +08:00
|
|
|
|
|
|
|
/* Setup our timer to poll from the server. */
|
|
|
|
window.setInterval(function() {
|
|
|
|
fetchData();
|
2013-01-27 08:37:05 +08:00
|
|
|
refreshGeneralInfo();
|
2020-02-03 01:18:27 +08:00
|
|
|
}, 100);
|
2013-01-13 08:39:29 +08:00
|
|
|
}
|
2013-01-27 08:37:05 +08:00
|
|
|
|
2013-01-13 08:39:29 +08:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body onload="initialize()">
|
2013-01-27 08:37:05 +08:00
|
|
|
<div id="map_canvas" style="width:80%; height:100%"></div>
|
|
|
|
<div id="info">
|
|
|
|
<div>
|
2013-02-02 23:32:42 +08:00
|
|
|
<h1>Dump1090</h1>
|
2013-01-27 08:37:05 +08:00
|
|
|
<p id="geninfo"></p>
|
|
|
|
<p id="selinfo">Click on a plane for info.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2013-01-13 08:39:29 +08:00
|
|
|
</body>
|
|
|
|
</html>
|