feat(SW-552): add padding to bound

This commit is contained in:
Fredrik Thorsson
2024-10-23 10:33:13 +02:00
parent 0d63abfa8b
commit fb863d63f7

View File

@@ -38,9 +38,18 @@ export default function Sidebar({
function moveToPoi(poiCoordinates: Coordinates) {
if (map) {
const bounds = new google.maps.LatLngBounds()
bounds.extend(new google.maps.LatLng(coordinates.lat, coordinates.lng))
const boundPadding = 0.02
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(poiCoordinates.lat, poiCoordinates.lng)
new google.maps.LatLng(minLat - boundPadding, minLng - boundPadding)
)
bounds.extend(
new google.maps.LatLng(maxLat + boundPadding, maxLng + boundPadding)
)
map.fitBounds(bounds)
}