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

View File

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

View File

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