diff --git a/htdocs/lib/MapManager.js b/htdocs/lib/MapManager.js
index 7ea33f14..bc14d465 100644
--- a/htdocs/lib/MapManager.js
+++ b/htdocs/lib/MapManager.js
@@ -58,18 +58,18 @@ function MapManager() {
//
MapManager.prototype.process = function(e) {
if (typeof e.data != 'string') {
- console.error("unsupported binary data on websocket; ignoring");
+ console.error('unsupported binary data on websocket; ignoring');
return
}
- if (e.data.substr(0, 16) == "CLIENT DE SERVER") {
+ if (e.data.substr(0, 16) == 'CLIENT DE SERVER') {
return
}
try {
var json = JSON.parse(e.data);
switch (json.type) {
- case "update":
+ case 'update':
this.processUpdates(json.value);
break;
@@ -79,9 +79,11 @@ MapManager.prototype.process = function(e) {
});
break;
- case "config":
+ case 'config':
Object.assign(this.config, json.value);
if ('receiver_gps' in this.config) {
+ // Save receiver location
+ Utils.setReceiverPos(this.config.receiver_gps);
// Passing API key even if this particular map
// engine does not need it (Google Maps do)
this.initializeMap(
diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js
index 50ad3b64..13f5f3df 100644
--- a/htdocs/lib/MessagePanel.js
+++ b/htdocs/lib/MessagePanel.js
@@ -430,7 +430,6 @@ $.fn.hfdlMessagePanel = function() {
AdsbMessagePanel = function(el) {
MessagePanel.call(this, el);
this.clearButton.css('display', 'none');
- this.receiver_pos = null;
}
AdsbMessagePanel.prototype = Object.create(MessagePanel.prototype);
@@ -439,10 +438,6 @@ AdsbMessagePanel.prototype.supportsMessage = function(message) {
return message['mode'] === 'ADSB-LIST';
};
-AdsbMessagePanel.prototype.setReceiverPos = function(pos) {
- if (pos.lat && pos.lon) this.receiver_pos = pos;
-};
-
AdsbMessagePanel.prototype.render = function() {
$(this.el).append($(
'
' +
@@ -504,13 +499,14 @@ AdsbMessagePanel.prototype.pushMessage = function(msg) {
// Compute distance to the receiver
var distance = '';
- if (this.receiver_pos && entry.lat && entry.lon) {
+ var receiver_pos = Utils.getReceiverPos();
+ if (receiver_pos && entry.lat && entry.lon) {
var id = entry.icao? entry.icao
: entry.aircraft? entry.aircraft
: entry.flight? entry.flight
: null;
- distance = Utils.distanceKm(entry, this.receiver_pos) + ' km';
+ distance = Utils.distanceKm(entry, receiver_pos) + ' km';
if (id) distance = Utils.linkToMap(id, distance);
}
diff --git a/htdocs/lib/Utils.js b/htdocs/lib/Utils.js
index 63e7cacb..e565ac68 100644
--- a/htdocs/lib/Utils.js
+++ b/htdocs/lib/Utils.js
@@ -8,6 +8,17 @@ Utils.callsign_url = null;
Utils.vessel_url = null;
Utils.flight_url = null;
Utils.icao_url = null;
+Utils.receiver_pos = null;
+
+// Set receiver position
+Utils.setReceiverPos = function(pos) {
+ if (pos.lat && pos.lon) this.receiver_pos = pos;
+};
+
+// Get receiver position
+Utils.getReceiverPos = function() {
+ return this.receiver_pos;
+};
// Set URL for linkifying callsigns
Utils.setCallsignUrl = function(url) {
@@ -145,8 +156,11 @@ Utils.HHMMSS = function(t) {
return pad(t.getUTCHours()) + ':' + pad(t.getUTCMinutes()) + ':' + pad(t.getUTCSeconds());
};
-// Compute distance, in kilometers, between two latlons.
+// Compute distance, in kilometers, between two latlons. Use receiver
+// location if the second latlon is not provided.
Utils.distanceKm = function(p1, p2) {
+ // Use receiver location if second latlon not given
+ if (p2 == null) p2 = this.receiver_pos;
// Convert from map objects to latlons
if ("lng" in p1) p1 = { lat : p1.lat(), lon : p1.lng() };
if ("lng" in p2) p2 = { lat : p2.lat(), lon : p2.lng() };
diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js
index 903a8090..afc1909d 100644
--- a/htdocs/openwebrx.js
+++ b/htdocs/openwebrx.js
@@ -1069,19 +1069,14 @@ function on_ws_recv(evt) {
}
if ('receiver_gps' in config) {
- var adsb_panel = $('#openwebrx-panel-adsb-message').adsbMessagePanel();
- adsb_panel.setReceiverPos(config['receiver_gps']);
+ Utils.setReceiverPos(config['receiver_gps']);
}
if ('flight_url' in config) {
- var hfdl_panel = $('#openwebrx-panel-hfdl-message').hfdlMessagePanel();
- var adsb_panel = $('#openwebrx-panel-adsb-message').adsbMessagePanel();
Utils.setFlightUrl(config['flight_url']);
}
if ('modes_url' in config) {
- var hfdl_panel = $('#openwebrx-panel-hfdl-message').hfdlMessagePanel();
- var adsb_panel = $('#openwebrx-panel-adsb-message').adsbMessagePanel();
Utils.setIcaoUrl(config['modes_url']);
}