From a983780b64302a71665a7832fea962caebbc4c3d Mon Sep 17 00:00:00 2001 From: ISA Date: Tue, 11 Jun 2024 15:09:35 +0200 Subject: [PATCH] stash: linesColors --- components/MapComponent.js | 22 +++++++++++++++++++++- pages/api/linesColorApi.js | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/MapComponent.js b/components/MapComponent.js index e9b3e4801..3cafc539a 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -48,6 +48,7 @@ const plusRoundIcon = L.icon({ }); const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { + const [linesColors, setLinesColors] = useState({}); // Zustand für die Farben der Linien /* path.includes("critical") || // Priorität 1 path.includes("major") || // Priorität 2 @@ -85,8 +86,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // Open the modal or any other logic }; const [lineColor, setLineColor] = useState(); + const [lineColors, setLineColors] = useState({}); //-------------------------------------------linesColorAPI - useEffect(() => { + /* useEffect(() => { const fetchlinesColor = async () => { try { const response = await fetch("/api/linesColorApi"); @@ -104,6 +106,24 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { } }; fetchlinesColor(); + }, []); */ + //------------------------------------------- + useEffect(() => { + const fetchlinesColor = async () => { + try { + const response = await fetch("/api/linesColorApi"); + const data = await response.json(); + console.log("linesColorAPI:", data); + const colors = data.linesColor.Statis.map((item) => ({ + id: item.IdModul, + color: item.Co, + })); + setLinesColors(colors); // Aktualisieren Sie Ihren Status mit einem Array von Farben + } catch (error) { + console.error("Fehler beim Abrufen der linesColorApi Daten:", error); + } + }; + fetchlinesColor(); }, []); //------------------------------------------- diff --git a/pages/api/linesColorApi.js b/pages/api/linesColorApi.js index db163f163..21630df39 100644 --- a/pages/api/linesColorApi.js +++ b/pages/api/linesColorApi.js @@ -8,7 +8,7 @@ export default function handler(req, res) { IdModul: 1, Na: "system", Le: 4, - Co: "#00FFFF", + Co: "#F00FFF", Me: "Eingang DE04 kommend", Feld: 3, Icon: 0,