Refactoring
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
// hooks/useLayerVisibility.js
|
||||
import { useEffect } from "react";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { mapLayersState } from "../store/atoms/mapLayersState";
|
||||
import { addContextMenuToMarker } from "../utils/contextMenuUtils";
|
||||
|
||||
const useLayerVisibility = (map, markers, mapLayersVisibility, layerKey) => {
|
||||
const useLayerVisibility = (map, markers, mapLayersVisibility, layerKey, oms) => {
|
||||
useEffect(() => {
|
||||
if (!map || !markers) return;
|
||||
if (!map || !markers || !oms) return;
|
||||
|
||||
const toggleLayer = (isVisible) => {
|
||||
markers.forEach((marker) => {
|
||||
if (isVisible) {
|
||||
marker.addTo(map);
|
||||
oms.addMarker(marker);
|
||||
addContextMenuToMarker(marker); // Kontextmenü hinzufügen
|
||||
} else {
|
||||
map.removeLayer(marker);
|
||||
oms.removeMarker(marker);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
toggleLayer(mapLayersVisibility[layerKey]);
|
||||
}, [map, markers, mapLayersVisibility, layerKey]);
|
||||
}, [map, markers, mapLayersVisibility, layerKey, oms]);
|
||||
};
|
||||
|
||||
export default useLayerVisibility;
|
||||
|
||||
Reference in New Issue
Block a user