Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no offset on mobile #892

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/map/hooks/use-map-constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export function useMapConstants() {
},
];

const MAP_TREE_ZOOMED_IN_OFFSET = [-150, 0] as PointLike;
// Our main breakpoint is 1024px, on desktop-like screens we want to offset the tree circle to the left
// because the tree popup is displayed on the right side of the screen. On mobile-like screens we don't
// want to offset the tree circle, because the tree popup is displayed full screen.
const mapTreeZoomedInOffset = (windowWidth: number): PointLike => {
return windowWidth >= 1024
? ([-150, 0] as PointLike)
: ([0, 0] as PointLike);
};

// The link is stored in source code instead of environment variable, because of the required string interpolation of lat/lng/id which would be too complicated to handle in environment variables
const pumpUpdateLink = (id: number, lat: number, lng: number) => {
Expand All @@ -60,9 +67,9 @@ export function useMapConstants() {
MAP_CENTER_LAT,
MAP_PUMP_IMAGE_ICONS,
TREE_GRAY_COLOR,
MAP_TREE_ZOOMED_IN_OFFSET,
TREE_YELLOW_COLOR,
TREE_ORANGE_COLOR,
mapTreeZoomedInOffset,
pumpUpdateLink,
};
}
6 changes: 3 additions & 3 deletions src/components/map/hooks/use-map-trees-interaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useProfileStore } from "../../../shared-stores/profile-store.tsx";
export function useMapTreesInteraction(map: mapboxgl.Map | undefined) {
const { hideFilterView } = useFilterStore();

const { MAP_MAX_ZOOM_LEVEL, MAP_TREE_ZOOMED_IN_OFFSET } = useMapConstants();
const { MAP_MAX_ZOOM_LEVEL, mapTreeZoomedInOffset } = useMapConstants();

const { setHoveredTreeId } = useHoveredTree(map);
const { setSelectedTreeId } = useSelectedTree(map);
Expand Down Expand Up @@ -96,7 +96,7 @@ export function useMapTreesInteraction(map: mapboxgl.Map | undefined) {
zoom: MAP_MAX_ZOOM_LEVEL,
duration: 1500,
essential: true,
offset: MAP_TREE_ZOOMED_IN_OFFSET,
offset: mapTreeZoomedInOffset(window.innerWidth),
});
});
return;
Expand Down Expand Up @@ -167,7 +167,7 @@ export function useMapTreesInteraction(map: mapboxgl.Map | undefined) {
zoom: MAP_MAX_ZOOM_LEVEL,
essential: true,
duration: 1500,
offset: MAP_TREE_ZOOMED_IN_OFFSET,
offset: mapTreeZoomedInOffset(window.innerWidth),
});
map.once("moveend", () => {
setEaseToStartedByUserClick(false);
Expand Down
Loading