[hamradio-commits] [dump1090] 233/373: Added metric-option to web-view Added option to show values in metric system. Metric = false; // true|false

Matthew Ernisse mernisse-guest at moszumanska.debian.org
Thu Oct 23 14:58:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

mernisse-guest pushed a commit to branch backport
in repository dump1090.

commit 3000baf184aaab9d5a64292e27c8ae440c5ce542
Author: terribl <terri at rannalla.net>
Date:   Tue May 28 12:15:18 2013 +0300

    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 | 61 ++++++++++++++++++++++++++-------------------------
 4 files changed, 38 insertions(+), 38 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 @@
 	<head>
 		<link rel="stylesheet" type="text/css" href="style.css" />
 		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
-		<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
+		<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
 		<script type="text/javascript" src="config.js"></script>
 		<script type="text/javascript" src="untrackedDeveloperSettings.js"></script> <!-- Developers -->
 		<script type="text/javascript" src="planeObject.js"></script>
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 += '<td></tr>';
 	
 	if (selected) {
-    	html += '<tr><td>Altitude: ' + selected.altitude + '</td>';
+	    if (Metric) {
+        	html += '<tr><td>Altitude: ' + Math.round(selected.altitude / 3.2828) + ' m</td>';
+        } else {
+            html += '<tr><td>Altitude: ' + selected.altitude + ' ft</td>';
+        }
     } else {
         html += '<tr><td>Altitude: n/a</td>';
     }
@@ -245,7 +249,11 @@ function refreshSelected() {
 	
 	html += '<tr><td>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);
             
-            // Converts radians to numeric (signed) degrees
-            if (typeof Number.prototype.toDeg == 'undefined') {
-              Number.prototype.toDeg = function() {
-                return this * 180 / Math.PI;
-              }
+            if (Metric) {
+                dist /= 1000;
+            } else {
+                dist /= 1852;
             }
-            
-            // 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 += '<tr><td colspan="' + columns + '">Distance from Site: ' + dist + ' NM</td></tr>';
+            dist = (Math.round((dist)*10)/10).toFixed(1);
+            html += '<tr><td colspan="' + columns + '">Distance from Site: ' + dist +
+                (Metric ? ' km' : ' NM') + '</td></tr>';
         } // End of SiteShow
 	} else {
 	    if (SiteShow) {
-	        html += '<tr><td colspan="' + columns + '">Distance from Site: n/a NM</td></tr>';
+	        html += '<tr><td colspan="' + columns + '">Distance from Site: n/a ' + 
+	            (Metric ? ' km' : ' NM') + '</td></tr>';
 	    } else {
     	    html += 'n/a</td></tr>';
     	}
 	}
 
 	html += '</table>';
-	
 	document.getElementById('plane_detail').innerHTML = html;
 }
 
@@ -401,8 +395,15 @@ function refreshTableInfo() {
     	    } else {
     	        html += '<td align="right"> </td>';
     	    }
-			html += '<td align="right">' + tableplane.altitude + '</td>';
-			html += '<td align="right">' + tableplane.speed + '</td>';
+    	    
+    	    if (Metric) {
+    			html += '<td align="right">' + Math.round(tableplane.altitude / 3.2828) + '</td>';
+    			html += '<td align="right">' + Math.round(tableplane.speed * 1.852) + '</td>';
+    	    } else {
+    	        html += '<td align="right">' + tableplane.altitude + '</td>';
+    	        html += '<td align="right">' + tableplane.speed + '</td>';
+    	    }
+			
 			html += '<td align="right">';
 			if (tableplane.vTrack) {
     			 html += normalizeTrack(tableplane.track, tableplane.vTrack)[2];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git



More information about the pkg-hamradio-commits mailing list