fix: userRights ? userRights.includes(56) : fale;

in try catch block eingepackt, falls ein Fehler auftaucht, dann in der Console und nicht im Browser
This commit is contained in:
ISA
2024-06-10 07:19:48 +02:00
parent 62f5502b02
commit c76ada149a

View File

@@ -1178,35 +1178,33 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}, []); }, []);
useEffect(() => { useEffect(() => {
try {
if (map && poiLayerRef.current && isPoiTypLoaded) { if (map && poiLayerRef.current && isPoiTypLoaded) {
map.removeLayer(poiLayerRef.current); map.removeLayer(poiLayerRef.current);
poiLayerRef.current = new L.LayerGroup().addTo(map); poiLayerRef.current = new L.LayerGroup().addTo(map);
locations.forEach(async (location) => { locations.forEach(async (location) => {
try {
const { latitude, longitude } = parsePoint(location.position); const { latitude, longitude } = parsePoint(location.position);
const poiTypName = poiTypMap.get(location.idPoiTyp) || "Unbekannt"; const poiTypName = poiTypMap.get(location.idPoiTyp) || "Unbekannt";
const deviceName = await fetchDeviceNameById(location.idLD); const deviceName = await fetchDeviceNameById(location.idLD);
//console.log("location.icon:", location);
// Check if user has the right to drag the marker const canDrag = userRights ? userRights.includes(56) : false;
const canDrag = userRights ? userRights.includes(56) : false; // Check if userRights is not null before using includes
// Finde das passende Icon aus poiData
const matchingIcon = poiData.find( const matchingIcon = poiData.find(
(poi) => poi.idPoi === location.idPoi (poi) => poi.idPoi === location.idPoi
); );
const iconUrl = matchingIcon const iconUrl = matchingIcon
? `/img/icons/pois/${matchingIcon.path}` ? `/img/icons/pois/${matchingIcon.path}`
: "/img/icons/pois/default-icon.png"; : "/img/icons/pois/default-icon.png";
const marker = L.marker([latitude, longitude], { const marker = L.marker([latitude, longitude], {
icon: L.icon({ icon: L.icon({
iconUrl: `/img/icons/pois/poi-marker-icon-${location.idPoiTyp}.png`,
//iconUrl: `/img/icons/pois/poi-marker-icon-${location.icon}.png`, //die kommen nicht aus poi sonder aus poityp tabelle
iconUrl: iconUrl, iconUrl: iconUrl,
iconSize: [25, 41], iconSize: [25, 41],
iconAnchor: [12, 41], iconAnchor: [12, 41],
popupAnchor: [1, -34], popupAnchor: [1, -34],
}), }),
draggable: canDrag, // Set draggable based on permission draggable: canDrag,
id: location.idPoi, id: location.idPoi,
}).bindContextMenu({ }).bindContextMenu({
contextmenu: true, contextmenu: true,
@@ -1255,12 +1253,18 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
console.error("Drag operation not allowed"); console.error("Drag operation not allowed");
} }
}); });
//poiLayer ein - oder ausschalten
if (poiLayerVisible) { if (poiLayerVisible) {
marker.addTo(poiLayerRef.current); marker.addTo(poiLayerRef.current);
} }
} catch (innerError) {
console.error("Error processing a location:", innerError);
}
}); });
} }
} catch (error) {
console.error("Error in useEffect:", error);
}
}, [ }, [
map, map,
locations, locations,
@@ -1270,6 +1274,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
userRights, userRights,
poiLayerVisible, poiLayerVisible,
]); ]);
//--------------------------------------------- //---------------------------------------------
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------