From 73e83f7602f855c8e70909e169d6666586c70571 Mon Sep 17 00:00:00 2001 From: Pyro Nicampt <81565698+PyroNicampt@users.noreply.github.com> Date: Tue, 31 Dec 2024 19:36:35 -0600 Subject: [PATCH] Fix map centering --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index abd4b97..ceac627 100644 --- a/index.js +++ b/index.js @@ -279,9 +279,10 @@ function establishDimensions(){ map.setAttribute('viewBox', `${minX-padding} ${minY-padding} ${width+2*padding} ${height+2*padding}`); map_markers.setAttribute('viewBox', map.getAttribute('viewBox')); let baseScale = Math.min(map_container.clientWidth/map.clientWidth, map_container.clientHeight/map.clientHeight); + let isLandscape = map_container.clientWidth > map_container.clientHeight; mapNav = { - x: -map.clientWidth/2+map_container.clientWidth/2 / baseScale, - y: -map.clientHeight/2+map_container.clientHeight/2 / baseScale, + x: isLandscape ? -map.clientWidth/2*baseScale + map_container.clientWidth/2 : 0, + y: isLandscape ? 0 : -map.clientHeight/2*baseScale + map_container.clientHeight/2, scale: baseScale }; updateMapview();