@@ -757,14 +757,60 @@ export default function MapComponent() {
757757 // };
758758 // }, []);
759759
760- // Handle beach search by name
761- function handleSearch ( selectedName ) {
760+ // Handle beach search by name or coordinates
761+ function handleSearch ( selectedName , lat , lon ) {
762762 if ( ! mapInstanceRef . current ) return ;
763- const term = ( selectedName || searchTerm ) . trim ( ) . toLowerCase ( ) ;
763+
764+ // If direct coordinates are provided, use them
765+ if ( lat && lon ) {
766+ const map = mapInstanceRef . current ;
767+ const targetZoom = 15 ;
768+ const offsetY = 150 ;
769+ const offsetX = 0 ;
770+ const targetLatLng = [ lat , lon ] ;
771+
772+ // Calculate offset points for smooth animation
773+ const currentZoom = map . getZoom ( ) ;
774+ const pointAtCurrentZoom = map . project ( targetLatLng , currentZoom ) ;
775+ const offsetPointAtCurrentZoom = pointAtCurrentZoom . subtract ( [ offsetX , offsetY ] ) ;
776+ const offsetLatLngAtCurrentZoom = map . unproject ( offsetPointAtCurrentZoom , currentZoom ) ;
777+
778+ // First just pan to the location at the current zoom level
779+ map . once ( 'moveend' , function ( ) {
780+ // After panning completes, smoothly zoom in
781+ map . once ( 'zoomend' , function ( ) {
782+ // Find and open any popup that might be at this location
783+ markersRef . current . forEach ( ( { marker, lat : markerLat , lon : markerLon } ) => {
784+ if ( Math . abs ( markerLat - lat ) < 0.0001 && Math . abs ( markerLon - lon ) < 0.0001 ) {
785+ marker . openPopup ( ) ;
786+ }
787+ } ) ;
788+ } ) ;
789+
790+ // Animate zoom with a duration in ms
791+ map . flyTo ( targetLatLng , targetZoom , {
792+ duration : 0.5 , // seconds
793+ easeLinearity : 0.2
794+ } ) ;
795+ } ) ;
796+
797+ // Start the sequence by panning
798+ map . panTo ( offsetLatLngAtCurrentZoom , {
799+ animate : true ,
800+ duration : 0.75 // seconds
801+ } ) ;
802+
803+ return ;
804+ }
805+
806+ // Otherwise continue with name-based search
807+ const term = selectedName ? selectedName . trim ( ) . toLowerCase ( ) : '' ;
764808 if ( ! term ) return ;
809+
765810 const match = markersRef . current . find ( item =>
766811 item . name . toLowerCase ( ) . includes ( term )
767812 ) ;
813+
768814 if ( match ) {
769815 const map = mapInstanceRef . current ;
770816 const currentZoom = map . getZoom ( ) ;
0 commit comments