Google map view enhanced: color by altitude and more.

This commit is contained in:
antirez 2013-01-16 20:25:28 +01:00
parent 21fc9de47a
commit 03759a3eb0
2 changed files with 22 additions and 10 deletions

View File

@ -1872,8 +1872,9 @@ char *aircraftsToJson(int *len) {
if (a->lat != 0 && a->lon != 0) { if (a->lat != 0 && a->lon != 0) {
l = snprintf(p,buflen, l = snprintf(p,buflen,
"{\"hex\":\"%s\", \"lat\":%f, \"lon\":%f, \"track\":%d},\n", "{\"hex\":\"%s\", \"flight\":\"%s\", \"lat\":%f, "
a->hexaddr, a->lat, a->lon, a->track); "\"lon\":%f, \"altitude\":%d, \"track\":%d},\n",
a->hexaddr, a->flight, a->lat, a->lon, a->altitude, a->track);
p += l; buflen -= l; p += l; buflen -= l;
/* Resize if needed. */ /* Resize if needed. */
if (buflen < 256) { if (buflen < 256) {

View File

@ -15,17 +15,23 @@
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
Map=null; Map=null;
CenterLat=50.0; CenterLat=45.0;
CenterLon=9.0; CenterLon=9.0;
Planes={}; Planes={};
function getIconForPlane(plane) { function getIconForPlane(plane) {
var r = 255, g = 255, b = 0;
var maxalt = 40000; /* Max altitude in the average case */
var invalt = maxalt-plane.altitude;
if (invalt < 0) invalt = 0;
b = parseInt(255/maxalt*invalt);
return { return {
strokeWeight: 2, strokeWeight: 1,
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW, path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 5, scale: 5,
fillColor: 'yellow', fillColor: 'rgb('+r+','+g+','+b+')',
fillOpacity: 0.8, fillOpacity: 0.9,
rotation: plane.track rotation: plane.track
}; };
} }
@ -35,25 +41,30 @@
var stillhere = {} var stillhere = {}
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);
if (Planes[plane.hex]) { if (Planes[plane.hex]) {
var myplane = Planes[plane.hex]; var myplane = Planes[plane.hex];
var marker = myplane.marker; marker = myplane.marker;
var icon = marker.getIcon(); var icon = marker.getIcon();
var newpos = new google.maps.LatLng(plane.lat, plane.lon); var newpos = new google.maps.LatLng(plane.lat, plane.lon);
marker.setPosition(newpos); marker.setPosition(newpos);
marker.setIcon(getIconForPlane(plane)); marker.setIcon(getIconForPlane(plane));
} else { } else {
var 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,
title: plane.hex,
icon: getIconForPlane(plane) icon: getIconForPlane(plane)
}); });
plane.marker = marker; plane.marker = marker;
Planes[plane.hex] = plane; Planes[plane.hex] = plane;
} }
if (plane.flight.length == 0)
marker.setTitle(plane.hex)
else
marker.setTitle(plane.flight+' ('+plane.hex+')')
} }
/* Remove idle planes. */ /* Remove idle planes. */
@ -70,7 +81,7 @@
function initialize() { function initialize() {
var mapOptions = { var mapOptions = {
center: new google.maps.LatLng(CenterLat, CenterLon), center: new google.maps.LatLng(CenterLat, CenterLon),
zoom: 8, zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP mapTypeId: google.maps.MapTypeId.ROADMAP
}; };
Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); Map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);