feat(SW-552): add fitbounds
This commit is contained in:
@@ -12,12 +12,14 @@ import Title from "@/components/TempDesignSystem/Text/Title"
|
|||||||
import styles from "./sidebar.module.css"
|
import styles from "./sidebar.module.css"
|
||||||
|
|
||||||
import type { SidebarProps } from "@/types/components/hotelPage/map/sidebar"
|
import type { SidebarProps } from "@/types/components/hotelPage/map/sidebar"
|
||||||
|
import { Coordinates } from "@/types/components/maps/coordinates"
|
||||||
|
|
||||||
export default function Sidebar({
|
export default function Sidebar({
|
||||||
activePoi,
|
activePoi,
|
||||||
hotelName,
|
hotelName,
|
||||||
pointsOfInterest,
|
pointsOfInterest,
|
||||||
onActivePoiChange,
|
onActivePoiChange,
|
||||||
|
coordinates,
|
||||||
}: SidebarProps) {
|
}: SidebarProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const map = useMap()
|
const map = useMap()
|
||||||
@@ -32,14 +34,22 @@ export default function Sidebar({
|
|||||||
setIsFullScreenSidebar((prev) => !prev)
|
setIsFullScreenSidebar((prev) => !prev)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePoiClick = useCallback(
|
function moveToPoi(poiCoordinates: Coordinates) {
|
||||||
(poiName: string, coordinates: { lat: number; lng: number }) => {
|
if (map) {
|
||||||
onActivePoiChange(activePoi === poiName ? null : poiName)
|
const bounds = new google.maps.LatLngBounds()
|
||||||
map?.panTo(coordinates)
|
bounds.extend(new google.maps.LatLng(coordinates.lat, coordinates.lng))
|
||||||
toggleFullScreenSidebar()
|
bounds.extend(
|
||||||
},
|
new google.maps.LatLng(poiCoordinates.lat, poiCoordinates.lng)
|
||||||
[activePoi, onActivePoiChange, map]
|
)
|
||||||
)
|
map.fitBounds(bounds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePoiClick(poiName: string, coordinates: Coordinates) {
|
||||||
|
onActivePoiChange(activePoi === poiName ? null : poiName)
|
||||||
|
moveToPoi(coordinates)
|
||||||
|
toggleFullScreenSidebar()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside
|
<aside
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export default function DynamicMap({
|
|||||||
hotelName={hotelName}
|
hotelName={hotelName}
|
||||||
pointsOfInterest={pointsOfInterest}
|
pointsOfInterest={pointsOfInterest}
|
||||||
onActivePoiChange={setActivePoi}
|
onActivePoiChange={setActivePoi}
|
||||||
|
coordinates={coordinates}
|
||||||
/>
|
/>
|
||||||
<InteractiveMap
|
<InteractiveMap
|
||||||
closeButton={closeButton}
|
closeButton={closeButton}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import type { PointOfInterest } from "@/types/hotel"
|
import type { PointOfInterest } from "@/types/hotel"
|
||||||
|
import type { Coordinates } from "../../maps/coordinates"
|
||||||
|
|
||||||
export interface SidebarProps {
|
export interface SidebarProps {
|
||||||
hotelName: string
|
hotelName: string
|
||||||
pointsOfInterest: PointOfInterest[]
|
pointsOfInterest: PointOfInterest[]
|
||||||
activePoi: PointOfInterest["name"] | null
|
activePoi: PointOfInterest["name"] | null
|
||||||
onActivePoiChange: (poi: PointOfInterest["name"] | null) => void
|
onActivePoiChange: (poi: PointOfInterest["name"] | null) => void
|
||||||
|
coordinates: Coordinates
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user