Stationnamen sind richtig
This commit is contained in:
@@ -17,11 +17,15 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
const data2 = await response2.json();
|
||||
console.log("GIS Linien Daten:", data2);
|
||||
|
||||
// Abrufen der Namen basierend auf idLD
|
||||
const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/station/getAllStationsNames`);
|
||||
const namesData = await response3.json();
|
||||
console.log("Namen der Linien:", namesData);
|
||||
|
||||
const colorsByModule = {};
|
||||
const newTooltipContents = {};
|
||||
const valueMap = {};
|
||||
|
||||
// Hier führen wir die Gruppierung durch und loggen sie
|
||||
logGroupedData(data1.Statis);
|
||||
|
||||
data1.Statis.forEach((statis) => {
|
||||
@@ -33,11 +37,9 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
schleifenwert: undefined,
|
||||
};
|
||||
}
|
||||
// Füge Messwert hinzu, falls es noch nicht vorhanden ist
|
||||
if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
|
||||
valueMap[key].messwert = statis.Value;
|
||||
}
|
||||
// Füge Schleifenwert hinzu, falls es noch nicht vorhanden ist
|
||||
if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
|
||||
valueMap[key].schleifenwert = statis.Value;
|
||||
}
|
||||
@@ -50,14 +52,19 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
|
||||
if (matchingLine) {
|
||||
const prioColor = statis.PrioColor === "#ffffff" ? "green" : statis.PrioColor;
|
||||
const key = `${matchingLine.idLD}-${matchingLine.idModul}`;
|
||||
const key = `${matchingLine.idLD}-${matchingLine.idModul}`; // Sicherstellen, dass der Key eindeutig ist
|
||||
const values = valueMap[key];
|
||||
|
||||
if (!values) {
|
||||
console.error(`No values found for key: ${key}`); // Debug: Überprüfe, ob Werte existieren
|
||||
return;
|
||||
}
|
||||
|
||||
const messageDisplay = values.messages.map((msg) => (msg ? `<span class="inline-block text-gray-800">${msg}</span><br>` : "")).join("");
|
||||
const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
|
||||
|
||||
colorsByModule[matchingLine.idModul] = prioColor;
|
||||
newTooltipContents[matchingLine.idModul] = `
|
||||
colorsByModule[key] = prioColor; // Stelle sicher, dass der Key richtig verwendet wird
|
||||
newTooltipContents[key] = `
|
||||
<div class="bg-white rounded-lg m-0 p-2 w-[210px]">
|
||||
<span class="text-lg font-semibold text-gray-900">${statis.ModulName || "Unknown"}</span>
|
||||
<br>
|
||||
@@ -65,6 +72,8 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
<br>
|
||||
<span class="text-md font-bold text-gray-800">Slot: ${statis.Modul || "N/A"}</span>
|
||||
<br>
|
||||
<span class="text-md font-bold text-gray-800">Line Name: ${namesData[matchingLine.idLD] || "N/A"}</span> <!-- Zeige den Namen -->
|
||||
<br>
|
||||
<div style="max-width: 100%; overflow-wrap: break-word; word-break: break-word; white-space: normal;">
|
||||
<span class="inline-block w-2 h-2 rounded-full mr-2" style="background-color: ${prioColor || "#000000"};"></span>
|
||||
${messageDisplay}
|
||||
@@ -92,8 +101,6 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
return { lineColors, tooltipContents };
|
||||
};
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Funktion zum Loggen der gruppierten und aggregierten Daten
|
||||
function logGroupedData(statisList) {
|
||||
const grouped = statisList.reduce((acc, item) => {
|
||||
const { IdLD, Modul, Level, PrioColor, PrioName, ModulName, ModulTyp, Message, DpName, Value } = item;
|
||||
@@ -106,28 +113,25 @@ function logGroupedData(statisList) {
|
||||
acc[IdLD][Modul] = {
|
||||
ModulName: ModulName || "Unknown",
|
||||
ModulTyp: ModulTyp || "N/A",
|
||||
TotalLevel: Level, // Verwende den ursprünglichen Level-Wert
|
||||
TotalLevel: Level,
|
||||
PrioColors: new Set(),
|
||||
PrioNames: new Set(),
|
||||
Messages: [],
|
||||
Messwert: undefined, // Neuer Wert für Messwert
|
||||
Schleifenwert: undefined, // Neuer Wert für Schleifenwert
|
||||
Messwert: undefined,
|
||||
Schleifenwert: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// Speichere die Prioritätsinformationen und Nachrichten
|
||||
acc[IdLD][Modul].PrioColors.add(PrioColor);
|
||||
acc[IdLD][Modul].PrioNames.add(PrioName);
|
||||
if (Message && Message !== "?") {
|
||||
acc[IdLD][Modul].Messages.push(Message);
|
||||
}
|
||||
|
||||
// Füge Messwert hinzu, wenn DpName "_Messwert" enthält und es noch nicht gesetzt ist
|
||||
if (DpName.endsWith("_Messwert") && !acc[IdLD][Modul].Messwert) {
|
||||
acc[IdLD][Modul].Messwert = Value;
|
||||
}
|
||||
|
||||
// Füge Schleifenwert hinzu, wenn DpName "_Schleifenwert" enthält und es noch nicht gesetzt ist
|
||||
if (DpName.endsWith("_Schleifenwert") && !acc[IdLD][Modul].Schleifenwert) {
|
||||
acc[IdLD][Modul].Schleifenwert = Value;
|
||||
}
|
||||
@@ -135,21 +139,20 @@ function logGroupedData(statisList) {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Formatierte Ausgabe der gruppierten Daten, Entfernen von Modulen ohne Namen und Stationen mit leeren Arrays
|
||||
const formattedData = {};
|
||||
Object.entries(grouped).forEach(([stationId, modules]) => {
|
||||
const filteredModules = Object.entries(modules)
|
||||
.filter(([modulId, data]) => data.ModulName !== "?") // Filtere Module ohne Namen heraus
|
||||
.filter(([modulId, data]) => data.ModulName !== "?")
|
||||
.map(([modulId, data]) => ({
|
||||
Modul: modulId,
|
||||
ModulName: data.ModulName,
|
||||
ModulTyp: data.ModulTyp,
|
||||
TotalLevel: data.TotalLevel, // Verwende den ursprünglichen Level
|
||||
TotalLevel: data.TotalLevel,
|
||||
PrioColors: Array.from(data.PrioColors).join(", "),
|
||||
PrioNames: Array.from(data.PrioNames).join(", "),
|
||||
Messages: data.Messages.join(" | "),
|
||||
Messwert: data.Messwert, // Füge Messwert hinzu
|
||||
Schleifenwert: data.Schleifenwert, // Füge Schleifenwert hinzu
|
||||
Messwert: data.Messwert,
|
||||
Schleifenwert: data.Schleifenwert,
|
||||
}));
|
||||
|
||||
if (filteredModules.length > 0) {
|
||||
@@ -160,9 +163,4 @@ function logGroupedData(statisList) {
|
||||
console.log("Aggregierte und gruppierte Daten (gefiltert):", formattedData);
|
||||
}
|
||||
|
||||
// Beispielaufruf der Funktion
|
||||
// const statisList = data1.Statis; // Verwende die Liste aus deinem API-Aufruf
|
||||
// logGroupedData(statisList);
|
||||
|
||||
//----------------------------------------------------------
|
||||
export default useLineData;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/talas_v5_DB/station/getStationNameByIdLD.js
|
||||
// /pages/api/talas_v5_DB/station/getAllStationsNames.js
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Verbindungspool-Konfiguration
|
||||
@@ -20,10 +20,22 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
// Verwenden des Verbindungspools, um die Abfrage auszuführen
|
||||
const [results] = await pool.query("SELECT * FROM location_device");
|
||||
// Abrufen aller idLD und ihrer Namen
|
||||
const [results] = await pool.query("SELECT idLD, name FROM location_device");
|
||||
|
||||
res.status(200).json(results);
|
||||
if (results.length === 0) {
|
||||
return res.status(404).json({ error: "No data found" });
|
||||
}
|
||||
|
||||
// Struktur der Antwort anpassen
|
||||
const namesMap = results.reduce((map, { idLD, name }) => {
|
||||
if (!map[idLD]) {
|
||||
map[idLD] = name; // Stelle sicher, dass hier keine Duplikate oder Überschreibungen entstehen
|
||||
}
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
res.status(200).json(namesMap);
|
||||
} catch (err) {
|
||||
console.error("Fehler beim Abrufen der Daten:", err);
|
||||
res.status(500).json({ error: "Error retrieving data from the database" });
|
||||
@@ -147,10 +147,10 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
newCoordinates[index] = [newCoords.lat, newCoords.lng];
|
||||
|
||||
const updatedPolyline = L.polyline(newCoordinates, {
|
||||
color: lineColors[lineData.idModul] || "#000000",
|
||||
color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
|
||||
}).addTo(map);
|
||||
|
||||
updatedPolyline.bindTooltip(tooltipContents[lineData.idModul] || "Standard-Tooltip-Inhalt", {
|
||||
updatedPolyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
|
||||
permanent: false,
|
||||
direction: "auto",
|
||||
});
|
||||
@@ -207,7 +207,7 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
const newCoordinates = [...lineData.coordinates];
|
||||
newCoordinates[index] = [newCoords.lat, newCoords.lng];
|
||||
|
||||
removeMarker(marker, lineData, currentZoom, currentCenter); // Pass currentZoom and currentCenter here
|
||||
removeMarker(marker, lineData, currentZoom, currentCenter);
|
||||
polylines[lineIndex].remove();
|
||||
lineData.coordinates = newCoordinates;
|
||||
},
|
||||
@@ -224,7 +224,7 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
});
|
||||
|
||||
const polyline = L.polyline(lineData.coordinates, {
|
||||
color: lineColors[lineData.idModul] || "#000000",
|
||||
color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000",
|
||||
contextmenu: true,
|
||||
contextmenuItems: [
|
||||
{
|
||||
@@ -236,8 +236,8 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
}
|
||||
const newPoint = e.latlng;
|
||||
const closestPoints = findClosestPoints(lineData.coordinates, newPoint, map);
|
||||
insertNewMarker(closestPoints, newPoint, lineData, map); // Make sure this is defined
|
||||
redrawPolyline(lineData, lineColors, tooltipContents, map); // Add missing parameters
|
||||
insertNewMarker(closestPoints, newPoint, lineData, map);
|
||||
redrawPolyline(lineData, lineColors, tooltipContents, map);
|
||||
window.location.reload();
|
||||
},
|
||||
},
|
||||
@@ -250,10 +250,10 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents,
|
||||
|
||||
polyline.on("mouseout", (e) => {
|
||||
polyline.setStyle({ weight: 3 });
|
||||
polyline.setStyle({ color: lineColors[lineData.idModul] || "#000000" });
|
||||
polyline.setStyle({ color: lineColors[`${lineData.idLD}-${lineData.idModul}`] || "#000000" });
|
||||
});
|
||||
|
||||
polyline.bindTooltip(tooltipContents[lineData.idModul] || "Standard-Tooltip-Inhalt", {
|
||||
polyline.bindTooltip(tooltipContents[`${lineData.idLD}-${lineData.idModul}`] || "Standard-Tooltip-Inhalt", {
|
||||
permanent: false,
|
||||
direction: "auto",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user