SkyView: Fix aircraft trail handling

Make aircraft trail handling more consistent and the code hopefully
easier to understand.
Fix position comparison (comparing array references does not work).

When initially loading the SkyView webpage, there are sometimes gaps in
the aircraft trails when the trail transitions from estimated/dotted to
known/solid track.

Fix elastic band style to handle estimated segments properly.
This commit is contained in:
Matthias Wirth 2019-07-27 15:19:17 +02:00
parent ef125bd5f0
commit 5cc04d4ca8

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;
@ -138,26 +139,29 @@ PlaneObject.prototype.isFiltered = function() {
PlaneObject.prototype.updateTrack = function(estimate_time) { PlaneObject.prototype.updateTrack = function(estimate_time) {
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,7 +172,7 @@ 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); var elapsed = (this.last_position_time - prev_time);
var est_track = (elapsed > estimate_time); var est_track = (elapsed > estimate_time);
var ground_track = (this.altitude === "ground"); var ground_track = (this.altitude === "ground");
@ -179,16 +183,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 +202,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 +222,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;
}; };
@ -657,7 +659,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);
if (lastseg.estimated) {
this.elastic_feature.setStyle(estimateStyle);
} else {
this.elastic_feature.setStyle(this.altitudeLines(lastseg.altitude)); this.elastic_feature.setStyle(this.altitudeLines(lastseg.altitude));
}
if (oldElastic < 0) { if (oldElastic < 0) {
PlaneTrailFeatures.push(this.elastic_feature); PlaneTrailFeatures.push(this.elastic_feature);