@@ -17,7 +17,7 @@ const { width: windowWidth, height: windowHeight } = useWindowSize()
1717
1818// Inline composable for map interaction handlers
1919function useMapInteractions(options : {
20- onMarkerClick: (uuid : string ) => void
20+ onMarkerClick: (uuid : string , coordinates : [ number , number ] ) => void
2121 onBackgroundClick: () => void
2222}) {
2323 const logger = consola .withTag (' map' )
@@ -48,9 +48,12 @@ function useMapInteractions(options: {
4848
4949 function handleLocationClick(map : Map , e : MapMouseEvent & { features? : GeoJSON .Feature [] }) {
5050 e .preventDefault ()
51- const uuid = e .features ?.[0 ]?.properties ?.uuid
52- if (uuid )
53- options .onMarkerClick (uuid )
51+ const feature = e .features ?.[0 ]
52+ const uuid = feature ?.properties ?.uuid
53+ if (uuid && feature ?.geometry ?.type === ' Point' ) {
54+ const coords = feature .geometry .coordinates as [number , number ]
55+ options .onMarkerClick (uuid , coords )
56+ }
5457 }
5558
5659 function setupCursorHandlers(map : Map , layerId : string ) {
@@ -168,24 +171,14 @@ function handleNavigate(uuid: string | undefined, latitude: number, longitude: n
168171 }
169172}
170173
171- function handleMarkerClick(uuid : string ) {
174+ function handleMarkerClick(uuid : string , coordinates : [ number , number ] ) {
172175 logger .info (' Marker clicked:' , uuid )
173176 selectedLocationUuid .value = uuid
174177 isDrawerOpen .value = true
175178 if (mapInstance .value ) {
176179 setSelectedLocation (mapInstance .value as any , uuid )
177-
178- // If marker is in bottom half, pan up so it's visible above drawer
179- const features = mapInstance .value .querySourceFeatures (' locations' , { filter: [' ==' , [' get' , ' uuid' ], uuid ] })
180- const feature = features [0 ]
181- if (feature ?.geometry ?.type === ' Point' ) {
182- const coords = feature .geometry .coordinates as [number , number ]
183- const point = mapInstance .value .project (coords )
184- const containerHeight = mapInstance .value .getContainer ().clientHeight
185- if (point .y > containerHeight / 2 ) {
186- flyTo ({ lat: coords [1 ], lng: coords [0 ] }, { zoom: mapInstance .value .getZoom (), padding: { bottom: 450 } })
187- }
188- }
180+ // Pan to marker position with padding for drawer, maintaining current zoom
181+ flyTo ({ lat: coordinates [1 ], lng: coordinates [0 ] }, { zoom: mapInstance .value .getZoom (), padding: { bottom: 450 } })
189182 }
190183}
191184
0 commit comments