import React, { useRef, useEffect, useState } from "react"; import styles from "../styles/ToggleLayersControl.module.css"; type Props = { map: React.MutableRefObject; }; const ToggleLayersControl: React.FC = ({ map }) => { const [heatmapVisible, setHeatmapVisible] = useState(true); const [gridVisible, setGridVisible] = useState(true); const [labelsVisible, setLabelsVisible] = useState(true); useEffect(() => { if (map.current && map.current.isStyleLoaded()) { map.current.setLayoutProperty( "grid-layer", "visibility", heatmapVisible ? "visible" : "none" ); } }, [heatmapVisible]); useEffect(() => { if (map.current && map.current.isStyleLoaded()) { map.current.setLayoutProperty( "graticule", "visibility", gridVisible ? "visible" : "none" ); } }, [gridVisible]); useEffect(() => { if (map.current && map.current.isStyleLoaded()) { map.current.setLayoutProperty( "grid-labels-layer", "visibility", labelsVisible ? "visible" : "none" ); } }, [labelsVisible]); return (
); }; export default ToggleLayersControl;