From ca314fcf2c8e5ef8a245f95887bad73c66070d4b Mon Sep 17 00:00:00 2001 From: terribl Date: Mon, 27 May 2013 11:36:23 +0300 Subject: [PATCH] Added distance to plane from site Just for fun. Distance is only shown if SiteShow is true in config.js-file. modified: public_html/script.js --- public_html/script.js | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/public_html/script.js b/public_html/script.js index 48288c8..d6048ba 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -267,12 +267,45 @@ function refreshSelected() { html += 'Lat/Long: '; if (selected && selected.vPosition) { - html += selected.latitude + ', ' + selected.longitude; + html += selected.latitude + ', ' + selected.longitude + ''; + + // 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; + } + } + + // 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'; + } // End of SiteShow } else { - html += 'n/a'; + if (SiteShow) { + html += 'Distance from Site: n/a NM'; + } else { + html += 'n/a'; + } } - html += ''; - + html += ''; document.getElementById('plane_detail').innerHTML = html; @@ -489,4 +522,6 @@ function selectPlaneByHex(hex) { } else { SelectedPlane = null; } + refreshSelected(); + refreshTableInfo(); }