Implement bearing to spot column. Closes #19

This commit is contained in:
Ian Renton
2025-10-12 17:39:26 +01:00
parent bb2813c2a5
commit 35a82a41bd
3 changed files with 41 additions and 3 deletions

View File

@@ -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) {

View File

@@ -65,6 +65,9 @@ function updateTable() {
if (showComment) {
table.find('thead tr').append(`<th class='hideonmobile'>Comment</th>`);
}
if (showBearing) {
table.find('thead tr').append(`<th class='hideonmobile'>Bearing</th>`);
}
if (showSource) {
table.find('thead tr').append(`<th class='hideonmobile'>Source</th>`);
}
@@ -120,7 +123,7 @@ function updateTable() {
mode_string = "???";
}
if (s["mode_source"] == "BANDPLAN") {
mode_string = mode_string + "<span class='mode-q hideonmobile'><i class='fa-solid fa-circle-question' title='The mode was not reported via the spotting service. This is a guess based on the frequency.'></i></span>"
mode_string = mode_string + "<span class='mode-q hideonmobile'><i class='fa-solid fa-circle-question' title='The mode was not reported via the spotting service. This is a guess based on the frequency.'></i></span>";
}
// Format comment
@@ -129,6 +132,20 @@ function updateTable() {
commentText = escapeHtml(s["comment"]);
}
// Format bearing text
var bearingText = "---<span class='bearing-q hideonmobile'><i class='fa-solid fa-circle-question' title='The position was not reported via the spotting service, and we could not determine one. A bearing to this DX is not available.'></i></span>";
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 + "<span class='bearing-q hideonmobile'><i class='fa-solid fa-circle-question' title='The position was not reported via the spotting service. We had to fall back to a QRZ 'home' location for a portable/mobile/alternative spot, so this bearing may not be accurate if the DX is close to you..'></i></span>";
} else {
bearingText = bearingText + "<span class='bearing-q hideonmobile'><i class='fa-solid fa-circle-question' title='The position was not reported via the spotting service. We had to fall back to just using the centre of a DXCC entity, so this bearing may not be accurate if the DX is close to you.'></i></span>";
}
}
}
// Sig or fallback to source
var sigSourceText = s["source"];
if (s["sig"]) {
@@ -187,6 +204,9 @@ function updateTable() {
if (showComment) {
$tr.append(`<td class='hideonmobile'>${commentText}</td>`);
}
if (showBearing) {
$tr.append(`<td class='nowrap hideonmobile'>${bearingText}</td>`);
}
if (showSource) {
$tr.append(`<td class='nowrap hideonmobile'><span class='icon-wrapper'><i class='fa-solid fa-${s["icon"]}'></i></span> ${sigSourceText}</td>`);
}
@@ -210,8 +230,11 @@ function updateTable() {
if (showRef) {
$td2.append(`${sig_refs} `);
}
if (showBearing) {
$td2.append(`${bearingText} `);
}
if (showComment) {
$td2.append(`${commentText} `);
$td2.append(`<br/>${commentText}`);
}
$tr2.append($td2);
table.find('tbody').append($tr2);