Skip to content

Commit

Permalink
Use Google maps and a few cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfrax committed Jun 9, 2017
1 parent d935a12 commit e6ee474
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
194 changes: 194 additions & 0 deletions map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spots map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<style type="text/css">
html {
height: 100%
}

body {
height: 100%;
margin: 0;
padding: 0
}

#map_canvas {
height: 100%
}

#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;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type="text/javascript">
Map = null;
CenterLat = 55.732727;
CenterLon = 13.172479;
Planes = {};
NumPlanes = 0;
Selected = null;

function initMap() {
Map = new google.maps.Map(document.getElementById('map_canvas'), {
center: {lat: CenterLat, lng: CenterLon},
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
window.setInterval(function () {
fetchData();
refreshGeneralInfo();
}, 1000);
}

function getIconForPlane(plane) { // Ok
var r = 255, g = 255, b = 0;
var maxalt = 40000;
/* Max altitude in the average case */
var invalt = maxalt - parseInt(plane['altitude']);
var selected = (Selected == plane['ICAO24']);
if (invalt < 0) invalt = 0;
b = parseInt(255 / maxalt * invalt);
return {
strokeWeight: (selected ? 2 : 1),
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 5,
fillColor: 'rgb(' + r + ',' + g + ',' + b + ')',
fillOpacity: 0.9,
rotation: parseInt(plane['heading'])
};
}
function selectPlane() {
if (!Planes[this.planehex]) return;
var old = Selected;
Selected = this.planehex;
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();
}

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['ICAO24'] + '<br>';
if (p['call_sign'] !== "") {
html += '<b>' + p['call_sign'] + '</b><br>';
}
html += 'Altitude: ' + p['altitude'] + ' meters<br>';
html += 'Speed: ' + p['velocity'] + ' km/h<br>';
html += 'Coordinates: ' + p['latitude'] + ', ' + p['longitude'] + '<br>';
i.innerHTML = html;
}
function fetchData() {
$.ajax({
url: "/spots/data",
method: 'GET',
dataType: 'json',
cache: false
}).done(function (data) {
var stillhere = {};
for (var j = 0; j < data.length; j++) {
var plane = data[j];
var marker = null;
stillhere[plane['ICAO24']] = true;
plane['call_sign'] = $.trim(plane['call_sign']);
if (Planes[plane['ICAO24']]) {
var myplane = Planes[plane['ICAO24']];
marker = myplane.marker;
var icon = marker.getIcon();
var newpos = new google.maps.LatLng(parseInt(plane['latitude']), parseInt(plane['longitude']));
marker.setPosition(newpos);
marker.setIcon(getIconForPlane(plane));
myplane.altitude = parseInt(plane['altitude']);
myplane.speed = parseInt(plane['velocity']);
myplane.lat = parseInt(plane['latitude']);
myplane.lon = parseInt(plane['longitude']);
myplane.track = parseInt(plane['heading']);
myplane.flight = plane['call_sign'];
if (myplane['ICAO24'] == Selected)
refreshSelectedInfo();
} else {
marker = new google.maps.Marker({
position: new google.maps.LatLng(parseInt(plane['latitude']), parseInt(plane['longitude'])),
map: Map,
icon: getIconForPlane(plane)
});
plane.marker = marker;
marker.planehex = plane['ICAO24'];
Planes[plane['ICAO24']] = plane;
/* Trap clicks for this marker. */
google.maps.event.addListener(marker, 'click', selectPlane);
}
if (plane['call_sign'] === "")
marker.setTitle(plane['ICAO24']);
else
marker.setTitle(plane['call_sign'] + ' (' + plane['ICAO24'] + ')')
}
NumPlanes = data.length;
/* Remove idle planes. */
for (var p in Planes) {
if (!stillhere[p]) {
Planes[p].marker.setMap(null);
delete Planes[p];
}
}
});
}
</script>
</head>
<body>
<div id="map_canvas" style="width:80%; height:100%"></div>
<div id="info">
<div>
<h1>Dump1090</h1>
<p id="geninfo"></p>
<p id="selinfo">Click on a plane for info.</p>
</div>
</div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyATvbYyz1Z74e_Ik1870gBBxP8_mdGz6ZY&callback=initMap"
type="text/javascript">

</script>

</body>
</html>


2 changes: 2 additions & 0 deletions spots.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h4 id="hdCurrentData"></h4>
<table id="tbCurrentData">
<thead>
<tr>
<th>No</th>
<th>ICAO</th>
<th>Mode</th>
<th>Squawk</th>
Expand Down Expand Up @@ -91,6 +92,7 @@ <h4 id="hdStatistics"></h4>

for (i = 0; i < series.length; i++) {
rows += "<tr><td>" +
(i + 1) + "</td><td>" +
series[i]['ICAO24'] + "</td><td>" +
series[i]['downlink_format'] + "</td><td>" +
series[i]['squawk'] + "</td><td>" +
Expand Down
6 changes: 6 additions & 0 deletions squitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,15 @@ def decodeCPR(self):

self.data['latitude'] = str(round(latitude, 3)) if latitude != 0.0 else ""
self.data['longitude'] = str(round(longitude, 3)) if longitude != 0.0 else ""

self.even_pos = False
self.odd_pos = False

self.odd_raw_latitude = 0
self.odd_raw_longitude = 0
self.even_raw_latitude = 0
self.even_raw_longitude = 0

return True

def decodeCPR_relative(self):
Expand Down

0 comments on commit e6ee474

Please sign in to comment.