feat: Fix Redux-Datenstruktur für GisStationsStaticDistrict und Bereichs-Dropdown

- `GisStationsStaticDistrict` wird jetzt korrekt aus Redux gelesen und verwendet `Points` als Array.
- Fehler `find is not a function` behoben durch Zugriff auf `GisStationsStaticDistrict.Points`.
- Sicherstellung, dass `Points` existiert, bevor darauf zugegriffen wird.
- Konsole-Logs für Debugging hinzugefügt, um leere oder ungültige Daten zu erkennen.
- Bereichsauswahl im Dropdown funktioniert jetzt korrekt und fliegt zur gewählten Station auf der Karte.

 Tested: Dropdown zeigt jetzt die `Area_Name`-Werte und `map.flyTo()` funktioniert korrekt.
This commit is contained in:
Ismail Ali
2025-03-08 12:10:21 +01:00
parent 8399a957b5
commit 806347f0dd
12 changed files with 201 additions and 24 deletions

View File

@@ -49,19 +49,31 @@ export const useMapComponentState = () => {
const fetchDeviceData = async () => {
try {
const response = await fetch("/api/talas5/location_device");
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
// Sicherstellen, dass die Antwort JSON ist
const contentType = response.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
throw new Error("❌ Ungültige Antwort: Kein JSON erhalten");
}
// URL-Parameter aus der aktuellen Browser-URL holen
const params = new URLSearchParams(window.location.search);
const idMap = params.get("idMap") || "12"; // Fallback auf "12" falls nicht gesetzt
const data = await response.json();
setLocationDeviceData(data);
const url = `${apiBaseUrl}/GisStationsStatic?idMap=${idMap}`;
if (data.length > 0) {
setDeviceName(data[0].name);
//console.log("📡 API Request URL:", url);
const response = await fetch(url);
//console.log("📡 API Response Status:", response.status);
// console.log("📡 API Response Headers:", response.headers.get("content-type"));
const text = await response.text();
//console.log("📡 API Response Text:", text);
// JSON manuell parsen, falls die API keinen JSON-Header sendet
const data = JSON.parse(text);
setLocationDeviceData(data.Points || []);
if (data.Points && data.Points.length > 0) {
setDeviceName(data.Points[0].LD_Name);
}
} catch (error) {
console.error("❌ Fehler beim Abrufen der Gerätedaten:", error);