From cb3289bfb26bc142488ff8d4a15fbd47e960600f Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Thu, 28 Nov 2019 17:15:59 +0100 Subject: [PATCH] temporary trails via config option --- html/config.js | 4 ++++ html/defaults.js | 4 ++++ html/planeObject.js | 25 ++++++++++++++++++++++++- html/script.js | 14 ++++++++++---- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/html/config.js b/html/config.js index 0d1770c..735f7a3 100644 --- a/html/config.js +++ b/html/config.js @@ -163,6 +163,10 @@ BingMapsAPIKey = null; // enable/disable mouseover/hover aircraft information //enableMouseover = true; +// enable/disable temporary aircraft trails +//tempTrails = false; +//tempTrailsTimeout = 90; + // Columns that have a // in front of them are shown. HideCols = [ "#icao", diff --git a/html/defaults.js b/html/defaults.js index 67bb029..67a964b 100644 --- a/html/defaults.js +++ b/html/defaults.js @@ -193,6 +193,10 @@ var mlatTimeout = 30; // enable/disable mouseover/hover aircraft information var enableMouseover = true; +// enable/disable temporary aircraft trails +var tempTrails = false; +var tempTrailsTimeout = 90; + // Columns that have a // in front of them are shown. var HideCols = [ "#icao", diff --git a/html/planeObject.js b/html/planeObject.js index de5ed35..39beb47 100644 --- a/html/planeObject.js +++ b/html/planeObject.js @@ -275,6 +275,7 @@ PlaneObject.prototype.updateTrack = function(now, last) { altitude: this.alt_rounded, alt_real: this.altitude, speed: this.speed, + ts: now, }; this.track_linesegs.push(newseg); this.history_size ++; @@ -348,7 +349,9 @@ PlaneObject.prototype.updateTrack = function(now, last) { this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]), feature: null, altitude: 0, - estimated: true }); + estimated: true, + ts: this.prev_time, + }); this.history_size += 2; } else { // Keep appending to the existing dashed line; keep every point @@ -370,6 +373,7 @@ PlaneObject.prototype.updateTrack = function(now, last) { altitude: this.prev_alt_rounded, alt_real: this.prev_alt, speed: this.prev_speed, + ts: this.prev_time, }); this.history_size += 2; @@ -393,6 +397,7 @@ PlaneObject.prototype.updateTrack = function(now, last) { if ( this.prev_alt_rounded !== lastseg.altitude + || tempTrails //lastseg.ground != on_ground //|| (!on_ground && isNaN(alt_change)) //|| (alt_change > 700) @@ -413,6 +418,7 @@ PlaneObject.prototype.updateTrack = function(now, last) { alt_real: this.prev_alt, speed: this.prev_speed, ground: on_ground, + ts: this.prev_time, }); this.history_size += 2; @@ -1370,3 +1376,20 @@ PlaneObject.prototype.getAircraftData = function() { console.log(this.icao + ': Database load error: ' + textStatus + ' at URL: ' + jqXHR.url); }.bind(this)); } + + +PlaneObject.prototype.reapTrail = function() { + const oldSegs = this.track_linesegs; + this.track_linesegs = []; + this.history_size = 0; + for (var i in oldSegs) { + const seg = oldSegs[i]; + if (seg.ts + tempTrailsTimeout > now) { + this.history_size += seg.fixed.getCoordinates().length; + this.track_linesegs.push(seg); + } + } + if (this.track_linesegs.length != oldSegs.length) { + this.remakeTrail(); + } +} diff --git a/html/script.js b/html/script.js index 6dd4c77..8492329 100644 --- a/html/script.js +++ b/html/script.js @@ -736,7 +736,6 @@ function parse_history() { for (var i in PlanesOrdered) setupPlane(PlanesOrdered[i].icao,PlanesOrdered[i]); } - try { PositionHistoryBuffer = null; console.timeEnd("Loaded aircraft tracks from History"); @@ -749,6 +748,10 @@ function parse_history() { // Setup our timer to poll from the server. window.setInterval(reaper, 60000); + if (tempTrails) { + window.setInterval(trailReaper, 10000); + trailReaper(now); + } if (enable_pf_data) { window.setInterval(fetchPfData, RefreshInterval*10.314); } @@ -766,9 +769,6 @@ function parse_history() { if (localStorage['sidebar_visible'] == "false") toggleSidebarVisibility(); - } catch (error) { - alert(error.message); - } } // Make a LineString with 'points'-number points @@ -2821,3 +2821,9 @@ function findPlanes(query, byIcao, byCallsign, byReg) { console.log("No match found for query: " + query); } } + +function trailReaper() { + for (var i in PlanesOrdered) { + PlanesOrdered[i].reapTrail(); + } +}