From 3000baf184aaab9d5a64292e27c8ae440c5ce542 Mon Sep 17 00:00:00 2001 From: terribl Date: Tue, 28 May 2013 12:15:18 +0300 Subject: [PATCH 1/3] Added metric-option to web-view Added option to show values in metric system. Metric = false; // true|false Removed unused conversion from aircraftsToJson() at dump1090.c-file. Tweaked distance calculation to use google map api. modified: dump1090.c modified: public_html/config.js modified: public_html/gmap.html modified: public_html/script.js --- dump1090.c | 9 ++----- public_html/config.js | 4 +++ public_html/gmap.html | 2 +- public_html/script.js | 63 ++++++++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/dump1090.c b/dump1090.c index c6f41f1..8376f6f 100644 --- a/dump1090.c +++ b/dump1090.c @@ -3487,7 +3487,7 @@ int decodeHexMessage(struct client *c, char *hex) { return (0); } -/* Return a description of planes in json. */ +/* Return a description of planes in json. No metric conversion. */ char *aircraftsToJson(int *len) { time_t now = time(NULL); struct aircraft *a = Modes.aircrafts; @@ -3498,7 +3498,6 @@ char *aircraftsToJson(int *len) { l = snprintf(p,buflen,"[\n"); p += l; buflen -= l; while(a) { - int altitude = a->altitude, speed = a->speed; int position = 0; int track = 0; @@ -3507,11 +3506,6 @@ char *aircraftsToJson(int *len) { continue; } - /* Convert units to metric if --metric was specified. */ - if (Modes.metric) { - altitude = (int) (altitude / 3.2828); - speed = (int) (speed * 1.852); - } if (a->bFlags & MODES_ACFLAGS_LATLON_VALID) { position = 1; @@ -3521,6 +3515,7 @@ char *aircraftsToJson(int *len) { track = 1; } + // No metric conversion l = snprintf(p,buflen, "{\"hex\":\"%06x\", \"squawk\":\"%04x\", \"flight\":\"%s\", \"lat\":%f, " "\"lon\":%f, \"validposition\":%d, \"altitude\":%d, \"track\":%d, \"validtrack\":%d," diff --git a/public_html/config.js b/public_html/config.js index bd6dcda..0bb539a 100644 --- a/public_html/config.js +++ b/public_html/config.js @@ -5,6 +5,10 @@ // // -------------------------------------------------------- +// -- Output Settings ------------------------------------- +// Show metric values +Metric = false; // true|false + // -- Map settings ---------------------------------------- // The Latitude and Longitude in decimal format CONST_CENTERLAT = 45.0; diff --git a/public_html/gmap.html b/public_html/gmap.html index 7bdd0f2..d4beb6f 100644 --- a/public_html/gmap.html +++ b/public_html/gmap.html @@ -2,7 +2,7 @@ - + diff --git a/public_html/script.js b/public_html/script.js index d6048ba..c3acfb4 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -232,7 +232,11 @@ function refreshSelected() { html += ''; if (selected) { - html += 'Altitude: ' + selected.altitude + ''; + if (Metric) { + html += 'Altitude: ' + Math.round(selected.altitude / 3.2828) + ' m'; + } else { + html += 'Altitude: ' + selected.altitude + ' ft'; + } } else { html += 'Altitude: n/a'; } @@ -245,7 +249,11 @@ function refreshSelected() { html += 'Speed: ' if (selected) { - html += selected.speed + ' kt'; + if (Metric) { + html += Math.round(selected.speed * 1.852) + ' km/h'; + } else { + html += selected.speed + ' kt'; + } } else { html += 'n/a'; } @@ -271,43 +279,29 @@ function refreshSelected() { // Let's show some extra data if we have site coordinates if (SiteShow) { - // Converts numeric degrees to radians - if (typeof Number.prototype.toRad == 'undefined') { - Number.prototype.toRad = function() { - return this * Math.PI / 180; - } + var siteLatLon = new google.maps.LatLng(SiteLat, SiteLon); + var planeLatLon = new google.maps.LatLng(selected.latitude, selected.longitude); + var dist = google.maps.geometry.spherical.computeDistanceBetween (siteLatLon, planeLatLon); + + if (Metric) { + dist /= 1000; + } else { + dist /= 1852; } - - // Converts radians to numeric (signed) degrees - if (typeof Number.prototype.toDeg == 'undefined') { - Number.prototype.toDeg = function() { - return this * 180 / Math.PI; - } - } - - // Calculate distance - var R = 6371; // km - var dLat = (selected.latitude-SiteLat).toRad(); - var dLon = (selected.longitude-SiteLon).toRad(); - var a = Math.sin(dLat/2) * Math.sin(dLat/2) + - Math.cos(SiteLat.toRad()) * Math.cos(selected.latitude.toRad()) * - Math.sin(dLon/2) * Math.sin(dLon/2); - var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); - var dist = (R * c) / 1.852; - dist = (Math.round(dist*10)/10).toFixed(1); - - html += 'Distance from Site: ' + dist + ' NM'; + dist = (Math.round((dist)*10)/10).toFixed(1); + html += 'Distance from Site: ' + dist + + (Metric ? ' km' : ' NM') + ''; } // End of SiteShow } else { if (SiteShow) { - html += 'Distance from Site: n/a NM'; + html += 'Distance from Site: n/a ' + + (Metric ? ' km' : ' NM') + ''; } else { html += 'n/a'; } } html += ''; - document.getElementById('plane_detail').innerHTML = html; } @@ -401,8 +395,15 @@ function refreshTableInfo() { } else { html += ' '; } - html += '' + tableplane.altitude + ''; - html += '' + tableplane.speed + ''; + + if (Metric) { + html += '' + Math.round(tableplane.altitude / 3.2828) + ''; + html += '' + Math.round(tableplane.speed * 1.852) + ''; + } else { + html += '' + tableplane.altitude + ''; + html += '' + tableplane.speed + ''; + } + html += ''; if (tableplane.vTrack) { html += normalizeTrack(tableplane.track, tableplane.vTrack)[2]; From 9904c228593024511f7a61efcb6a90efa9d3a1ca Mon Sep 17 00:00:00 2001 From: terribl Date: Thu, 30 May 2013 12:22:52 +0300 Subject: [PATCH 2/3] Added option to draw measurement circles around site Options: SiteCircles = true; SiteCirclesDistances = new Array(100,150,200); Circles are only shown if 'SiteShow' is true. SiteCirclesDistances is array of numbers. Distances are in NM or km depending 'Metric'-settings. modified: public_html/config.js modified: public_html/script.js --- public_html/config.js | 5 +++- public_html/script.js | 65 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/public_html/config.js b/public_html/config.js index 0bb539a..e027134 100644 --- a/public_html/config.js +++ b/public_html/config.js @@ -7,7 +7,7 @@ // -- Output Settings ------------------------------------- // Show metric values -Metric = false; // true|false +Metric = false; // true or false // -- Map settings ---------------------------------------- // The Latitude and Longitude in decimal format @@ -27,3 +27,6 @@ SiteShow = false; // true or false SiteLat = 45.0; SiteLon = 9.0; +SiteCircles = true; // true or false (Only shown if SiteShow is true) +SiteCirclesDistances = new Array(100,150,200); // In nautical miles or km (depending settings value 'Metric') + diff --git a/public_html/script.js b/public_html/script.js index c3acfb4..07cda07 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -146,9 +146,10 @@ function initialize() { GoogleMap.mapTypes.set("dark_map", styledMap); // Add home marker if requested - if (SiteShow) { - var siteMarker = new google.maps.LatLng(SiteLat, SiteLon); - var markerImage = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal4/icon57.png', + if (SiteShow && (typeof SiteLat !== 'undefined' || typeof SiteLon !== 'undefined')) { + var siteMarker = new google.maps.LatLng(SiteLat, SiteLon); + var markerImage = new google.maps.MarkerImage( + 'http://maps.google.com/mapfiles/kml/pal4/icon57.png', new google.maps.Size(32, 32), // Image size new google.maps.Point(0, 0), // Origin point of image new google.maps.Point(16, 16)); // Position where marker should point @@ -157,7 +158,13 @@ function initialize() { map: GoogleMap, icon: markerImage, title: 'My Radar Site' - }); + }); + + if (SiteCircles) { + for (var i=0;iN/A (' + selected.icao + ')'; + html += 'N/A (' + + selected.icao + ')'; } else if (selected && selected.flight != "") { - html += '' + selected.flight + ''; + html += '' + + selected.flight + ''; } else { html += 'DUMP1090'; } @@ -355,12 +364,18 @@ function refreshTableInfo() { html += ''; html += 'ICAO'; html += 'Flight'; - html += 'Squawk'; - html += 'Altitude'; - html += 'Speed'; - html += 'Track'; - html += 'Msgs'; - html += 'Seen'; + html += 'Squawk'; + html += 'Altitude'; + html += 'Speed'; + html += 'Track'; + html += 'Msgs'; + html += 'Seen'; for (var tablep in Planes) { var tableplane = Planes[tablep] if (!tableplane.reapable) { @@ -526,3 +541,29 @@ function selectPlaneByHex(hex) { refreshSelected(); refreshTableInfo(); } + +function drawCircle(marker, distance) { + if (typeof distance === 'undefined') { + return false; + + if (!(!isNaN(parseFloat(distance)) && isFinite(distance)) || distance < 0) { + return false; + } + } + + distance *= 1000.0; + if (!Metric) { + distance *= 1.852; + } + + // Add circle overlay and bind to marker + var circle = new google.maps.Circle({ + map: GoogleMap, + radius: distance, // In meters + fillOpacity: 0.0, + strokeWeight: 1, + strokeOpacity: 0.3 + }); + circle.bindTo('center', marker, 'position'); +} + From fd0c11642467d9813bf94ee2ebc03b4c801cfe42 Mon Sep 17 00:00:00 2001 From: terribl Date: Thu, 30 May 2013 12:31:41 +0300 Subject: [PATCH 3/3] Tyop corrected --- public_html/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public_html/config.js b/public_html/config.js index e027134..c4d7ecd 100644 --- a/public_html/config.js +++ b/public_html/config.js @@ -28,5 +28,6 @@ SiteLat = 45.0; SiteLon = 9.0; SiteCircles = true; // true or false (Only shown if SiteShow is true) -SiteCirclesDistances = new Array(100,150,200); // In nautical miles or km (depending settings value 'Metric') +// In nautical miles or km (depending settings value 'Metric') +SiteCirclesDistances = new Array(100,150,200);