Skip to content

Commit

Permalink
Website: Enable zoom in/out on mobile (#897)
Browse files Browse the repository at this point in the history
* update website for mobile interaction

* format
  • Loading branch information
isaacbrodsky authored Aug 12, 2024
1 parent 25160b9 commit 8a78f58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion website/src/components/common.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const isMobile = (props) => `@media screen and (max-width: 480px)`;
export const MOBILE_CUTOFF_WINDOW_WIDTH = 480;

export const isMobile = (props) =>
`@media screen and (max-width: ${MOBILE_CUTOFF_WINDOW_WIDTH}px)`;
23 changes: 20 additions & 3 deletions website/src/components/explorer/map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PathStyleExtension } from "@deck.gl/extensions";
import { WebMercatorViewport, FlyToInterpolator } from "@deck.gl/core";
import { getRes0Cells, uncompactCells, cellToBoundary } from "h3-js";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import { MOBILE_CUTOFF_WINDOW_WIDTH } from "../common";

const INITIAL_VIEW_STATE = {
longitude: -74.012,
Expand Down Expand Up @@ -47,6 +48,18 @@ export function ExplorerMap({
() => uncompactCells(getRes0Cells(), 2).map((hex) => ({ hex })),
[],
);
const [windowWidth, setWindowWidth] = useState(null);

useEffect(() => {
const updateWidth = () => {
setWindowWidth(window.width);
};

updateWidth();

window.addEventListener("resize", updateWidth);
return () => window.removeEventListener("resize", updateWidth);
}, [setWindowWidth]);

useEffect(() => {
if (userValidHex && deckRef.current) {
Expand Down Expand Up @@ -111,8 +124,9 @@ export function ExplorerMap({
filled: false,
stroked: true,
getLineColor: [0, 0, 0],
getLineWidth: 3,
lineWidthMinPixels: 3,
getLineWidth: 2,
lineWidthUnits: "pixels",
lineWidthMinPixels: 2,
highPrecision: true,
pickable: true,
filled: true,
Expand Down Expand Up @@ -205,11 +219,14 @@ export function ExplorerMap({
ref={deckRef}
layers={layers}
initialViewState={currentInitialViewState}
controller={true}
getTooltip={getTooltip}
getCursor={getCursor}
onClick={onClick}
onLoad={() => setDeckLoaded(true)}
controller={{
dragPan: windowWidth && windowWidth >= MOBILE_CUTOFF_WINDOW_WIDTH,
}}
touchAction="pan-y"
>
<Map
reuseMaps
Expand Down
3 changes: 0 additions & 3 deletions website/src/components/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export const HeroExampleContainer = styled.div`
right: 0;
bottom: 0;
z-index: -1;
${isMobile} {
pointer-events: none;
}
`;

export const Section = styled.section`
Expand Down

0 comments on commit 8a78f58

Please sign in to comment.