From 8d0054c44ffe7bc14af003202e540acb75b5521e Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Tue, 5 Nov 2024 08:55:23 +0100 Subject: [PATCH] feat(SW-552): update bounds and zoom logic --- .../Map/DynamicMap/Sidebar/index.tsx | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/components/ContentType/HotelPage/Map/DynamicMap/Sidebar/index.tsx b/components/ContentType/HotelPage/Map/DynamicMap/Sidebar/index.tsx index e73c2c6b4..e99004874 100644 --- a/components/ContentType/HotelPage/Map/DynamicMap/Sidebar/index.tsx +++ b/components/ContentType/HotelPage/Map/DynamicMap/Sidebar/index.tsx @@ -37,21 +37,26 @@ export default function Sidebar({ function moveToPoi(poiCoordinates: Coordinates) { if (map) { + const hotelLatLng = new google.maps.LatLng( + coordinates.lat, + coordinates.lng + ) + const poiLatLng = new google.maps.LatLng( + poiCoordinates.lat, + poiCoordinates.lng + ) + const bounds = new google.maps.LatLngBounds() - const boundPadding = 0.02 + bounds.extend(hotelLatLng) + bounds.extend(poiLatLng) - const minLat = Math.min(coordinates.lat, poiCoordinates.lat) - const maxLat = Math.max(coordinates.lat, poiCoordinates.lat) - const minLng = Math.min(coordinates.lng, poiCoordinates.lng) - const maxLng = Math.max(coordinates.lng, poiCoordinates.lng) - - bounds.extend( - new google.maps.LatLng(minLat - boundPadding, minLng - boundPadding) - ) - bounds.extend( - new google.maps.LatLng(maxLat + boundPadding, maxLng + boundPadding) - ) map.fitBounds(bounds) + + const currentZoomLevel = map.getZoom() + + if (currentZoomLevel && currentZoomLevel <= 13) { + map.setZoom(currentZoomLevel - 1) + } } }