diff --git a/webassets/css/style.css b/webassets/css/style.css index 89d5f00..cebe765 100644 --- a/webassets/css/style.css +++ b/webassets/css/style.css @@ -102,7 +102,7 @@ span.freq-hz { font-size: 0.8em; } -span.mode-q { +span.mode-q, span.bearing-q { padding-left: 0.5em; font-size: 0.7em; color: lightgray; diff --git a/webassets/js/common.js b/webassets/js/common.js index 8c0312d..79484fb 100644 --- a/webassets/js/common.js +++ b/webassets/js/common.js @@ -109,6 +109,21 @@ function columnsUpdated() { saveSettings(); } +// Calculate great circle bearing between two lat/lon points. +function calcBearing(lat1, lon1, lat2, lon2) { + lat1 *= Math.PI / 180; + lon1 *= Math.PI / 180; + lat2 *= Math.PI / 180; + lon2 *= Math.PI / 180; + var lonDelta = lon2 - lon1; + var y = Math.sin(lonDelta) * Math.cos(lat2); + var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta); + var bearing = Math.atan2(y, x); + bearing = bearing * (180 / Math.PI); + if ( bearing < 0 ) { bearing += 360; } + return bearing; +} + // Convert a Maidenhead grid reference of arbitrary precision to the lat/long of the centre point of the square. // Returns null if the grid format is invalid. function latLonForGridCentre(grid) { diff --git a/webassets/js/spots.js b/webassets/js/spots.js index 22e8bf5..bff15f0 100644 --- a/webassets/js/spots.js +++ b/webassets/js/spots.js @@ -65,6 +65,9 @@ function updateTable() { if (showComment) { table.find('thead tr').append(`Comment`); } + if (showBearing) { + table.find('thead tr').append(`Bearing`); + } if (showSource) { table.find('thead tr').append(`Source`); } @@ -120,7 +123,7 @@ function updateTable() { mode_string = "???"; } if (s["mode_source"] == "BANDPLAN") { - mode_string = mode_string + "" + mode_string = mode_string + ""; } // Format comment @@ -129,6 +132,20 @@ function updateTable() { commentText = escapeHtml(s["comment"]); } + // Format bearing text + var bearingText = "---"; + if (userPos != null && s["latitude"] != null && s["longitude"] != null) { + var bearing = calcBearing(userPos[0], userPos[1], s["latitude"], s["longitude"]); + bearingText = bearing.toFixed(0).padStart(3, '0') + "°"; + if (s["location_good"] == null || s["location_good"] == false) { + if (s["location_source"] == "QRZ") { + bearingText = bearingText + ""; + } else { + bearingText = bearingText + ""; + } + } + } + // Sig or fallback to source var sigSourceText = s["source"]; if (s["sig"]) { @@ -187,6 +204,9 @@ function updateTable() { if (showComment) { $tr.append(`${commentText}`); } + if (showBearing) { + $tr.append(`${bearingText}`); + } if (showSource) { $tr.append(` ${sigSourceText}`); } @@ -210,8 +230,11 @@ function updateTable() { if (showRef) { $td2.append(`${sig_refs} `); } + if (showBearing) { + $td2.append(`${bearingText} `); + } if (showComment) { - $td2.append(`${commentText} `); + $td2.append(`
${commentText}`); } $tr2.append($td2); table.find('tbody').append($tr2);