From d7174dea7759571a6b464f4e0f87340a90f6a695 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Mon, 21 Aug 2023 22:05:53 -0400 Subject: [PATCH] Simplifying JS code. --- htdocs/lib/MapMarkers.js | 61 +++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/htdocs/lib/MapMarkers.js b/htdocs/lib/MapMarkers.js index c2d5176b..9a79419f 100644 --- a/htdocs/lib/MapMarkers.js +++ b/htdocs/lib/MapMarkers.js @@ -125,10 +125,9 @@ MarkerManager.prototype.clear = function() { function Marker() {} // Wrap given callsign or other ID into a clickable link. -// When URL not supplied, guess the correct URL by ID type. Marker.linkify = function(callsign, url = null) { - // If no URL given, assume we have an actual HAM callsign - if (!url || (url == '')) url = callsign_url; + // If no URL given, assume HAM callsign + if ((url == null) || (url == '')) url = callsign_url; // Must have valid callsign and lookup URL if ((callsign == '') || (url == null) || (url == '')) @@ -139,6 +138,21 @@ Marker.linkify = function(callsign, url = null) { '">' + callsign + ''; }; +// Create link to tune OWRX to the given frequency and modulation. +Marker.linkifyFreq = function(freq, mod) { + var text; + if (freq >= 30000000) { + text = "" + (freq / 1000000.0) + "MHz"; + } else if (freq >= 10000) { + text = "" + (freq / 1000.0) + "kHz"; + } else { + text = "" + freq + "Hz"; + } + + return '' + text + ''; +}; + // Compute distance, in kilometers, between two latlons. Marker.distanceKm = function(p1, p2) { // Earth radius in km @@ -305,11 +319,9 @@ FeatureMarker.prototype.getInfoHTML = function(name, receiverMarker = null) { } if (this.freq) { - var freq; - freq = "" + (this.freq / 1000000.0) + "MHz"; - freq = '' + freq + ''; - detailsString += Marker.makeListItem('Frequency', freq); + detailsString += Marker.makeListItem('Frequency', Marker.linkifyFreq( + this.freq, this.mmode? this.mmode:'fm' + )); } if (this.mmode) { @@ -337,11 +349,9 @@ FeatureMarker.prototype.getInfoHTML = function(name, receiverMarker = null) { + '‑' + ('0000' + this.schedule[j].time2).slice(-4) + '  ' + this.schedule[j].name; - freq = '' - + Math.round(this.schedule[j].freq/1000) + 'kHz'; - - scheduleString += Marker.makeListItem(name, freq); + scheduleString += Marker.makeListItem(name, Marker.linkifyFreq( + this.schedule[j].freq, mode? mode : 'am' + )); } } @@ -580,18 +590,23 @@ AprsMarker.prototype.getInfoHTML = function(name, receiverMarker = null) { hopsString = '

via ' + hops.join(', ') + ' 

'; } - // Linkify name based on what it is (vessel, flight, mode-S code, or else) - if (this.mode === 'AIS') { - name = Marker.linkify(name, vessel_url); - } else if ((this.mode !== 'HFDL') && (this.mode !== 'VDL2')) { - name = Marker.linkify(name); - } else if (this.aircraft && (name === this.aircraft) && (name[0] != '.')) { - name = Marker.linkify(name, modes_url); - } else { - name = Marker.linkify(name, flight_url); + // Linkify title based on what it is (vessel, flight, mode-S code, or else) + var url = null; + switch (this.mode) { + case 'HFDL': + case 'VDL2': + if (this.aircraft && (name === this.aircraft) && (name[0] != '.')) { + url = modes_url; + } else { + url = flight_url; + } + break; + case 'AIS': + url = vessel_url; + break; } - return '

' + name + distance + '

' + return '

' + Marker.linkify(name, url) + distance + '

' + '
' + timeString + ' using ' + this.mode + ( this.band ? ' on ' + this.band : '' ) + '
' + commentString + weatherString + detailsString + hopsString;