@@ -179,6 +179,7 @@ export default function SparvagnMap({ poi }: SparvagnMapProps) {
179179 const userMarkerRef = useRef < LeafletCircleMarker | null > ( null ) ;
180180 const watchIdRef = useRef < number | null > ( null ) ;
181181 const refreshTimerRef = useRef < number | null > ( null ) ;
182+ const hasCenteredOnLocationRef = useRef ( false ) ;
182183
183184 const [ pois , setPois ] = useState < Poi [ ] > ( ( ) => poi . map ( ( p ) => ( { ...p , unlocked : false } ) ) ) ;
184185 // console.log("Rendering SparvagnMap with pois:", pois);
@@ -298,12 +299,17 @@ export default function SparvagnMap({ poi }: SparvagnMapProps) {
298299 }
299300
300301 setPois ( ( prev ) => {
302+ let changed = false ;
301303 const next = prev . map ( ( poi ) => {
302304 if ( ! poi . unlocked && distanceToPoi ( userLocation , poi ) <= poi . geoFenceDistance ) {
305+ changed = true ;
303306 return { ...poi , unlocked : true } ;
304307 }
305308 return poi ;
306309 } ) ;
310+ if ( ! changed ) {
311+ return prev ;
312+ }
307313 return next ;
308314 } ) ;
309315 } , [ userLocation ] ) ;
@@ -322,8 +328,9 @@ export default function SparvagnMap({ poi }: SparvagnMapProps) {
322328 return ;
323329 }
324330
325- if ( ! hasCenteredOnLocation ) {
331+ if ( ! hasCenteredOnLocationRef . current ) {
326332 map . setView ( [ location . lat , location . lng ] , 16 ) ;
333+ hasCenteredOnLocationRef . current = true ;
327334 setHasCenteredOnLocation ( true ) ;
328335 }
329336 if ( userMarkerRef . current ) {
@@ -338,7 +345,7 @@ export default function SparvagnMap({ poi }: SparvagnMapProps) {
338345 } ) . addTo ( map ) ;
339346 }
340347 } ,
341- [ hasCenteredOnLocation ]
348+ [ ]
342349 ) ;
343350
344351 const onLocationError = useCallback ( ( ) => {
0 commit comments