Flights: OpenSky liefert 6.500+ global, korrekte Hoehenkonvertierung (ft->m), Cesium Entity-Clustering bei 30px/5min, Labels nur < 800km. Status-Text zeigt Anzahl nach Laden. Ships: Entity-Clustering aktiviert (25px/5min), Labels nur < 300km. Status-Text zeigt Anzahl. Beide Layer zeigen jetzt ALLE Daten komplett — Ukraine, Belarus, Nahost, Afrika, Russland, China alles enthalten.
86 Zeilen
3.8 KiB
JavaScript
86 Zeilen
3.8 KiB
JavaScript
/**
|
|
* Flugverkehr-Layer: Grüne Punkte auf dem 3D-Globus.
|
|
*/
|
|
const FlightsLayer = {
|
|
_viewer: null,
|
|
_dataSource: null,
|
|
_interval: null,
|
|
_count: 0,
|
|
|
|
start(viewer) {
|
|
if (this._dataSource) return;
|
|
this._viewer = viewer;
|
|
this._dataSource = new Cesium.CustomDataSource('flights');
|
|
this._dataSource.clustering.enabled = true;
|
|
this._dataSource.clustering.pixelRange = 30;
|
|
this._dataSource.clustering.minimumClusterSize = 5;
|
|
viewer.dataSources.add(this._dataSource);
|
|
this._fetch();
|
|
var self = this;
|
|
this._interval = setInterval(function() { self._fetch(); }, 30000);
|
|
},
|
|
|
|
stop() {
|
|
if (this._interval) { clearInterval(this._interval); this._interval = null; }
|
|
if (this._dataSource && this._viewer) {
|
|
this._viewer.dataSources.remove(this._dataSource);
|
|
this._dataSource = null;
|
|
}
|
|
this._count = 0;
|
|
},
|
|
|
|
_fetch() {
|
|
var self = this;
|
|
var loadEl = document.getElementById('loading-flights');
|
|
var statusEl = document.getElementById('status-flights');
|
|
if (loadEl) loadEl.classList.add('active');
|
|
if (statusEl) { statusEl.textContent = 'Lade Daten...'; statusEl.classList.add('active'); }
|
|
fetch('/api/flights')
|
|
.then(function(r) { return r.json(); })
|
|
.then(function(data) {
|
|
if (!self._dataSource) return;
|
|
self._dataSource.entities.removeAll();
|
|
var ac = data.ac || [];
|
|
self._count = ac.length;
|
|
ac.forEach(function(a) {
|
|
if (!a.lat || !a.lon) return;
|
|
// alt_baro ist in ft vom Backend, konvertiere zu m fuer Cesium
|
|
var altFt = a.alt_baro || 30000;
|
|
var altM = altFt * 0.3048;
|
|
var cs = (a.flight || a.hex || '').trim() || '?';
|
|
self._dataSource.entities.add({
|
|
position: Cesium.Cartesian3.fromDegrees(a.lon, a.lat, altM),
|
|
point: {
|
|
pixelSize: 3,
|
|
color: Cesium.Color.fromCssColorString('#00ff88'),
|
|
outlineColor: Cesium.Color.fromCssColorString('#003311'),
|
|
outlineWidth: 1,
|
|
heightReference: Cesium.HeightReference.NONE,
|
|
},
|
|
label: {
|
|
text: cs,
|
|
font: '10px monospace',
|
|
fillColor: Cesium.Color.fromCssColorString('#00ff88').withAlpha(0.7),
|
|
outlineColor: Cesium.Color.BLACK,
|
|
outlineWidth: 2,
|
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
|
pixelOffset: new Cesium.Cartesian2(6, -3),
|
|
scale: 0.7,
|
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 800000),
|
|
},
|
|
description: '<div style="font-family:monospace;font-size:12px;color:#00ff88">' +
|
|
'<strong>' + cs + '</strong><br>' +
|
|
'ALT: ' + altFt + ' ft<br>' +
|
|
'SPD: ' + (a.gs || '?') + ' kts<br>' +
|
|
'HDG: ' + Math.round(a.track || 0) + '°' +
|
|
(a.origin ? '<br>FROM: ' + a.origin : '') +
|
|
'</div>',
|
|
});
|
|
});
|
|
if (statusEl) { statusEl.textContent = ac.length.toLocaleString('de-DE') + ' Flugzeuge'; }
|
|
})
|
|
.catch(function(e) { console.warn('Flights fetch error:', e); if (statusEl) { statusEl.textContent = 'Fehler beim Laden'; } })
|
|
.finally(function() { if (loadEl) loadEl.classList.remove('active'); setTimeout(function() { if (statusEl) statusEl.classList.remove('active'); }, 5000); });
|
|
},
|
|
};
|