initial Marker werden wie erwartet auf die Karte gezeichnet, aber Plus Icon wird sich nicht aktualisiert, es muss dafür die Seite neu geladen wird

This commit is contained in:
ISA
2024-12-19 09:56:02 +01:00
parent 7d43759b64
commit ecaf21917e

View File

@@ -180,7 +180,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
setUserId(params.get("u")); setUserId(params.get("u"));
}, [setMapId, setUserId]); }, [setMapId, setUserId]);
useEffect(() => { /* useEffect(() => {
if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded && isRightsLoaded) { if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded && isRightsLoaded) {
//console.log("Überprüfung der Berechtigung vor addItemsToMapContextMenu: ", hasRights); //console.log("Überprüfung der Berechtigung vor addItemsToMapContextMenu: ", hasRights);
addItemsToMapContextMenu(hasRights); addItemsToMapContextMenu(hasRights);
@@ -192,7 +192,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern
hasRights, // Sicherstellen, dass hasRights berücksichtigt wird hasRights, // Sicherstellen, dass hasRights berücksichtigt wird
isRightsLoaded, // Überprüfung, ob die Rechte geladen sind isRightsLoaded, // Überprüfung, ob die Rechte geladen sind
]); ]); */
useEffect(() => { useEffect(() => {
const fetchAndSetUserRights = async () => { const fetchAndSetUserRights = async () => {
@@ -270,8 +270,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}, []); }, []);
//-------------------------------------------------------- //--------------------------------------------------------
useDrawLines(setLinePositions); useDrawLines(setLinePositions); // Linien auf die Karte zeichnen
//-------------------------------------------- //--------------------------------------------
// POIs Popup Informationen anzeigen
useEffect(() => { useEffect(() => {
const fetchPoiTypData = async () => { const fetchPoiTypData = async () => {
try { try {
@@ -284,7 +285,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
console.error("Fehler beim Abrufen der poiTyp-Daten-1:", error); console.error("Fehler beim Abrufen der poiTyp-Daten-1:", error);
} }
}; };
//--------------------------------------------
const fetchPoiData = async () => { const fetchPoiData = async () => {
try { try {
const response = await fetch("/api/talas_v5_DB/pois/poi-icons"); const response = await fetch("/api/talas_v5_DB/pois/poi-icons");
@@ -296,13 +296,13 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
console.error("Fehler beim Abrufen der poiData-2:", error); console.error("Fehler beim Abrufen der poiData-2:", error);
} }
}; };
//--------------------------------------------
fetchPoiTypData(); fetchPoiTypData();
fetchPoiData(); fetchPoiData();
}, []); }, []);
//--------------------------------------------
useEffect(() => { /* useEffect(() => {
if (map) { if (map) {
const dbLayer = new L.LayerGroup().addTo(map); // Define dbLayer here const dbLayer = new L.LayerGroup().addTo(map); // Define dbLayer here
@@ -310,8 +310,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
dbLayer.remove(); dbLayer.remove();
}; };
} }
}, [map]); }, [map]); */
//--------------------------------------------
// POIs auf die Karte zeichnen
useEffect(() => { useEffect(() => {
if (map && !poiLayerRef.current) { if (map && !poiLayerRef.current) {
poiLayerRef.current = new L.LayerGroup().addTo(map); poiLayerRef.current = new L.LayerGroup().addTo(map);
@@ -328,6 +329,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}, [map, locations, poiReadTrigger]); }, [map, locations, poiReadTrigger]);
//-------------------------------------------- //--------------------------------------------
// POIs auf die Karte zeichnen
useEffect(() => { useEffect(() => {
if (poiData.length === 0) return; if (poiData.length === 0) return;
@@ -400,22 +402,30 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
]; ];
const editMode = localStorage.getItem("editMode") === "true"; // EditMode prüfen const editMode = localStorage.getItem("editMode") === "true"; // EditMode prüfen
const mapLayersVisibility = JSON.parse(localStorage.getItem("mapLayersVisibility")) || {};
if (editMode) { allMarkers.forEach((marker) => {
// Alle Marker entfernen, wenn EditMode aktiv ist // Prüfe, ob der Marker einer sichtbaren Layer-Gruppe zugeordnet ist
allMarkers.forEach((marker) => { const layerKey = marker.options?.layerKey; // Layer-Key aus den Optionen des Markers
const isVisible = mapLayersVisibility[layerKey];
if (!layerKey || isVisible === undefined) {
console.warn(`Marker ohne gültigen layerKey oder keine Sichtbarkeitsdaten: ${marker}`);
return;
}
if (editMode || !isVisible) {
// Entferne Marker, wenn EditMode aktiv ist oder Layer unsichtbar
if (map.hasLayer(marker)) { if (map.hasLayer(marker)) {
map.removeLayer(marker); map.removeLayer(marker);
} }
}); } else {
} else { // Füge Marker hinzu, wenn EditMode deaktiviert ist und Layer sichtbar
// Marker wieder hinzufügen, falls EditMode deaktiviert ist
allMarkers.forEach((marker) => {
if (!map.hasLayer(marker)) { if (!map.hasLayer(marker)) {
marker.addTo(map); marker.addTo(map);
} }
}); }
} });
// Überprüfe überlappende Marker und füge das "Plus"-Icon hinzu // Überprüfe überlappende Marker und füge das "Plus"-Icon hinzu
checkOverlappingMarkers(map, allMarkers, plusRoundIcon); checkOverlappingMarkers(map, allMarkers, plusRoundIcon);