27 lines
861 B
JavaScript
27 lines
861 B
JavaScript
// /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;
|