28 lines
660 B
TypeScript
28 lines
660 B
TypeScript
"use client";
|
|
|
|
import type { Map as MapLibreMap } from "maplibre-gl";
|
|
import type { RefObject } from "react";
|
|
import { useEffect } from "react";
|
|
import { setSimulationLayersVisibility } from "../map/simulation-layers";
|
|
|
|
type UseSimulationLayerVisibilityOptions = {
|
|
mapRef: RefObject<MapLibreMap | null>;
|
|
mapReady: boolean;
|
|
visible: boolean;
|
|
};
|
|
|
|
export function useSimulationLayerVisibility({
|
|
mapRef,
|
|
mapReady,
|
|
visible
|
|
}: UseSimulationLayerVisibilityOptions) {
|
|
useEffect(() => {
|
|
const map = mapRef.current;
|
|
if (!mapReady || !map) {
|
|
return;
|
|
}
|
|
|
|
setSimulationLayersVisibility(map, visible);
|
|
}, [mapRef, mapReady, visible]);
|
|
}
|