Merge pull request #48 from wiedehopf/track_history_fix

SkyView: Fix aircraft trail handling
This commit is contained in:
Oliver Jowett 2019-08-16 18:46:49 +08:00 committed by GitHub
commit e2761fc21d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 25 deletions

View file

@ -44,6 +44,7 @@ function PlaneObject(icao) {
this.version = null; this.version = null;
this.prev_position = null; this.prev_position = null;
this.prev_position_time = null;
this.position = null; this.position = null;
this.position_from_mlat = false this.position_from_mlat = false
this.sitedist = null; this.sitedist = null;
@ -135,29 +136,32 @@ PlaneObject.prototype.isFiltered = function() {
// Appends data to the running track so we can get a visual tail on the plane // Appends data to the running track so we can get a visual tail on the plane
// Only useful for a long running browser session. // Only useful for a long running browser session.
PlaneObject.prototype.updateTrack = function(estimate_time) { PlaneObject.prototype.updateTrack = function(receiver_timestamp, last_timestamp) {
if (!this.position) if (!this.position)
return false; return false;
if (this.position == this.prev_position) if (this.prev_position && this.position[0] == this.prev_position[0] && this.position[1] == this.prev_position[1])
return false; return false;
var projHere = ol.proj.fromLonLat(this.position); var projHere = ol.proj.fromLonLat(this.position);
var projPrev; var projPrev;
var prev_time;
if (this.prev_position === null) { if (this.prev_position === null) {
projPrev = projHere; projPrev = projHere;
prev_time = this.last_position_time;
} else { } else {
projPrev = ol.proj.fromLonLat(this.prev_position); projPrev = ol.proj.fromLonLat(this.prev_position);
prev_time = this.prev_position_time;
} }
this.prev_position = this.position; this.prev_position = this.position;
this.prev_position_time = this.last_position_time;
if (this.track_linesegs.length == 0) { if (this.track_linesegs.length == 0) {
// Brand new track // Brand new track
//console.log(this.icao + " new track"); //console.log(this.icao + " new track");
var newseg = { fixed: new ol.geom.LineString([projHere]), var newseg = { fixed: new ol.geom.LineString([projHere]),
feature: null, feature: null,
head_update: this.last_position_time, update_time: this.last_position_time,
tail_update: this.last_position_time,
estimated: false, estimated: false,
ground: (this.altitude === "ground"), ground: (this.altitude === "ground"),
altitude: this.altitude altitude: this.altitude
@ -168,9 +172,20 @@ PlaneObject.prototype.updateTrack = function(estimate_time) {
} }
var lastseg = this.track_linesegs[this.track_linesegs.length - 1]; var lastseg = this.track_linesegs[this.track_linesegs.length - 1];
var elapsed = (this.last_position_time - lastseg.head_update);
// Determine if track data are intermittent/stale
var est_track = (elapsed > estimate_time); // Time difference between two position updates should not be much
// greater than the difference between data inputs
// MLAT data are given some more leeway
var time_difference = (this.last_position_time - prev_time) - (receiver_timestamp - last_timestamp);
var stale_timeout = (this.position_from_mlat ? 30 : 5);
var est_track = (time_difference > stale_timeout);
// Also check if the position was already stale when it was exported by dump1090
// Makes stale check more accurate for history points spaced 30 seconds apart
est_track = est_track || ((receiver_timestamp - this.last_position_time) > stale_timeout);
var ground_track = (this.altitude === "ground"); var ground_track = (this.altitude === "ground");
if (est_track) { if (est_track) {
@ -179,16 +194,16 @@ PlaneObject.prototype.updateTrack = function(estimate_time) {
// >5s gap in data, create a new estimated segment // >5s gap in data, create a new estimated segment
//console.log(this.icao + " switching to estimated"); //console.log(this.icao + " switching to estimated");
lastseg.fixed.appendCoordinate(projPrev); lastseg.fixed.appendCoordinate(projPrev);
this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev, projHere]), this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]),
feature: null, feature: null,
head_update: this.last_position_time, update_time: prev_time,
altitude: 0, altitude: 0,
estimated: true }); estimated: true });
this.history_size += 2; this.history_size += 2;
} else { } else {
// Keep appending to the existing dashed line; keep every point // Keep appending to the existing dashed line; keep every point
lastseg.fixed.appendCoordinate(projPrev); lastseg.fixed.appendCoordinate(projPrev);
lastseg.head_update = this.last_position_time; lastseg.update_time = prev_time;
this.history_size++; this.history_size++;
} }
@ -198,16 +213,16 @@ PlaneObject.prototype.updateTrack = function(estimate_time) {
if (lastseg.estimated) { if (lastseg.estimated) {
// We are back to good data (we got two points close in time), switch back to // We are back to good data (we got two points close in time), switch back to
// solid lines. // solid lines.
lastseg.fixed.appendCoordinate(projPrev);
lastseg = { fixed: new ol.geom.LineString([projPrev]), lastseg = { fixed: new ol.geom.LineString([projPrev]),
feature: null, feature: null,
head_update: this.last_position_time, update_time: prev_time,
tail_update: this.last_position_time,
estimated: false, estimated: false,
ground: (this.altitude === "ground"), ground: (this.altitude === "ground"),
altitude: this.altitude }; altitude: this.altitude };
this.track_linesegs.push(lastseg); this.track_linesegs.push(lastseg);
this.history_size ++; this.history_size += 2;
// continue return true;
} }
if ( (lastseg.ground && this.altitude !== "ground") || if ( (lastseg.ground && this.altitude !== "ground") ||
@ -218,29 +233,27 @@ PlaneObject.prototype.updateTrack = function(estimate_time) {
// FIXME needs reimplementing post-google // FIXME needs reimplementing post-google
lastseg.fixed.appendCoordinate(projPrev); lastseg.fixed.appendCoordinate(projPrev);
this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev, projHere]), this.track_linesegs.push({ fixed: new ol.geom.LineString([projPrev]),
feature: null, feature: null,
head_update: this.last_position_time, update_time: prev_time,
tail_update: this.last_position_time,
estimated: false, estimated: false,
altitude: this.altitude, altitude: this.altitude,
ground: (this.altitude === "ground") }); ground: (this.altitude === "ground") });
this.history_size += 3; this.history_size += 2;
return true; return true;
} }
// Add more data to the existing track. // Add more data to the existing track.
// We only retain some historical points, at 5+ second intervals, // We only retain some historical points, at 5+ second intervals,
// plus the most recent point // plus the most recent point
if (this.last_position_time - lastseg.tail_update >= 5) { if (prev_time - lastseg.update_time >= 5) {
// enough time has elapsed; retain the last point and add a new one // enough time has elapsed; retain the last point and add a new one
//console.log(this.icao + " retain last point"); //console.log(this.icao + " retain last point");
lastseg.fixed.appendCoordinate(projHere); lastseg.fixed.appendCoordinate(projPrev);
lastseg.tail_update = lastseg.head_update; lastseg.update_time = prev_time;
this.history_size ++; this.history_size ++;
} }
lastseg.head_update = this.last_position_time;
return true; return true;
}; };
@ -555,7 +568,7 @@ PlaneObject.prototype.updateTick = function(receiver_timestamp, last_timestamp)
} else { } else {
if (this.position !== null && (this.selected || this.seen_pos < 60)) { if (this.position !== null && (this.selected || this.seen_pos < 60)) {
this.visible = true; this.visible = true;
if (this.updateTrack(receiver_timestamp - last_timestamp + (this.position_from_mlat ? 30 : 5))) { if (this.updateTrack(receiver_timestamp, last_timestamp)) {
this.updateLines(); this.updateLines();
this.updateMarker(true); this.updateMarker(true);
} else { } else {
@ -657,7 +670,11 @@ PlaneObject.prototype.updateLines = function() {
var lastfixed = lastseg.fixed.getCoordinateAt(1.0); var lastfixed = lastseg.fixed.getCoordinateAt(1.0);
var geom = new ol.geom.LineString([lastfixed, ol.proj.fromLonLat(this.position)]); var geom = new ol.geom.LineString([lastfixed, ol.proj.fromLonLat(this.position)]);
this.elastic_feature = new ol.Feature(geom); this.elastic_feature = new ol.Feature(geom);
this.elastic_feature.setStyle(this.altitudeLines(lastseg.altitude)); if (lastseg.estimated) {
this.elastic_feature.setStyle(estimateStyle);
} else {
this.elastic_feature.setStyle(this.altitudeLines(lastseg.altitude));
}
if (oldElastic < 0) { if (oldElastic < 0) {
PlaneTrailFeatures.push(this.elastic_feature); PlaneTrailFeatures.push(this.elastic_feature);

View file

@ -444,7 +444,7 @@ function end_load_history() {
console.log("Updating tracks at: " + now); console.log("Updating tracks at: " + now);
for (var i = 0; i < PlanesOrdered.length; ++i) { for (var i = 0; i < PlanesOrdered.length; ++i) {
var plane = PlanesOrdered[i]; var plane = PlanesOrdered[i];
plane.updateTrack((now - last) + 1); plane.updateTrack(now, last);
} }
last = now; last = now;