polylines tooltip content
This commit is contained in:
26
hooks/useMarkerLayers.js
Normal file
26
hooks/useMarkerLayers.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// hooks/useMarkerLayers.js
|
||||
import { useEffect } from "react";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { mapLayersState } from "../store/atoms/mapLayersState";
|
||||
|
||||
const useMarkerLayers = (map, markers, layerType) => {
|
||||
const mapLayersVisibility = useRecoilValue(mapLayersState);
|
||||
|
||||
useEffect(() => {
|
||||
if (!map || !markers) return;
|
||||
|
||||
const toggleLayer = (isVisible) => {
|
||||
markers.forEach((marker) => {
|
||||
if (isVisible) {
|
||||
marker.addTo(map);
|
||||
} else {
|
||||
map.removeLayer(marker);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
toggleLayer(mapLayersVisibility[layerType]);
|
||||
}, [map, markers, mapLayersVisibility, layerType]);
|
||||
};
|
||||
|
||||
export default useMarkerLayers;
|
||||
Reference in New Issue
Block a user