improve location handling & clearing

This commit is contained in:
Jakob Ketterl 2021-01-16 21:16:49 +01:00
parent 8be0092f61
commit 946866319c

View File

@ -88,23 +88,18 @@ YsfMetaPanel.prototype.update = function(data) {
this.setDown(data['down']); this.setDown(data['down']);
this.el.find(".openwebrx-meta-slot").addClass("active"); this.el.find(".openwebrx-meta-slot").addClass("active");
} else { } else {
this.setSource(); this.clear();
this.setLocation();
this.setUp();
this.setDown();
this.el.find(".openwebrx-meta-slot").removeClass("active");
} }
}; };
YsfMetaPanel.prototype.clear = function() { YsfMetaPanel.prototype.clear = function() {
MetaPanel.prototype.clear.call(this); MetaPanel.prototype.clear.call(this);
this.mode = ''; this.setMode();
this.source = ''; this.setSource();
this.lat = 0; this.setLocation();
this.lon = 0; this.setUp();
this.callsign = ''; this.setDown();
this.up = ''; this.el.find(".openwebrx-meta-slot").removeClass("active");
this.down = '';
}; };
YsfMetaPanel.prototype.setMode = function(mode) { YsfMetaPanel.prototype.setMode = function(mode) {
@ -124,9 +119,11 @@ YsfMetaPanel.prototype.setSource = function(source) {
}; };
YsfMetaPanel.prototype.setLocation = function(lat, lon, callsign) { YsfMetaPanel.prototype.setLocation = function(lat, lon, callsign) {
if (this.lat === lat && this.lon === lon && this.callsign === callsign) return; var hasLocation = lat && lon && callsign && callsign != '';
if (hasLocation === this.hasLocation && this.callsign === callsign) return;
this.hasLocation = hasLocation; this.callsign = callsign;
var html = ''; var html = '';
if (lat && lon && callsign) { if (hasLocation) {
html = '<a class="openwebrx-maps-pin" href="map?callsign=' + callsign + '" target="_blank"></a>'; html = '<a class="openwebrx-maps-pin" href="map?callsign=' + callsign + '" target="_blank"></a>';
} }
this.el.find('.openwebrx-ysf-source .location').html(html); this.el.find('.openwebrx-ysf-source .location').html(html);