Skip to content

Commit 172f412

Browse files
authored
fix for dynamic vertical centering on mobile (#2266)
1 parent 0ad987d commit 172f412

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

client/src/hooks/useMapbox.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ export const useMapbox = () => {
3535
const baseLongOffset = 0.08;
3636
const longitudeOffset = baseLongOffset * Math.pow(2, 11 - currentZoom);
3737

38-
// calculates latitude offset for mobile according to zoom level and takes screen height into account
39-
const baseLatOffset = 0.05;
38+
// calculates latitude offset for mobile according to zoom level and screen height
39+
const baseLatOffset = 0.065;
4040
const screenHeight = window.innerHeight;
41-
const referenceHeight = 800;
42-
const screenHeightFactor = screenHeight / referenceHeight;
43-
const latitudeOffset =
44-
baseLatOffset * Math.pow(2, 11 - currentZoom) * screenHeightFactor;
41+
42+
function calculateLatOffset(screenHeight) {
43+
const baseHeight = 550;
44+
const rate = 0.006 / 50; // approximately 0.006 deg per 50 pixels
45+
return 0.034 + (screenHeight - baseHeight) * rate;
46+
}
47+
48+
const heightOffsetFactor = !screenHeight
49+
? baseLatOffset
50+
: calculateLatOffset(screenHeight);
51+
52+
const latitudeOffset = heightOffsetFactor * Math.pow(2, 11 - currentZoom);
4553

4654
mapbox.default.flyTo({
4755
center: [

0 commit comments

Comments
 (0)