Adding distance display to the info windows.

This commit is contained in:
Marat Fayzullin 2022-09-15 19:34:39 -04:00
parent 5cd0847362
commit 4423c7f13a

View File

@ -353,6 +353,23 @@ $(function(){
'">' + callsign + '</a>';
};
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(
'<h3>Locator: ' + locator + '</h3>' +
'<h3>Locator: ' + locator + distance + '</h3>' +
'<div>Active Callsigns:</div>' +
'<ul>' +
inLocator.map(function(i){