- Fetch-Logik für GIS-Daten aus MapComponent.js ausgelagert. - Neuer Hook: useFetchWebServiceMap im hooks-Verzeichnis hinzugefügt. - Modularisierung und Wiederverwendbarkeit verbessert.
88 lines
2.4 KiB
JavaScript
88 lines
2.4 KiB
JavaScript
import { useEffect } from "react";
|
|
import {
|
|
fetchGisStationsStaticDistrict,
|
|
fetchGisStationsStatusDistrict,
|
|
fetchGisStationsMeasurements,
|
|
fetchGisSystemStatic,
|
|
} from "../services/fetchData";
|
|
|
|
export const useFetchWebServiceMap = (
|
|
dispatch,
|
|
mapGisStationsStaticDistrictUrl,
|
|
mapGisStationsStatusDistrictUrl,
|
|
mapGisStationsMeasurementsUrl,
|
|
mapGisSystemStaticUrl,
|
|
setGisStationsStatusDistrict,
|
|
setGisStationsMeasurements,
|
|
setGisSystemStatic,
|
|
setGisSystemStaticLoaded
|
|
) => {
|
|
useEffect(() => {
|
|
const fetchWebServiceMap = async () => {
|
|
try {
|
|
// Zähler für externe API-Aufrufe in localStorage speichern
|
|
let requestCount = localStorage.getItem("fetchWebServiceMap") || 0;
|
|
requestCount = parseInt(requestCount, 10);
|
|
|
|
const fetchOptions = {
|
|
method: "GET",
|
|
headers: {
|
|
Connection: "close",
|
|
},
|
|
};
|
|
|
|
// Fetch GIS Stations Static District
|
|
await fetchGisStationsStaticDistrict(
|
|
mapGisStationsStaticDistrictUrl,
|
|
dispatch,
|
|
fetchOptions
|
|
);
|
|
requestCount++;
|
|
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
|
|
// Fetch GIS Stations Status District
|
|
await fetchGisStationsStatusDistrict(
|
|
mapGisStationsStatusDistrictUrl,
|
|
setGisStationsStatusDistrict,
|
|
fetchOptions
|
|
);
|
|
requestCount++;
|
|
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
|
|
// Fetch GIS Stations Measurements
|
|
await fetchGisStationsMeasurements(
|
|
mapGisStationsMeasurementsUrl,
|
|
setGisStationsMeasurements,
|
|
fetchOptions
|
|
);
|
|
requestCount++;
|
|
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
|
|
// Fetch GIS System Static
|
|
await fetchGisSystemStatic(
|
|
mapGisSystemStaticUrl,
|
|
setGisSystemStatic,
|
|
setGisSystemStaticLoaded,
|
|
fetchOptions
|
|
);
|
|
requestCount++;
|
|
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
}
|
|
};
|
|
|
|
fetchWebServiceMap();
|
|
}, [
|
|
dispatch,
|
|
mapGisStationsStaticDistrictUrl,
|
|
mapGisStationsStatusDistrictUrl,
|
|
mapGisStationsMeasurementsUrl,
|
|
mapGisSystemStaticUrl,
|
|
setGisStationsStatusDistrict,
|
|
setGisStationsMeasurements,
|
|
setGisSystemStatic,
|
|
setGisSystemStaticLoaded,
|
|
]);
|
|
};
|