@@ -27,21 +27,23 @@ const TEA_COLOR = '#15803d' // green
2727const isCoffee = ( farm : AnyFarm ) => 'varieties' in farm
2828
2929const defStyle = ( farm : AnyFarm ) : L . CircleMarkerOptions => ( {
30- radius : 7 ,
30+ radius : 5 ,
3131 color : '#fff' ,
3232 weight : 1.5 ,
3333 fillColor : isCoffee ( farm ) ? COFFEE_COLOR : TEA_COLOR ,
3434 fillOpacity : 0.85 ,
3535 className : 'farm-dot' ,
36+ pane : 'farmDotsPane' ,
3637} )
3738
3839const hiStyle = ( farm : AnyFarm ) : L . CircleMarkerOptions => ( {
39- radius : 11 ,
40+ radius : 8 ,
4041 color : '#fff' ,
4142 weight : 2.5 ,
4243 fillColor : isCoffee ( farm ) ? COFFEE_COLOR : TEA_COLOR ,
4344 fillOpacity : 1 ,
4445 className : 'farm-dot farm-dot--selected' ,
46+ pane : 'farmDotsPane' ,
4547} )
4648
4749const CYCLOSM_URL = 'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png'
@@ -58,6 +60,7 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
5860 const markersRef = useRef < Map < string , { marker : L . CircleMarker ; farm : AnyFarm } > > ( new Map ( ) )
5961 const prevSelectedRef = useRef < string | null > ( null )
6062 const overlayRef = useRef < L . Polygon | null > ( null )
63+ const userInteractedRef = useRef ( false )
6164 const [ mapReady , setMapReady ] = useState ( false )
6265
6366 // Initialise the Leaflet map once
@@ -79,13 +82,15 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
7982 } ) . setView ( [ 20 , 80 ] , 6 )
8083
8184 mapRef . current = map
85+ map . createPane ( 'farmDotsPane' ) . style . zIndex = '450'
8286 setMapReady ( true )
8387
8488 const emitBounds = ( ) => {
85- if ( ! onBoundsChange ) return
89+ if ( ! userInteractedRef . current || ! onBoundsChange ) return
8690 const b = map . getBounds ( )
8791 onBoundsChange ( { north : b . getNorth ( ) , south : b . getSouth ( ) , east : b . getEast ( ) , west : b . getWest ( ) } )
8892 }
93+ map . on ( 'movestart' , ( ) => { userInteractedRef . current = true } )
8994 map . on ( 'moveend' , emitBounds )
9095 map . on ( 'zoomend' , emitBounds )
9196
@@ -171,8 +176,8 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
171176 existing . set ( farm . id , { marker, farm } )
172177 } )
173178
174- // Only fit bounds when nothing is selected — selecting a farm will flyTo instead
175- if ( ! selectedId ) {
179+ // Only fit bounds on initial load before the user has panned/zoomed
180+ if ( ! selectedId && ! userInteractedRef . current ) {
176181 const coords : [ number , number ] [ ] = [ ]
177182 existing . forEach ( ( { marker } , id ) => {
178183 if ( nextIds . has ( id ) ) coords . push ( [ marker . getLatLng ( ) . lat , marker . getLatLng ( ) . lng ] )
@@ -215,8 +220,8 @@ export default function FarmMap({ farms, selectedId, selectedFarm, onSelect, onB
215220 if ( lat != null && lng != null ) {
216221 map . setView ( [ lat , lng ] , 13 , { animate : false } )
217222 }
218- } else {
219- // Nothing selected — zoom back out to show all visible markers
223+ } else if ( ! userInteractedRef . current ) {
224+ // Nothing selected and user hasn't manually navigated — zoom to show all markers
220225 const coords : [ number , number ] [ ] = [ ]
221226 markersRef . current . forEach ( ( { marker } ) => {
222227 coords . push ( [ marker . getLatLng ( ) . lat , marker . getLatLng ( ) . lng ] )
0 commit comments