- `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.
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
// /redux/api/fromDB/fetchLocationDevices.js
|
|
// das ist für Datasheet dropdownmenu Bereiche/Area-Name
|
|
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
|
|
// API-Fetch-Funktion für GIS Stations Static mit dynamischem URL-Parameter
|
|
export const fetchGisStationsStatic = createAsyncThunk("gisStationsStatic/fetchGisStationsStatic", async (_, { rejectWithValue }) => {
|
|
try {
|
|
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
|
|
|
// URL-Parameter aus der aktuellen Browser-URL holen
|
|
const params = new URLSearchParams(window.location.search);
|
|
const idMap = params.get("idMap") || "12"; // Standardwert "12", falls `idMap` nicht existiert
|
|
|
|
const url = `${apiBaseUrl}/GisStationsStatic?idMap=${idMap}`;
|
|
console.log("📡 API Request URL:", url);
|
|
|
|
const response = await fetch(url);
|
|
|
|
if (!response.ok) {
|
|
throw new Error("GisStationsStatic konnte nicht geladen werden");
|
|
}
|
|
|
|
const data = await response.json();
|
|
return data;
|
|
} catch (error) {
|
|
return rejectWithValue(error.message);
|
|
}
|
|
});
|
|
|
|
// Redux-Slice
|
|
const gisStationsStaticSlice = createSlice({
|
|
name: "gisStationsStatic",
|
|
initialState: {
|
|
data: null,
|
|
status: "idle",
|
|
error: null,
|
|
},
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder
|
|
.addCase(fetchGisStationsStatic.pending, (state) => {
|
|
state.status = "loading";
|
|
})
|
|
.addCase(fetchGisStationsStatic.fulfilled, (state, action) => {
|
|
state.status = "succeeded";
|
|
state.data = action.payload;
|
|
})
|
|
.addCase(fetchGisStationsStatic.rejected, (state, action) => {
|
|
state.status = "failed";
|
|
state.error = action.payload;
|
|
});
|
|
},
|
|
});
|
|
|
|
// Selector-Funktion
|
|
export const selectGisStationsStatic = (state) => state.gisStationsStatic.data;
|
|
|
|
export default gisStationsStaticSlice.reducer;
|