diff --git a/html/planeObject.js b/html/planeObject.js
index b07ee59..c86c67d 100644
--- a/html/planeObject.js
+++ b/html/planeObject.js
@@ -701,7 +701,6 @@ PlaneObject.prototype.setMarkerRgb = function() {
PlaneObject.prototype.updateIcon = function() {
let fillColor = hslToRgb(this.getMarkerColor());
- this.scale = scaleFactor * this.baseScale;
let svgKey = fillColor + '!' + this.shape.name + '!' + this.strokeWidth;
let labelText = null;
@@ -1100,7 +1099,7 @@ PlaneObject.prototype.processTrace = function() {
noPan = false;
showTraceExit = false;
- this.updateMarker(true);
+ this.updateMarker();
if (!showTime) {
this.updateLines();
@@ -1113,13 +1112,31 @@ PlaneObject.prototype.processTrace = function() {
console.log(this.history_size + ' ' + points_in_trace);
};
+PlaneObject.prototype.updatePositionData = function(now, last, data, init) {
+ let newPos = this.updateTrack(now, last);
+
+ this.moveMarker |= newPos;
+ this.moveMarkerGL |= newPos;
+
+ if (globeIndex && newPos) {
+ let state = {};
+ state.now = this.position_time;
+ state.position = this.position;
+ state.altitude = this.altitude;
+ state.alt_rounded = this.alt_rounded;
+ state.speed = this.speed;
+ state.track = this.track;
+ state.rotation = this.rotation;
+ this.trace.push(state);
+ if (this.trace.length > 20) {
+ this.trace.slice(-15);
+ }
+ }
+}
// Update our data
PlaneObject.prototype.updateData = function(now, last, data, init) {
// get location data first, return early if only those are needed.
- this.updated = true;
- let newPos = false;
-
let isArray = Array.isArray(data);
// [.hex, .alt_baro, .gs, .track, .lat, .lon, .seen_pos, "mlat"/"tisb"/.type , .flight, .messages]
// 0 1 2 3 4 5 6 7 8 9
@@ -1142,12 +1159,10 @@ PlaneObject.prototype.updateData = function(now, last, data, init) {
this.last_message_time = now - seen;
// remember last known position even if stale
- // some logic for parsing 978 and 1090 aircraft.jsons at the same time.
- // more logic to not show or process mlat positions when filtered out.
- if (lat != null && seen_pos < (now - this.position_time + 2) && !(noMLAT && mlat)) {
+ // do not show or process mlat positions when filtered out.
+ if (lat != null && lon != null && !(noMLAT && mlat)) {
this.position = [lon, lat];
this.position_time = now - seen_pos;
- newPos = true;
}
// remember last known altitude even if stale
@@ -1262,6 +1277,7 @@ PlaneObject.prototype.updateData = function(now, last, data, init) {
if (isArray) {
this.messages = data[9];
+ this.updatePositionData(now, last, data, init);
return;
}
@@ -1385,24 +1401,12 @@ PlaneObject.prototype.updateData = function(now, last, data, init) {
this.request_rotation_from_track = true;
}
- if (globeIndex && newPos) {
- let state = {};
- state.now = this.position_time;
- state.position = this.position;
- state.altitude = this.altitude;
- state.alt_rounded = this.alt_rounded;
- state.speed = this.speed;
- state.track = this.track;
- state.rotation = this.rotation;
- this.trace.push(state);
- if (this.trace.length > 20) {
- this.trace.slice(-15);
- }
- }
-
this.checkForDB(data);
this.last = now;
+
+ this.updatePositionData(now, last, data, init);
+ return;
};
PlaneObject.prototype.updateTick = function(redraw) {
@@ -1420,29 +1424,22 @@ PlaneObject.prototype.updateFeatures = function(now, last, redraw) {
if (globeIndex && this.isFiltered())
return;
- let moved = false;
-
const lastVisible = this.visible;
this.visible = (!this.isFiltered() && this.checkVisible());
- if (this.updated) {
- moved = this.updateTrack(now, last);
- this.updated = false;
- }
-
if (this.visible) {
if (SelectedAllPlanes)
this.selected = true;
let lines = false;
- if (redraw || moved || lastVisible != this.visible)
+ if (redraw || lastVisible != this.visible)
lines = true;
if (lines)
this.updateLines();
- this.updateMarker(moved);
+ this.updateMarker();
if (this == SelectedPlane && FollowSelected && this.position)
OLMap.getView().setCenter(ol.proj.fromLonLat(this.position));
@@ -1469,7 +1466,7 @@ PlaneObject.prototype.clearMarker = function() {
};
// Update our marker on the map
-PlaneObject.prototype.updateMarker = function(moved) {
+PlaneObject.prototype.updateMarker = function() {
if (pTracks)
return;
if (!this.visible || this.position == null || this.isFiltered()) {
@@ -1494,25 +1491,26 @@ PlaneObject.prototype.updateMarker = function(moved) {
if (!this.shape)
console.log(baseMarkerKey);
}
+ this.scale = scaleFactor * this.baseScale;
this.strokeWidth = outlineWidth * ((this.selected && !SelectedAllPlanes && !onlySelected) ? 1.15 : 0.7) / this.baseScale;
if (!this.marker) {
this.marker = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
this.marker.hex = this.icao;
- } else if (moved) {
+ } else if (this.moveMarker) {
this.marker.setGeometry(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
}
+ this.moveMarker = false;
- if (webgl && !this.glMarker) {
- this.glMarker = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
- this.glMarker.hex = this.icao;
- } else if (webgl && moved) {
- this.glMarker.setGeometry(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
- }
+ if (webgl) {
+ if (!this.glMarker) {
+ this.glMarker = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
+ this.glMarker.hex = this.icao;
+ } else if (this.moveMarker) {
+ this.glMarker.setGeometry(new ol.geom.Point(ol.proj.fromLonLat(this.position)));
+ }
+ this.moveMarkerGL = false;
- this.updateIcon();
-
- if (webgl && this.glMarker) {
this.setMarkerRgb();
const iconRotation = this.shape.noRotate ? 0 : this.rotation;
this.glMarker.set('rotation', iconRotation * Math.PI / 180.0);
@@ -1522,6 +1520,8 @@ PlaneObject.prototype.updateMarker = function(moved) {
this.glMarker.set('dx', (getSpriteX(this.shape) + 1) / glImapWidth);
this.glMarker.set('dy', (getSpriteY(this.shape) + 1) / glImapHeight);
}
+
+ this.updateIcon();
if (!this.marker.visible) {
this.marker.visible = true;
PlaneIconFeatures.addFeature(this.marker);
@@ -2040,7 +2040,7 @@ PlaneObject.prototype.getAircraftData = function() {
refreshSelected();
}
- this.updateMarker(true);
+ this.updateMarker();
data = null;
}.bind(this));
diff --git a/html/script.js b/html/script.js
index 38bc862..61d487f 100644
--- a/html/script.js
+++ b/html/script.js
@@ -101,6 +101,7 @@ let overrideMapType = null;
let halloween = false;
let noRegOnly = false;
let triggerMapRefresh = false;
+let firstDraw = true;
let shareLink = '';
@@ -258,11 +259,15 @@ function processReceiverUpdate(data, init) {
processAircraft(data.aircraft[j], init, uat);
}
+function fetchSoon() {
+ clearTimeout(refreshId);
+ refreshId = setTimeout(fetchData, refreshInt());
+}
+
function fetchData() {
if (heatmap)
return;
- clearTimeout(refreshId);
- refreshId = setTimeout(fetchData, refreshInt());
+ fetchSoon();
//console.log("fetch");
if (showTrace)
return;
@@ -357,12 +362,13 @@ function fetchData() {
let ts = new Uint32Array(data.buffer, 0, 2);
data.now = ts[0] / 1000 + ts[1] * 4294967.296;
}
- if (data.now >= now || globeIndex) {
- //console.time("Process " + data.globeIndex);
- processReceiverUpdate(data);
- //console.timeEnd("Process " + data.globeIndex);
- }
- if (uat_data && uat_data.now > uat_now) {
+
+ //console.time("Process " + data.globeIndex);
+ processReceiverUpdate(data);
+ //console.timeEnd("Process " + data.globeIndex);
+ data = null;
+
+ if (uat_data) {
processReceiverUpdate(uat_data);
uat_data = null;
}
@@ -372,10 +378,8 @@ function fetchData() {
}
PendingFetches--;
- if (globeIndex) {
- clearTimeout(refreshId);
- refreshId = setTimeout(fetchData, refreshInt());
- }
+ if (globeIndex)
+ fetchSoon();
// Check for stale receiver data
if (last == now && !globeIndex) {
@@ -407,8 +411,7 @@ function fetchData() {
$("#update_error").css('display','block');
StaleReceiverCount++;
PendingFetches--;
- clearTimeout(refreshId);
- refreshId = setTimeout(fetchData, refreshInt());
+ fetchSoon();
});
}
}
@@ -1004,17 +1007,6 @@ function parseHistory() {
processReceiverUpdate(data, true);
}
- // update aircraft tracks
- if (data.uat_978 != "true") {
- for (let i = 0; i < PlanesOrdered.length; ++i) {
- let plane = PlanesOrdered[i];
- if (plane.dataSource == "uat")
- plane.updateTrack(uat_now, uat_last);
- else
- plane.updateTrack(now, last);
- }
- }
-
if (h==1) {
console.log("Applied history " + h + " from: "
+ (new Date(now * 1000)).toLocaleTimeString());
@@ -1111,14 +1103,6 @@ function startPage() {
else
setInterval(checkMovement, 30);
- // And kick off one refresh immediately.
- if (!heatmap && !pTracks)
- fetchData();
- if (replay) {
- //initReplay();
- //play(); // kick off first play
- }
-
loadFinished = true;
if (tempTrails)
@@ -1129,8 +1113,13 @@ function startPage() {
if (!heatmap)
$("#loader").addClass("hidden");
- refreshSelected();
- refreshHighlighted();
+ // And kick off one refresh immediately.
+ if (!heatmap && !pTracks)
+ fetchData();
+ if (replay) {
+ //initReplay();
+ //play(); // kick off first play
+ }
}
//
@@ -1742,7 +1731,7 @@ function refreshSelected() {
const selected = SelectedPlane;
if (SelectedPlane.position)
- SelectedPlane.updateMarker(true);
+ SelectedPlane.updateMarker();
if (selected.flight != selCall) {
selCall = selected.flight;
if (selected.flight && selected.flight.trim()) {
@@ -2708,7 +2697,7 @@ function selectPlaneByHex(hex, options) {
}
if (newPlane && newPlane.position) {
newPlane.updateLines();
- newPlane.updateMarker(true);
+ newPlane.updateMarker();
}
if (options.zoom == 'follow') {
@@ -3155,7 +3144,7 @@ function toggleLabels() {
enableLabels = !enableLabels;
localStorage['enableLabels'] = enableLabels;
for (let key in PlanesOrdered) {
- PlanesOrdered[key].updateMarker(false);
+ PlanesOrdered[key].updateMarker();
}
buttonActive('#L', enableLabels);
@@ -3172,7 +3161,7 @@ function toggleExtendedLabels() {
console.log(extendedLabels);
localStorage['extendedLabels'] = extendedLabels;
for (let key in PlanesOrdered) {
- PlanesOrdered[key].updateMarker(false);
+ PlanesOrdered[key].updateMarker();
}
buttonActive('#O', extendedLabels);
}
@@ -3521,10 +3510,10 @@ function checkMovement() {
checkMoveCenter[1] != center[1]
) {
noMovement = 0;
- }
- if (noMovement == 0)
checkFollow();
+ active();
+ }
checkMoveZoom = zoom;
checkMoveCenter[0] = center[0];
@@ -3539,7 +3528,6 @@ function checkMovement() {
// no zoom/pan inputs for 450 ms after a zoom/pan input
//
//console.time("fire!");
- active();
changeZoom();
changeCenter();
@@ -3560,6 +3548,13 @@ function checkRefresh() {
mapRefresh();
//console.timeEnd("refreshTable");
+
+ // work around an issue with webGL not showing planes on first mapRefresh
+ if (false && firstDraw) { // ... doesn't help?
+ mapRefresh();
+ firstDraw = false;
+ }
+
triggerMapRefresh = false;
changeZoom();
changeCenter();
@@ -4989,8 +4984,7 @@ function getInactive() {
function active() {
let now = new Date().getTime();
if ((now - lastActive) > 200 * 1000) {
- clearTimeout(refreshId);
- refreshId = setTimeout(fetchData, RefreshInterval);
+ fetchData();
}
lastActive = now;
}