Station Icon Color ändern, je nach Status

This commit is contained in:
ISA
2024-04-17 11:52:18 +02:00
parent 7789de40ec
commit 3f07c7633e

View File

@@ -28,12 +28,6 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
const mapGisSystemStaticUrl = config.mapGisSystemStaticUrl; const mapGisSystemStaticUrl = config.mapGisSystemStaticUrl;
const mapDataIconUrl = config.mapDataIconUrl; const mapDataIconUrl = config.mapDataIconUrl;
console.log("GisStationsStaticDistrict 1 :", GisStationsStaticDistrict);
console.log("GisStationsStatusDistrict 1 :", GisStationsStatusDistrict);
console.log("GisStationsMeasurements 1 :", GisStationsMeasurements);
console.log("GisSystemStatic 1 :", GisSystemStatic);
console.log("map 1:", map);
// Funktion zum Aktualisieren der Position in der Datenbank // Funktion zum Aktualisieren der Position in der Datenbank
const updateLocationInDatabase = async (id, newLatitude, newLongitude) => { const updateLocationInDatabase = async (id, newLatitude, newLongitude) => {
const response = await fetch("/api/updateLocation", { const response = await fetch("/api/updateLocation", {
@@ -47,12 +41,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
}); });
if (response.ok) { if (response.ok) {
console.log("Position erfolgreich aktualisiert");
//schreib die neue Kooridnaten in die Console //schreib die neue Kooridnaten in die Console
console.log("Latitude: " + newLatitude);
console.log("Longitude: " + newLongitude);
console.log("ID: " + id);
console.log("Response: " + response);
//akuellisiere die Position in der Datenbank mit den neuen Koordinaten mit updateLocation mit SQL Anweisung UPDATE //akuellisiere die Position in der Datenbank mit den neuen Koordinaten mit updateLocation mit SQL Anweisung UPDATE
} else { } else {
console.error("Fehler beim Aktualisieren der Position"); console.error("Fehler beim Aktualisieren der Position");
@@ -64,16 +53,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
console.log("Datenabruf gestartet...");
const response = await fetch(mapGisStationsStaticDistrictUrl); const response = await fetch(mapGisStationsStaticDistrictUrl);
const jsonResponse = await response.json(); const jsonResponse = await response.json();
// Prüfen, ob die Antwort das erwartete Format hat und Daten enthält // Prüfen, ob die Antwort das erwartete Format hat und Daten enthält
if (jsonResponse && jsonResponse.Points) { if (jsonResponse && jsonResponse.Points) {
console.log(
"GisStationsStaticDistrict geladen:",
jsonResponse.Points
);
setGisStationsStaticDistrict(jsonResponse.Points); // Direkter Zugriff auf 'Points' setGisStationsStaticDistrict(jsonResponse.Points); // Direkter Zugriff auf 'Points'
} else { } else {
console.error( console.error(
@@ -94,9 +78,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
//------------------------------------------ //------------------------------------------
//\talas5\TileMap\img\icons\icon1.png //\talas5\TileMap\img\icons\icon1.png
// minor-marker-icon-23.png // minor-marker-icon-23.png
function getIconPath(iconNumber) {
return `TileMap/img/icons/marker-icon-${iconNumber}.png`;
}
// Marker hinzufügen für GisStationsStaticDistrict // Marker hinzufügen für GisStationsStaticDistrict
useEffect(() => { useEffect(() => {
if (map && GisStationsStaticDistrict.length > 0) { if (map && GisStationsStaticDistrict.length > 0) {
@@ -156,23 +138,12 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
console.log("Datenabruf gestartet...");
const response = await fetch(mapGisStationsStaticDistrictUrl); const response = await fetch(mapGisStationsStaticDistrictUrl);
const jsonResponse = await response.json(); const jsonResponse = await response.json();
// Prüfen, ob die Antwort das erwartete Format hat und Daten enthält // Prüfen, ob die Antwort das erwartete Format hat und Daten enthält
if (jsonResponse && jsonResponse.Points) { if (jsonResponse && jsonResponse.Points) {
console.log(
"GisStationsStaticDistrict geladen:",
jsonResponse.Points
);
setGisStationsStaticDistrict(jsonResponse.Points); // Direkter Zugriff auf 'Points' setGisStationsStaticDistrict(jsonResponse.Points); // Direkter Zugriff auf 'Points'
// Anzeigen eines spezifischen Details aus dem JSON
console.log(
"etwas von json zeigen :",
jsonResponse.Points[0].LD_Name
); // Beispiel für das Anzeigen des LD_Name des ersten Points
} else { } else {
console.error( console.error(
'Erwartete Daten im "Points"-Array nicht gefunden', 'Erwartete Daten im "Points"-Array nicht gefunden',
@@ -193,16 +164,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
console.log("Datenabruf gestartet...");
const response = await fetch(mapGisStationsStatusDistrictUrl); const response = await fetch(mapGisStationsStatusDistrictUrl);
const jsonResponse = await response.json(); const jsonResponse = await response.json();
// Prüfen, ob die Antwort das erwartete Format hat und Daten enthält // Prüfen, ob die Antwort das erwartete Format hat und Daten enthält
if (jsonResponse && jsonResponse.Statis) { if (jsonResponse && jsonResponse.Statis) {
console.log(
"GisStationsStatusDistrict geladen:",
jsonResponse.Statis
);
setGisStationsStatusDistrict(jsonResponse.Statis); // Direkter Zugriff auf 'Statis' setGisStationsStatusDistrict(jsonResponse.Statis); // Direkter Zugriff auf 'Statis'
} else { } else {
console.error( console.error(
@@ -224,13 +190,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
console.log("Datenabruf gestartet...");
const response = await fetch(mapGisStationsMeasurementsUrl); const response = await fetch(mapGisStationsMeasurementsUrl);
const jsonResponse = await response.json(); const jsonResponse = await response.json();
// Prüfen, ob die Antwort das erwartete Format hat und Daten enthält // Prüfen, ob die Antwort das erwartete Format hat und Daten enthält
if (jsonResponse && jsonResponse.Statis) { if (jsonResponse && jsonResponse.Statis) {
console.log("GisStationsMeasurements geladen:", jsonResponse.Statis);
setGisStationsMeasurements(jsonResponse.Statis); // Direkter Zugriff auf 'Statis' setGisStationsMeasurements(jsonResponse.Statis); // Direkter Zugriff auf 'Statis'
} else { } else {
console.error( console.error(
@@ -253,13 +217,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
console.log("Datenabruf gestartet...");
const response = await fetch(mapGisSystemStaticUrl); const response = await fetch(mapGisSystemStaticUrl);
const jsonResponse = await response.json(); const jsonResponse = await response.json();
// Prüfen, ob die Antwort das erwartete Format hat und Daten enthält // Prüfen, ob die Antwort das erwartete Format hat und Daten enthält
if (jsonResponse && jsonResponse.Systems) { if (jsonResponse && jsonResponse.Systems) {
console.log("GisSystemStatic geladen:", jsonResponse.Systems);
setGisSystemStatic(jsonResponse.Systems); // Direkter Zugriff auf 'Systems' setGisSystemStatic(jsonResponse.Systems); // Direkter Zugriff auf 'Systems'
} else { } else {
console.error( console.error(
@@ -297,7 +259,6 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
let initialMap = []; let initialMap = [];
useEffect(() => { useEffect(() => {
console.log("Server URL from config:", config.serverURL);
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
console.log("Window height from config:", config.windowHeight); console.log("Window height from config:", config.windowHeight);
} }
@@ -305,7 +266,6 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
// Funktionen zur Überwachung der Internetverbindung // Funktionen zur Überwachung der Internetverbindung
const checkInternet = () => { const checkInternet = () => {
console.log("Checking internet connectivity...");
fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" }) fetch("https://tile.openstreetmap.org/1/1/1.png", { method: "HEAD" })
.then((response) => setOnline(response.ok)) .then((response) => setOnline(response.ok))
.catch(() => setOnline(false)); .catch(() => setOnline(false));
@@ -500,9 +460,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
const showCoordinates = (e) => { const showCoordinates = (e) => {
alert("Breitengrad: " + e.latlng.lat + "\nLängengrad: " + e.latlng.lng); alert("Breitengrad: " + e.latlng.lat + "\nLängengrad: " + e.latlng.lng);
}; };
const showData = (e) => { const showData = (e) => {};
console.log(e);
};
const showTalas = (e) => { const showTalas = (e) => {
map.addLayer(TALAS); map.addLayer(TALAS);
loadData(); loadData();
@@ -523,7 +481,6 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
// Ensure this function is only called when map is initialized and available // Ensure this function is only called when map is initialized and available
const showAddStationPopup = (e) => { const showAddStationPopup = (e) => {
if (!initialMap) { if (!initialMap) {
console.log("Map is not initialized.");
return; return;
} }
@@ -630,7 +587,6 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
const result = await response.json(); const result = await response.json();
if (response.ok) { if (response.ok) {
console.log("Standort hinzugefügt:", result);
alert("Standort erfolgreich hinzugefügt!"); alert("Standort erfolgreich hinzugefügt!");
form.reset(); // Formular zurücksetzen form.reset(); // Formular zurücksetzen
// Hier könntest du weitere Aktionen durchführen, wie das Schließen des Popups oder das Aktualisieren der Marker auf der Karte // Hier könntest du weitere Aktionen durchführen, wie das Schließen des Popups oder das Aktualisieren der Marker auf der Karte
@@ -693,24 +649,34 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
}); });
GisStationsStaticDistrict.forEach((station) => { GisStationsStaticDistrict.forEach((station) => {
// Filtere alle Statusobjekte für diese station.Na
const statusObjects = GisStationsStatusDistrict.filter(
(status) => status.IdLD === station.IdLD
);
// Alle Status-Objekte mit gleicher IdLD finden // Alle Status-Objekte mit gleicher IdLD finden
const matchingStatuses = GisStationsStatusDistrict.filter( const matchingStatuses = GisStationsStatusDistrict.filter(
(status) => status.IdLD === station.IdLD (status) => status.IdLD === station.IdLD
); );
let additionalInfo = ""; let status2 = "";
let statusInfo = "";
// Umdrehen der Reihenfolge der Statusmeldungen // Umdrehen der Reihenfolge der Statusmeldungen
matchingStatuses.reverse().forEach((status) => { matchingStatuses.reverse().forEach((status) => {
additionalInfo += ` statusInfo += `
<div class="flex items-center my-1"> <div class="flex items-center my-1">
<div class="w-2 h-2 mr-2 inline-block rounded-full" style="background-color: ${status.Co};"></div> <div class="w-2 h-2 mr-2 inline-block rounded-full" style="background-color: ${status.Co};"></div>
${status.Me}&nbsp;<span style="color: ${status.Co};">(${status.Na})</span> ${status.Me}&nbsp;<span style="color: ${status.Co};">(${status.Na})</span>
</div>`; </div>`;
status2 = status.Na;
}); });
let iconPath = getIconPath(status2, station.Icon);
const marker = L.marker([station.X, station.Y], { const marker = L.marker([station.X, station.Y], {
icon: L.icon({ icon: L.icon({
iconUrl: getIconPath(station.Icon), iconUrl: iconPath,
iconSize: [25, 41], iconSize: [25, 41],
iconAnchor: [12, 41], iconAnchor: [12, 41],
popupAnchor: [1, -34], popupAnchor: [1, -34],
@@ -728,7 +694,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
marker marker
.bindPopup( .bindPopup(
`<b>${station.LD_Name}</b><br>${station.Device}<br>${station.Area_Short} (${station.Area_Name})<br>${station.Location_Short} (${station.Location_Name}) <br>${additionalInfo}<br><br>` `<b>${station.LD_Name}</b><br>${station.Device}<br>${station.Area_Short} (${station.Area_Name})<br>${station.Location_Short} (${station.Location_Name}) <br>${statusInfo}<br><br>`
) )
.openPopup(); .openPopup();
}); });
@@ -736,6 +702,40 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
}, [map, GisStationsStaticDistrict, GisStationsStatusDistrict]); // Include GisStationsStatusDistrict in dependencies }, [map, GisStationsStaticDistrict, GisStationsStatusDistrict]); // Include GisStationsStatusDistrict in dependencies
//------------------------------------------ //------------------------------------------
// Funktion, die den Pfad zum entsprechenden Icon basierend auf dem Status generiert
/* function getIconPath(status, iconId) {
let prefix = "";
switch (status) {
case "critical":
prefix = "critical-marker-icon";
break;
case "major":
prefix = "major-marker-icon";
break;
case "minor":
prefix = "minor-marker-icon";
break;
case "system":
prefix = "system-marker-icon";
break;
case "ok":
default:
prefix = "marker-icon"; // Annahme: "ok" ist der Standardstatus und grün
break;
}
return `path/to/icons/${prefix}-${iconId}.png`;
} */
//------------------------------------------
function getIconPath(status, iconNumber) {
if (status) {
// Wenn status vorhanden ist, füge ihn in den Pfad ein mit Bindestrich
return `TileMap/img/icons/${status}-marker-icon-${iconNumber}.png`;
} else {
// Wenn kein status vorhanden ist, lasse den Status-Teil ganz weg
return `TileMap/img/icons/marker-icon-${iconNumber}.png`;
}
}
return ( return (
<div <div