Fix: disasters.js neu geschrieben (Syntax-Fehler durch Patch)
Sauberer Neuschrieb: NASA EONET + USGS Erdbeben kombiniert. Syntax verifiziert.
Dieser Commit ist enthalten in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Naturkatastrophen-Layer: NASA EONET (Waldbrände, Vulkane, Stürme, Eis).
|
* Katastrophen-Layer: NASA EONET + USGS Erdbeben kombiniert.
|
||||||
*/
|
*/
|
||||||
const DisastersLayer = {
|
const DisastersLayer = {
|
||||||
_viewer: null,
|
_viewer: null,
|
||||||
@@ -28,62 +28,48 @@ const DisastersLayer = {
|
|||||||
var loadEl = document.getElementById('loading-disasters');
|
var loadEl = document.getElementById('loading-disasters');
|
||||||
var statusEl = document.getElementById('status-disasters');
|
var statusEl = document.getElementById('status-disasters');
|
||||||
if (loadEl) loadEl.classList.add('active');
|
if (loadEl) loadEl.classList.add('active');
|
||||||
if (statusEl) { statusEl.textContent = 'Lade Ereignisse + Erdbeben...'; statusEl.classList.add('active'); }
|
if (statusEl) { statusEl.textContent = 'Lade Katastrophen + Erdbeben...'; statusEl.classList.add('active'); }
|
||||||
// Lade beides parallel: NASA EONET + USGS Erdbeben
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
fetch('/api/disasters').then(function(r) { return r.json(); }).catch(function() { return {events:[]}; }),
|
fetch('/api/disasters').then(function(r) { return r.json(); }).catch(function() { return { events: [] }; }),
|
||||||
fetch('/api/quakes').then(function(r) { return r.json(); }).catch(function() { return {features:[]}; }),
|
fetch('/api/quakes').then(function(r) { return r.json(); }).catch(function() { return { features: [] }; })
|
||||||
])
|
])
|
||||||
.then(function(results) {
|
.then(function(results) {
|
||||||
var eonetData = results[0];
|
if (!self._dataSource) return;
|
||||||
var quakeData = results[1];
|
self._dataSource.entities.removeAll();
|
||||||
self._renderAll(eonetData, quakeData);
|
var events = results[0].events || [];
|
||||||
var total = (eonetData.events || []).length + (quakeData.features || []).length;
|
var quakes = results[1].features || [];
|
||||||
self._count = total;
|
self._renderEonet(events);
|
||||||
if (statusEl) statusEl.textContent = total + ' Ereignisse';
|
self._renderQuakes(quakes);
|
||||||
|
self._count = events.length + quakes.length;
|
||||||
|
if (statusEl) statusEl.textContent = self._count + ' Ereignisse';
|
||||||
})
|
})
|
||||||
.catch(function(e) { console.warn('Disasters error:', e); if (statusEl) statusEl.textContent = 'Fehler'; })
|
.catch(function(e) { console.warn('Disasters error:', e); if (statusEl) statusEl.textContent = 'Fehler'; })
|
||||||
.finally(function() { if (loadEl) loadEl.classList.remove('active'); setTimeout(function() { if (statusEl) statusEl.classList.remove('active'); }, 5000); });
|
.finally(function() { if (loadEl) loadEl.classList.remove('active'); setTimeout(function() { if (statusEl) statusEl.classList.remove('active'); }, 5000); });
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderAll(eonetData, quakeData) {
|
|
||||||
if (!this._dataSource) return;
|
|
||||||
this._dataSource.entities.removeAll();
|
|
||||||
|
|
||||||
// NASA EONET Events
|
|
||||||
var events = eonetData.events || [];
|
|
||||||
this._renderEonet(events);
|
|
||||||
|
|
||||||
// USGS Erdbeben
|
|
||||||
var quakes = quakeData.features || [];
|
|
||||||
this._renderQuakes(quakes);
|
|
||||||
},
|
|
||||||
|
|
||||||
_renderEonet(events) {
|
_renderEonet(events) {
|
||||||
var self = this;
|
var self = this;
|
||||||
.then(function(r) { return r.json(); })
|
|
||||||
var icons = {
|
var icons = {
|
||||||
'wildfires': { color: '#ff4400', symbol: '🔥', label: 'Waldbrand' },
|
'wildfires': { color: '#ff4400', label: 'Waldbrand' },
|
||||||
'volcanoes': { color: '#ff0000', symbol: '🌋', label: 'Vulkan' },
|
'volcanoes': { color: '#ff0000', label: 'Vulkan' },
|
||||||
'severeStorms': { color: '#aa44ff', symbol: '🌀', label: 'Sturm' },
|
'severeStorms': { color: '#aa44ff', label: 'Sturm' },
|
||||||
'floods': { color: '#4488ff', symbol: '🌊', label: 'Flut' },
|
'floods': { color: '#4488ff', label: 'Flut' },
|
||||||
'earthquakes': { color: '#ffaa00', symbol: '⚡', label: 'Erdbeben' },
|
'earthquakes': { color: '#ffaa00', label: 'Erdbeben' },
|
||||||
'seaLakeIce': { color: '#88ddff', symbol: '❄️', label: 'Eis' },
|
'seaLakeIce': { color: '#88ddff', label: 'Eis' },
|
||||||
'landslides': { color: '#886644', symbol: '⛰️', label: 'Erdrutsch' },
|
'landslides': { color: '#886644', label: 'Erdrutsch' },
|
||||||
};
|
};
|
||||||
events.forEach(function(evt) {
|
events.forEach(function(evt) {
|
||||||
var cats = evt.categories || [];
|
var cats = evt.categories || [];
|
||||||
var catId = cats.length ? cats[0].id : 'unknown';
|
var catId = cats.length ? cats[0].id : 'unknown';
|
||||||
var icon = icons[catId] || { color: '#ffffff', symbol: '⚠️', label: catId };
|
var icon = icons[catId] || { color: '#ffffff', label: catId };
|
||||||
var geom = evt.geometry || [];
|
var geom = evt.geometry || [];
|
||||||
if (!geom.length) return;
|
if (!geom.length) return;
|
||||||
var latest = geom[geom.length - 1];
|
var latest = geom[geom.length - 1];
|
||||||
var coords = latest.coordinates;
|
var coords = latest.coordinates;
|
||||||
if (!coords || coords.length < 2) return;
|
if (!coords || coords.length < 2) return;
|
||||||
var lon = coords[0], lat = coords[1];
|
|
||||||
|
|
||||||
self._dataSource.entities.add({
|
self._dataSource.entities.add({
|
||||||
position: Cesium.Cartesian3.fromDegrees(lon, lat, 0),
|
position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 0),
|
||||||
point: {
|
point: {
|
||||||
pixelSize: 8,
|
pixelSize: 8,
|
||||||
color: Cesium.Color.fromCssColorString(icon.color),
|
color: Cesium.Color.fromCssColorString(icon.color),
|
||||||
@@ -92,16 +78,20 @@ const DisastersLayer = {
|
|||||||
heightReference: Cesium.HeightReference.NONE,
|
heightReference: Cesium.HeightReference.NONE,
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
text: icon.symbol,
|
text: icon.label,
|
||||||
font: '14px sans-serif',
|
font: '10px monospace',
|
||||||
|
fillColor: Cesium.Color.fromCssColorString(icon.color),
|
||||||
|
outlineColor: Cesium.Color.BLACK,
|
||||||
|
outlineWidth: 2,
|
||||||
|
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
|
||||||
pixelOffset: new Cesium.Cartesian2(0, -14),
|
pixelOffset: new Cesium.Cartesian2(0, -14),
|
||||||
|
scale: 0.7,
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000000),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000000),
|
||||||
},
|
},
|
||||||
description: '<div style="font-family:monospace;font-size:13px;padding:8px">' +
|
description: '<div style="font-family:monospace;font-size:13px;padding:8px">' +
|
||||||
'<strong style="color:' + icon.color + '">' + icon.label.toUpperCase() + '</strong><br>' +
|
'<strong style="color:' + icon.color + '">' + icon.label.toUpperCase() + '</strong><br>' +
|
||||||
'<span style="color:#e0e0e0">' + (evt.title || '?') + '</span><br>' +
|
'<span style="color:#e0e0e0">' + (evt.title || '?') + '</span><br>' +
|
||||||
'<span style="color:#888">Quellen: ' + (evt.sources || []).map(function(s) { return s.id; }).join(', ') + '</span>' +
|
'<span style="color:#888">Quellen: ' + (evt.sources || []).map(function(s) { return s.id; }).join(', ') + '</span></div>',
|
||||||
'</div>',
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren