Fix the final (elastic) line segment in trails so it works correctly

in both in the select-all case and the regular case.
This commit is contained in:
Oliver Jowett 2016-09-15 12:37:30 +01:00
parent d0f9b870cd
commit 5445ce143c

View file

@ -23,6 +23,7 @@ function PlaneObject(icao) {
this.rssi = null; this.rssi = null;
// Track history as a series of line segments // Track history as a series of line segments
this.elastic_feature = null;
this.track_linesegs = []; this.track_linesegs = [];
this.history_size = 0; this.history_size = 0;
@ -204,6 +205,11 @@ PlaneObject.prototype.clearLines = function() {
seg.feature = null; seg.feature = null;
} }
} }
if (this.elastic_feature !== null) {
PlaneTrailFeatures.remove(this.elastic_feature);
this.elastic_feature = null;
}
}; };
PlaneObject.prototype.getDataSource = function() { PlaneObject.prototype.getDataSource = function() {
@ -516,18 +522,24 @@ PlaneObject.prototype.updateLines = function() {
}) })
}); });
// create the new latest-position line // find the old elastic band so we can replace it in place
// (which should be faster than remove-and-add when PlaneTrailFeatures is large)
var oldElastic = -1;
if (this.elastic_feature !== null) {
oldElastic = PlaneTrailFeatures.getArray().indexOf(this.elastic_feature);
}
// create the new elastic band feature
var lastseg = this.track_linesegs[this.track_linesegs.length - 1]; var lastseg = this.track_linesegs[this.track_linesegs.length - 1];
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)]);
var feature = new ol.Feature(geom); this.elastic_feature = new ol.Feature(geom);
lastseg.feature = feature; this.elastic_feature.setStyle(this.altitude === 'ground' ? groundStyle : airStyle);
feature.setStyle(this.altitude === 'ground' ? groundStyle : airStyle);
if (PlaneTrailFeatures.getLength() == 0) { if (oldElastic < 0) {
PlaneTrailFeatures.push(feature); PlaneTrailFeatures.push(this.elastic_feature);
} else { } else {
PlaneTrailFeatures.setAt(0, feature); PlaneTrailFeatures.setAt(oldElastic, this.elastic_feature);
} }
// create any missing fixed line features // create any missing fixed line features