From 4423c7f13a4ed696832493a08a36b7ddd340ebdd Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Thu, 15 Sep 2022 19:34:39 -0400 Subject: [PATCH] Adding distance display to the info windows. --- htdocs/map.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/htdocs/map.js b/htdocs/map.js index 8c9ea8c..8acbaa8 100644 --- a/htdocs/map.js +++ b/htdocs/map.js @@ -353,6 +353,23 @@ $(function(){ '">' + callsign + ''; }; + var distanceKm = function(p1, p2) { + // Earth radius in km + var R = 6371.0; + // Convert degrees to radians + var rlat1 = p1.lat() * (Math.PI/180); + var rlat2 = p2.lat() * (Math.PI/180); + // Compute difference in radians + var difflat = rlat2-rlat1; + var difflon = (p2.lng()-p1.lng()) * (Math.PI/180); + // Compute distance + d = 2 * R * Math.asin(Math.sqrt( + Math.sin(difflat/2) * Math.sin(difflat/2) + + Math.cos(rlat1) * Math.cos(rlat2) * Math.sin(difflon/2) * Math.sin(difflon/2) + )); + return Math.round(d); + } + var infowindow; var showLocatorInfoWindow = function(locator, pos) { var infowindow = getInfoWindow(); @@ -364,8 +381,10 @@ $(function(){ }).sort(function(a, b){ return b.lastseen - a.lastseen; }); + var distance = receiverMarker? + " (at " + distanceKm(receiverMarker.position, pos) + "km)" : ""; infowindow.setContent( - '

Locator: ' + locator + '

' + + '

Locator: ' + locator + distance + '

' + '
Active Callsigns:
' + '