/** * Monitor-Layer: OSINT-Daten aus dem AegisSight Monitor. * Zeigt geoparsete Standorte mit Zusammenfassungen auf dem Globus. */ const MonitorLayer = { _viewer: null, _points: null, _labels: null, _interval: null, _count: 0, _data: [], _incidents: [], _handler: null, start(viewer) { if (this._points) return; this._viewer = viewer; this._points = viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection()); this._labels = viewer.scene.primitives.add(new Cesium.LabelCollection()); this._fetch(); var self = this; this._interval = setInterval(function() { self._fetch(); }, 120000); // Klick-Handler this._handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); this._handler.setInputAction(function(click) { self._onClick(click.position); }, Cesium.ScreenSpaceEventType.LEFT_CLICK); }, stop() { if (this._interval) { clearInterval(this._interval); this._interval = null; } if (this._handler) { this._handler.destroy(); this._handler = null; } if (this._points && this._viewer) { this._viewer.scene.primitives.remove(this._points); this._points = null; } if (this._labels && this._viewer) { this._viewer.scene.primitives.remove(this._labels); this._labels = null; } this._count = 0; this._data = []; this._incidents = []; }, _onClick(position) { if (!this._viewer || !this._data.length) return; var cartesian = this._viewer.scene.pickPosition(position); if (!cartesian) { var ray = this._viewer.scene.camera.getPickRay(position); cartesian = this._viewer.scene.globe.pick(ray, this._viewer.scene); } if (!cartesian) return; var carto = Cesium.Cartographic.fromCartesian(cartesian); var clickLat = Cesium.Math.toDegrees(carto.latitude); var clickLon = Cesium.Math.toDegrees(carto.longitude); // Naechsten Monitor-Punkt finden var best = null, bestDist = 999; for (var i = 0; i < this._data.length; i++) { var f = this._data[i]; var c = f.geometry.coordinates; var d = Math.abs(c[1] - clickLat) + Math.abs(c[0] - clickLon); if (d < bestDist) { bestDist = d; best = f; } } if (!best || bestDist > 2) return; var p = best.properties; var incident = null; for (var j = 0; j < this._incidents.length; j++) { if (this._incidents[j].id === p.incident_id) { incident = this._incidents[j]; break; } } // Info-Panel bauen var catColors = { primary: '#ff2222', secondary: '#ff8800', tertiary: '#4499ff', mentioned: '#888888' }; var catLabels = { primary: 'Hauptgeschehen', secondary: 'Reaktionen', tertiary: 'Beteiligte', mentioned: 'Erwaehnt' }; var catColor = catColors[p.category] || '#888'; var catLabel = catLabels[p.category] || p.category; var html = '
'; // Ort + Kategorie html += '
'; html += '' + (p.name || '?') + ''; if (p.country) html += ' (' + p.country + ')'; html += '
' + catLabel.toUpperCase() + ''; html += ' · ' + (p.article_count || 0) + ' Artikel'; html += '
'; // Headlines var headlines = p.headlines || []; if (headlines.length && headlines[0]) { html += '
'; for (var h = 0; h < Math.min(headlines.length, 3); h++) { if (headlines[h] && headlines[h].trim()) { html += '
• ' + headlines[h].trim().substring(0, 120) + '
'; } } html += '
'; } // Lage-Zusammenfassung if (incident && incident.summary) { html += '
'; html += '
' + (incident.title || 'LAGE').toUpperCase() + '
'; // Summary kuerzen und Markdown-Formatierung entfernen var summary = incident.summary .replace(/##?\s*/g, '') .replace(/\*\*/g, '') .replace(/\[(\d+)\]/g, '') .substring(0, 500); html += '
' + summary; if (incident.summary.length > 500) html += '...'; html += '
'; if (incident.updated_at) { html += '
Stand: ' + new Date(incident.updated_at).toLocaleString('de-DE') + '
'; } html += '
'; } html += '
'; this._viewer.trackedEntity = undefined; this._viewer.selectedEntity = new Cesium.Entity({ name: (p.name || '?') + ' — ' + (incident ? incident.title : 'Monitor'), description: html, }); }, _fetchForLage(lageId) { var self = this; var loadEl = document.getElementById('loading-monitor'); var statusEl = document.getElementById('status-monitor'); if (loadEl) loadEl.classList.add('active'); if (statusEl) { statusEl.textContent = 'Lade Lage-Daten...'; statusEl.classList.add('active'); } fetch('/api/monitor-feed?incident_id=' + lageId) .then(function(r) { return r.json(); }) .then(function(data) { self._data = data.features || []; self._incidents = data.incidents || []; self._count = self._data.length; self._render(); var title = self._incidents.length ? self._incidents[0].title : ''; if (statusEl) statusEl.textContent = self._count + ' Orte' + (title ? ' (' + title + ')' : ''); }) .catch(function(e) { console.warn('Monitor error:', e); if (statusEl) statusEl.textContent = 'Fehler'; }) .finally(function() { if (loadEl) loadEl.classList.remove('active'); setTimeout(function() { if (statusEl) statusEl.classList.remove('active'); }, 8000); }); }, _fetch() { var self = this; var loadEl = document.getElementById('loading-monitor'); var statusEl = document.getElementById('status-monitor'); if (loadEl) loadEl.classList.add('active'); if (statusEl) { statusEl.textContent = 'Lade Monitor-Daten...'; statusEl.classList.add('active'); } var lageId = (typeof Globe !== 'undefined' && Globe._currentLageId) ? Globe._currentLageId : ''; fetch('/api/monitor-feed' + (lageId ? '?incident_id=' + lageId : '')) .then(function(r) { return r.json(); }) .then(function(data) { self._data = data.features || []; self._incidents = data.incidents || []; self._count = self._data.length; self._render(); if (statusEl) { var incCount = self._incidents.length; statusEl.textContent = self._count + ' Orte aus ' + incCount + ' Lagen'; } }) .catch(function(e) { console.warn('Monitor error:', e); if (statusEl) statusEl.textContent = 'Fehler'; }) .finally(function() { if (loadEl) loadEl.classList.remove('active'); setTimeout(function() { if (statusEl) statusEl.classList.remove('active'); }, 8000); }); }, _render() { if (!this._points) return; this._points.removeAll(); this._labels.removeAll(); var colors = { 'primary': Cesium.Color.fromCssColorString('#ff2222'), 'secondary': Cesium.Color.fromCssColorString('#ff8800'), 'tertiary': Cesium.Color.fromCssColorString('#4499ff'), 'mentioned': Cesium.Color.fromCssColorString('#888888'), }; for (var i = 0; i < this._data.length; i++) { var f = this._data[i]; var coords = f.geometry.coordinates; var p = f.properties; var cat = p.category || 'mentioned'; var color = colors[cat] || colors.mentioned; var count = p.article_count || 1; var size = Math.min(Math.max(Math.sqrt(count) * 2.5, 4), 14); this._points.add({ position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 1000), pixelSize: size, color: color, outlineColor: Cesium.Color.WHITE.withAlpha(0.6), outlineWidth: 1, }); if (count >= 2) { this._labels.add({ position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 1000), text: (p.name || '?') + ' (' + count + ')', font: '11px sans-serif', fillColor: color, outlineColor: Cesium.Color.BLACK, outlineWidth: 3, style: Cesium.LabelStyle.FILL_AND_OUTLINE, pixelOffset: new Cesium.Cartesian2(0, -size - 6), scale: 0.8, horizontalOrigin: Cesium.HorizontalOrigin.CENTER, distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 3000000), }); } } }, };