/**
* GEOINT Tools: Sonnenstand-Rechner, Hoehenprofil, EXIF-Anzeige im VLM-Workflow.
*/
const GeointTools = {
_panel: null,
_elevMode: false,
_elevStart: null,
_elevHandler: null,
_elevLine: null,
_elevLabels: null,
// ============================================================
// Sonnenstand-Rechner
// ============================================================
showSunCalc: function() {
var panel = document.getElementById('geoint-panel');
if (!panel) return;
// Default: aktuelle Cursor-Position oder Kartenmitte
var cam = Globe.viewer.camera.positionCartographic;
var lat = cam ? Cesium.Math.toDegrees(cam.latitude).toFixed(4) : '50.0';
var lon = cam ? Cesium.Math.toDegrees(cam.longitude).toFixed(4) : '10.0';
var now = new Date().toISOString().slice(0, 16);
panel.innerHTML =
'
' +
'
SONNENSTAND
' +
'
' +
'
' +
'' +
'
' +
'
' +
'
' +
'
' +
'';
panel.style.display = 'block';
},
_calcSun: function() {
var lat = parseFloat(document.getElementById('sun-lat').value);
var lon = parseFloat(document.getElementById('sun-lon').value);
var dt = document.getElementById('sun-datetime').value;
if (isNaN(lat) || isNaN(lon) || !dt) return;
var resultEl = document.getElementById('sun-result');
resultEl.innerHTML = 'Berechne...
';
fetch('/api/geoint/sun-position', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ latitude: lat, longitude: lon, datetime_iso: dt + ':00Z' }),
})
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.detail) { resultEl.innerHTML = '' + data.detail + '
'; return; }
var dayIcon = data.is_daylight ? '(Tag)' : '(Nacht)';
var golden = data.golden_hour ? ' | Golden Hour' : '';
resultEl.innerHTML =
'' +
'
Azimut' + data.azimuth + '°
' +
'
Elevation' + data.elevation + '° ' + dayIcon + '
' +
'
Schattenrichtung' + data.shadow_direction + '°
' +
'
Schattenverhaeltnis' + (data.shadow_ratio !== null ? data.shadow_ratio + 'x Objekthoehe' : 'Kein Schatten') + '
' +
(golden ? '
Golden Hour aktiv
' : '') +
'
';
})
.catch(function(e) { resultEl.innerHTML = 'Fehler: ' + e.message + '
'; });
},
// ============================================================
// Hoehenprofil (2-Punkte-Tool)
// ============================================================
startElevation: function() {
if (this._elevMode) { this.stopElevation(); return; }
this._elevMode = true;
this._elevStart = null;
var panel = document.getElementById('geoint-panel');
if (panel) {
panel.innerHTML =
'' +
'
HOEHENPROFIL
' +
'
' +
'
' +
'Klicke Startpunkt auf den Globus
' +
'';
panel.style.display = 'block';
}
// Polyline + Labels fuer Visualisierung
this._elevLine = Globe.viewer.scene.primitives.add(new Cesium.PolylineCollection());
this._elevLabels = Globe.viewer.scene.primitives.add(new Cesium.LabelCollection());
var self = this;
this._elevHandler = new Cesium.ScreenSpaceEventHandler(Globe.viewer.scene.canvas);
this._elevHandler.setInputAction(function(click) {
var cart = Globe.viewer.scene.pickPosition(click.position);
if (!cart) {
var ray = Globe.viewer.scene.camera.getPickRay(click.position);
cart = Globe.viewer.scene.globe.pick(ray, Globe.viewer.scene);
}
if (!cart) return;
var c = Cesium.Cartographic.fromCartesian(cart);
var lat = Cesium.Math.toDegrees(c.latitude);
var lon = Cesium.Math.toDegrees(c.longitude);
if (!self._elevStart) {
self._elevStart = { lat: lat, lon: lon };
// Marker setzen
self._elevLabels.add({
position: cart, text: 'A',
font: '14px monospace', fillColor: Cesium.Color.fromCssColorString('#00ff88'),
outlineColor: Cesium.Color.BLACK, outlineWidth: 3,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
pixelOffset: new Cesium.Cartesian2(0, -14),
});
var statusEl = document.getElementById('elev-status');
if (statusEl) statusEl.textContent = 'Klicke Endpunkt auf den Globus';
} else {
// Endpunkt
self._elevLabels.add({
position: cart, text: 'B',
font: '14px monospace', fillColor: Cesium.Color.fromCssColorString('#ff5252'),
outlineColor: Cesium.Color.BLACK, outlineWidth: 3,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
pixelOffset: new Cesium.Cartesian2(0, -14),
});
// Linie
var startCart = Cesium.Cartesian3.fromDegrees(self._elevStart.lon, self._elevStart.lat, 100);
var endCart = Cesium.Cartesian3.fromDegrees(lon, lat, 100);
self._elevLine.add({
positions: [startCart, endCart], width: 2,
material: Cesium.Material.fromType('Color', { color: Cesium.Color.fromCssColorString('#00ff88').withAlpha(0.6) }),
});
self._fetchElevation(self._elevStart.lat, self._elevStart.lon, lat, lon);
if (self._elevHandler) { self._elevHandler.destroy(); self._elevHandler = null; }
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
},
_fetchElevation: function(sLat, sLon, eLat, eLon) {
var statusEl = document.getElementById('elev-status');
if (statusEl) statusEl.textContent = 'Berechne Hoehenprofil...';
fetch('/api/geoint/elevation-profile', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ start_lat: sLat, start_lon: sLon, end_lat: eLat, end_lon: eLon, samples: 80 }),
})
.then(function(r) { return r.json(); })
.then(function(data) {
if (data.detail) { if (statusEl) statusEl.textContent = 'Fehler: ' + data.detail; return; }
if (statusEl) statusEl.textContent = '';
GeointTools._renderElevation(data);
})
.catch(function(e) { if (statusEl) statusEl.textContent = 'Fehler: ' + e.message; });
},
_renderElevation: function(data) {
var resultEl = document.getElementById('elev-result');
if (!resultEl) return;
var s = data.stats;
var los = data.line_of_sight;
var losColor = los.clear ? '#00ff88' : '#ff5252';
var losText = los.clear ? 'Frei' : 'Blockiert';
// SVG Chart
var points = data.points;
var maxElev = s.elevation_max + 10;
var minElev = Math.max(0, s.elevation_min - 10);
var range = maxElev - minElev || 1;
var w = 280, h = 100;
var pathD = '';
for (var i = 0; i < points.length; i++) {
var x = (i / (points.length - 1)) * w;
var y = h - ((points[i].elevation - minElev) / range) * h;
pathD += (i === 0 ? 'M' : 'L') + x.toFixed(1) + ',' + y.toFixed(1);
}
// LOS line
var losY1 = h - ((points[0].elevation - minElev) / range) * h;
var losY2 = h - ((points[points.length - 1].elevation - minElev) / range) * h;
resultEl.innerHTML =
'' +
'' +
'
Distanz' + s.distance_km + ' km
' +
'
Sichtlinie' + losText + '
' +
'
Min / Max' + s.elevation_min + ' / ' + s.elevation_max + ' m
' +
'
Hoehendiff.' + s.elevation_diff + ' m
' +
'
Anstieg+' + s.total_ascent + ' m
' +
'
Abstieg-' + s.total_descent + ' m
' +
'
' +
'';
},
stopElevation: function() {
this._elevMode = false;
this._elevStart = null;
if (this._elevHandler) { this._elevHandler.destroy(); this._elevHandler = null; }
if (this._elevLine && Globe.viewer) { Globe.viewer.scene.primitives.remove(this._elevLine); this._elevLine = null; }
if (this._elevLabels && Globe.viewer) { Globe.viewer.scene.primitives.remove(this._elevLabels); this._elevLabels = null; }
this.closePanel();
},
closePanel: function() {
var panel = document.getElementById('geoint-panel');
if (panel) { panel.style.display = 'none'; panel.innerHTML = ''; }
},
};