@@ -251,19 +251,31 @@ export default function MapComponent() {
251251
252252 const historicalData = await fetchHistoricalData ( name ) ;
253253
254+ // add once at top of click‐handler so you can reuse
255+ const popupOffset = [ 17 , - 25 ] ; // x=0 (center), y=−45px (above marker)
256+
254257 if ( historicalData . length === 0 ) {
255258 marker . bindPopup ( `
256259 <div role="dialog" aria-labelledby="popup-title-${ i } ">
257260 <h3 id="popup-title-${ i } ">${ name } </h3>
258261 <p>No historical data available</p>
259262 <p>Current temperature: ${ formattedTemp } (${ tempCategory } )</p>
260263 </div>
261- ` ) . openPopup ( ) ;
264+ ` , {
265+ offset : popupOffset ,
266+ className : 'custom-popup'
267+ } ) . openPopup ( ) ;
262268 return ;
263269 }
264270
265271 if ( historicalData . length < 2 ) {
266- marker . bindPopup ( `<strong>${ name } </strong><br/>Not enough data to generate a graph` ) . openPopup ( ) ;
272+ marker . bindPopup (
273+ `<strong>${ name } </strong><br/>Not enough data to generate a graph` ,
274+ {
275+ offset : popupOffset ,
276+ className : 'custom-popup'
277+ }
278+ ) . openPopup ( ) ;
267279 return ;
268280 }
269281
@@ -438,7 +450,7 @@ export default function MapComponent() {
438450
439451 // Open popup
440452 const popup = L . popup ( {
441- offset : [ 10 , - 20 ] ,
453+ offset : popupOffset ,
442454 maxWidth : 650 ,
443455 maxHeight : 470 ,
444456 className : 'custom-popup'
@@ -779,10 +791,10 @@ export default function MapComponent() {
779791 map . once ( 'moveend' , function ( ) {
780792 // After panning completes, smoothly zoom in
781793 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 } ) => {
794+ // replace marker.openPopup() with marker.fire('click')
795+ markersRef . current . forEach ( ( { marker, lat : markerLat , lon : markerLon } ) => {
784796 if ( Math . abs ( markerLat - lat ) < 0.0001 && Math . abs ( markerLon - lon ) < 0.0001 ) {
785- marker . openPopup ( ) ;
797+ marker . fire ( 'click' ) ;
786798 }
787799 } ) ;
788800 } ) ;
@@ -828,13 +840,13 @@ export default function MapComponent() {
828840 map . once ( 'moveend' , function ( ) {
829841 // After panning completes, smoothly zoom in
830842 map . once ( 'zoomend' , function ( ) {
831- // After zooming completes, open the popup
832- match . marker . openPopup ( ) ;
843+ // fire the click event so your click-handler builds the popup & chart
844+ match . marker . fire ( 'click' ) ;
833845 } ) ;
834846
835847 // Animate zoom with a duration in ms
836848 map . flyTo ( offsetLatLng , targetZoom , {
837- duration : 0.5 , // seconds
849+ duration : 0.5 ,
838850 easeLinearity : 0.2
839851 } ) ;
840852 } ) ;
0 commit comments