Wenn in der Tabelle location_device in der Spalte active = 0 steht wird die TALAS-Meldestation auf der Karte nicht mehr als CPL angezeigt.

This commit is contained in:
Ismail Ali
2025-02-02 18:03:21 +01:00
parent 5b2cb762cc
commit b2777612f2

View File

@@ -5,8 +5,8 @@ import L from "leaflet";
import "leaflet.smooth_marker_bouncing"; import "leaflet.smooth_marker_bouncing";
import { toast } from "react-toastify"; import { toast } from "react-toastify";
import * as config from "../config/config.js"; import * as config from "../config/config.js";
import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines"; // Importiere die Funktion zum Deaktivieren der Polyline-Ereignisse import { disablePolylineEvents, enablePolylineEvents } from "./setupPolylines";
import { setPolylineEventsDisabled } from "../store/atoms/polylineEventsDisabledState"; // Importiere den Recoil-Atom-Zustand import { setPolylineEventsDisabled } from "../store/atoms/polylineEventsDisabledState";
// Funktion zum Bestimmen der Priorität basierend auf dem Icon-Pfad // Funktion zum Bestimmen der Priorität basierend auf dem Icon-Pfad
const determinePriority = (iconPath, priorityConfig) => { const determinePriority = (iconPath, priorityConfig) => {
@@ -21,30 +21,36 @@ const determinePriority = (iconPath, priorityConfig) => {
// Funktion zum Erstellen und Setzen von Markern // Funktion zum Erstellen und Setzen von Markern
export const createAndSetDevices = async (systemId, setMarkersFunction, GisSystemStatic, priorityConfig) => { export const createAndSetDevices = async (systemId, setMarkersFunction, GisSystemStatic, priorityConfig) => {
try { try {
// Zähler für externe API-Aufrufe in localStorage speichern // API-Aufrufe zählen
let requestCount = localStorage.getItem("gisStationsStaticRequestCount-createDevice") || 0; let requestCount = localStorage.getItem("gisStationsStaticRequestCount-createDevice") || 0;
requestCount++; requestCount++;
localStorage.setItem("gisStationsStaticRequestCount-createDevice", requestCount); localStorage.setItem("gisStationsStaticRequestCount-createDevice", requestCount);
//console.log(`config.mapGisStationsStaticDistrictUrl in createAndSetDevice wurde ${requestCount} Mal aufgerufen.`);
const response1 = await fetch(config.mapGisStationsStaticDistrictUrl); const response1 = await fetch(config.mapGisStationsStaticDistrictUrl);
const jsonResponse = await response1.json(); const jsonResponse = await response1.json();
const response2 = await fetch(config.mapGisStationsStatusDistrictUrl); const response2 = await fetch(config.mapGisStationsStatusDistrictUrl);
const statusResponse = await response2.json(); const statusResponse = await response2.json();
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
const getIdSystemAndAllowValueMap = new Map(GisSystemStatic.map((system) => [system.IdSystem, system.Allow])); if (!jsonResponse.Points || !statusResponse.Statis) {
console.error("Fehlende Daten in API-Response!");
return;
}
console.log("✅ API-Daten geladen:", jsonResponse.Points.length, "Punkte gefunden.");
// Filter: Nur Stationen mit `Active === 1`
const activeStations = jsonResponse.Points.filter((station) => station.System === systemId && station.Active === 1);
console.log("🔍 Gefilterte aktive Stationen:", activeStations.length);
if (jsonResponse.Points && statusResponse.Statis) {
console.log("jsonResponse.Points: ", jsonResponse.Points);
console.log("statusResponse.Statis: ", statusResponse.Statis);
const statisMap = new Map(statusResponse.Statis.map((s) => [s.IdLD, s])); const statisMap = new Map(statusResponse.Statis.map((s) => [s.IdLD, s]));
let markersData = jsonResponse.Points.filter((station) => station.System === systemId && getIdSystemAndAllowValueMap.get(station.System) === 1).map((station) => {
let markersData = activeStations.map((station) => {
const statis = statisMap.get(station.IdLD); const statis = statisMap.get(station.IdLD);
const iconPath = statis ? `img/icons/${statis.Na}-marker-icon-${station.Icon}.png` : `img/icons/marker-icon-${station.Icon}.png`; const iconPath = statis ? `img/icons/${statis.Na}-marker-icon-${station.Icon}.png` : `img/icons/marker-icon-${station.Icon}.png`;
const priority = determinePriority(iconPath, priorityConfig); const priority = determinePriority(iconPath, priorityConfig);
const zIndexOffset = 100 * (5 - priority); // Adjusted for simplicity and positive values const zIndexOffset = 100 * (5 - priority);
const marker = L.marker([station.X, station.Y], { const marker = L.marker([station.X, station.Y], {
icon: L.icon({ icon: L.icon({
@@ -53,38 +59,31 @@ export const createAndSetDevices = async (systemId, setMarkersFunction, GisSyste
iconAnchor: [12, 41], iconAnchor: [12, 41],
popupAnchor: [1, -34], popupAnchor: [1, -34],
}), }),
areaName: station.Area_Name, // Stelle sicher, dass dieser Bereich gesetzt wird title: station.LD_Name,
link: station.Link, contextmenu: true,
data: { Active: station.Active }, // Speichere Active-Wert für spätere Verwendung
zIndexOffset: zIndexOffset, zIndexOffset: zIndexOffset,
}); });
// Deaktiviere Polyline-Ereignisse beim Überfahren des Markers
marker.on("mouseover", function () { marker.on("mouseover", function () {
this.openPopup(); this.openPopup();
}); });
// Verwende das `contextmenu`-Ereignis für den Rechtsklick
marker.on("contextmenu", function (event) { marker.on("contextmenu", function (event) {
if (event && event.preventDefault) { if (event && event.preventDefault) event.preventDefault();
event.preventDefault(); // Verhindert das Standard-Kontextmenü
}
//setPolylineEventsDisabled(true);
//disablePolylineEvents(window.polylines);
this.openPopup(); this.openPopup();
}); });
document.addEventListener("mouseout", function (event) { document.addEventListener("mouseout", function (event) {
if (event.relatedTarget === null || event.relatedTarget.nodeName === "BODY") { if (event.relatedTarget === null || event.relatedTarget.nodeName === "BODY") {
//setPolylineEventsDisabled(false);
enablePolylineEvents(window.polylines, window.lineColors); enablePolylineEvents(window.polylines, window.lineColors);
} }
}); });
marker.on("mouseout", function () { marker.on("mouseout", function () {
this.closePopup(); this.closePopup();
}); });
// Überprüfe, ob die bounce-Funktion verfügbar ist und verwende sie
if (typeof marker.bounce === "function" && statis) { if (typeof marker.bounce === "function" && statis) {
marker.on("add", () => marker.bounce(3)); marker.on("add", () => marker.bounce(3));
} }
@@ -111,13 +110,14 @@ export const createAndSetDevices = async (systemId, setMarkersFunction, GisSyste
</div> </div>
`); `);
return marker; return marker;
}); });
console.log("📌 Marker erstellt:", markersData.length);
// Aktualisiere den Marker-Status im State
setMarkersFunction(markersData); setMarkersFunction(markersData);
}
} catch (error) { } catch (error) {
console.error("Error fetching data: ", error); console.error("❌ Fehler beim Abrufen der Daten: ", error);
} }
}; };