Fix fullscreen controls

This commit is contained in:
Tyler Hallada 2022-01-23 19:39:36 -05:00
parent c031524bd4
commit 7b5cc02993
3 changed files with 35 additions and 17 deletions

View File

@ -28,6 +28,9 @@ const Map: React.FC = () => {
const map = useRef<mapboxgl.Map | null>( const map = useRef<mapboxgl.Map | null>(
null null
) as React.MutableRefObject<mapboxgl.Map>; ) as React.MutableRefObject<mapboxgl.Map>;
const mapWrapper = useRef<HTMLDivElement | null>(
null
) as React.MutableRefObject<HTMLDivElement>;
const [selectedCell, setSelectedCell] = useState<[number, number] | null>( const [selectedCell, setSelectedCell] = useState<[number, number] | null>(
null null
); );
@ -269,8 +272,16 @@ const Map: React.FC = () => {
}, },
"grid-labels-layer" "grid-labels-layer"
); );
const fullscreenControl = new mapboxgl.FullscreenControl();
map.current.addControl(new mapboxgl.FullscreenControl()); console.log(
(fullscreenControl as unknown as { _container: HTMLElement })._container
);
(fullscreenControl as unknown as { _container: HTMLElement })._container =
mapWrapper.current;
console.log(
(fullscreenControl as unknown as { _container: HTMLElement })._container
);
map.current.addControl(fullscreenControl);
map.current.addControl(new mapboxgl.NavigationControl()); map.current.addControl(new mapboxgl.NavigationControl());
let singleClickTimeout: NodeJS.Timeout | null = null; let singleClickTimeout: NodeJS.Timeout | null = null;
@ -364,9 +375,7 @@ const Map: React.FC = () => {
}); });
const bounds = map.current.getBounds(); const bounds = map.current.getBounds();
console.log(bounds);
if (!bounds.contains(nw) || !bounds.contains(se)) { if (!bounds.contains(nw) || !bounds.contains(se)) {
console.log("out of viewport, panning");
map.current.panTo(nw); map.current.panTo(nw);
} }
} }
@ -377,23 +386,29 @@ const Map: React.FC = () => {
if (singleClickTimeout) clearTimeout(singleClickTimeout); if (singleClickTimeout) clearTimeout(singleClickTimeout);
singleClickTimeout = null; singleClickTimeout = null;
}); });
map.current.on("idle", () => {
map.current.resize();
});
}); });
}, [setSelectedCell, data]); }, [setSelectedCell, data]);
return ( return (
<> <>
<Sidebar
selectedCell={selectedCell}
setSelectedCell={setSelectedCell}
map={map}
/>
<div <div
className={`${styles["map-wrapper"]} ${ className={`${styles["map-wrapper"]} ${
selectedCell ? styles["map-wrapper-sidebar-open"] : "" selectedCell ? styles["map-wrapper-sidebar-open"] : ""
}`} }`}
ref={mapWrapper}
> >
<div ref={mapContainer} className={styles["map-container"]} /> <div ref={mapContainer} className={styles["map-container"]}>
<ToggleLayersControl map={map} /> <Sidebar
selectedCell={selectedCell}
setSelectedCell={setSelectedCell}
map={map}
/>
<ToggleLayersControl map={map} />
</div>
</div> </div>
</> </>
); );

View File

@ -11,14 +11,16 @@
height: 100%; height: 100%;
} }
.map-wrapper-sidebar-open { .map-wrapper-sidebar-open .map-container {
margin-left: 300px; width: calc(100% - 300px);
left: 300px;
} }
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {
.map-wrapper-sidebar-open { .map-wrapper-sidebar-open .map-container {
margin-left: initial; height: calc(100% - 45%);
margin-bottom: 45%; width: 100%;
height: 55%; left: 0;
bottom: 45%;
} }
} }

View File

@ -9,6 +9,7 @@
width: 300px; width: 300px;
padding: 12px; padding: 12px;
border-right: 1px solid #222222; border-right: 1px solid #222222;
font-size: 0.875rem;
} }
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {