- Die Logik zum Abrufen und Zeichnen von Linien wurde in den neuen Hook `useDrawLines` ausgelagert. - Dies verbessert die Übersichtlichkeit in `MapComponent.js` und ermöglicht eine einfachere Wiederverwendung und Wartung. - Der neue Hook befindet sich im Verzeichnis `hooks/layers/`.
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import { useEffect } from "react";
|
|
const useDrawLines = (setLinePositions) => {
|
|
// Linien auf die Karte zeichnen
|
|
useEffect(() => {
|
|
const endpoint = "/api/talas_v5_DB/gisLines/readGisLines";
|
|
//const endpoint = "http://localhost/talas5/ClientData/WebServiceMap.asmx/GisLinesStatus?idMap=10";
|
|
fetch(endpoint)
|
|
.then((response) => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then((data) => {
|
|
const newLinePositions = data.map((item) => {
|
|
//console.log("item.idLD", item.idLD);
|
|
//console.log("item.idModul", item.idModul);
|
|
|
|
if (item.points && Array.isArray(item.points)) {
|
|
return {
|
|
coordinates: item.points.map((point) => [point.x, point.y]),
|
|
idModul: item.idModul,
|
|
idLD: item.idLD,
|
|
};
|
|
} else {
|
|
throw new Error("Points missing or not an array");
|
|
}
|
|
});
|
|
setLinePositions(newLinePositions);
|
|
})
|
|
.catch((error) => {
|
|
console.error("Error fetching data:", error.message);
|
|
});
|
|
}, []);
|
|
};
|
|
|
|
export default useDrawLines;
|