hooks auslagern von MapComponent, useInitializeMap.js und useLoadUserRights.js
This commit is contained in:
26
components/mainComponent/hooks/useSetupMarkers.js
Normal file
26
components/mainComponent/hooks/useSetupMarkers.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// /components/mainComponent/hooks/useSetupMarkers.js
|
||||
import { useEffect } from "react";
|
||||
import { checkOverlappingMarkers } from "../../../utils/mapUtils";
|
||||
|
||||
const useSetupMarkers = (map, allMarkers, mapLayersVisibility, plusRoundIcon) => {
|
||||
useEffect(() => {
|
||||
if (map) {
|
||||
allMarkers.forEach((marker) => {
|
||||
const layerKey = marker.options?.layerKey;
|
||||
const isVisible = mapLayersVisibility[layerKey];
|
||||
|
||||
if (!layerKey || isVisible === undefined) return;
|
||||
|
||||
if (localStorage.getItem("editMode") === "true" || !isVisible) {
|
||||
if (map.hasLayer(marker)) map.removeLayer(marker);
|
||||
} else {
|
||||
if (!map.hasLayer(marker)) marker.addTo(map);
|
||||
}
|
||||
});
|
||||
|
||||
checkOverlappingMarkers(map, allMarkers, plusRoundIcon);
|
||||
}
|
||||
}, [map, allMarkers, mapLayersVisibility]);
|
||||
};
|
||||
|
||||
export default useSetupMarkers;
|
||||
Reference in New Issue
Block a user