Skip to content

Commit

Permalink
Remove zoom buttons on touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
umonkey committed Apr 1, 2024
1 parent d7aee60 commit dfd1a65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/src/components/maps/MapControl/MapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ZoomControl } from "react-leaflet";

import { IBounds, ILatLng, ITreeInfo } from "@/types";
import { AddTreeControl, DraggableMarker, LocateControl, MapBase, MapEventHandler, Markers } from "@/components";
import { useMobileDevice } from "./hooks";

import "leaflet/dist/leaflet.css";

Expand All @@ -20,6 +21,8 @@ export const MapControl = (props: IProps) => {
// a movable pointer when props.picker is true.
const [point, setPoint] = useState<ILatLng | null>(null);

const isMobile = useMobileDevice();

const handleBoundsChange = (bounds: IBounds) => {
props.onBoundsChange && props.onBoundsChange(bounds);
};
Expand All @@ -39,7 +42,10 @@ export const MapControl = (props: IProps) => {
{ !props.picker && props.markers && <Markers markers={props.markers} /> }
{ props.picker && <DraggableMarker position={point} onChange={handleMarkerDragged} /> }

<ZoomControl position="bottomright" />
{!isMobile && (
<ZoomControl position="bottomright" />
)}

<LocateControl position="bottomright" />

{props.onAddTree && (
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/maps/MapControl/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect, useState } from "react";

export const useMobileDevice = () => {
const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
const hasTouchScreen = "ontouchstart" in document.documentElement;
setIsMobile(hasTouchScreen);
}, []);

return isMobile;
};

0 comments on commit dfd1a65

Please sign in to comment.