Skip to content

Commit 8eb097b

Browse files
committed
try to fix 'pulsing'
1 parent 22b34ea commit 8eb097b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/layers/UseCurrentLocationLayer.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,15 @@ export default function useCurrentLocationLayer(map: Map, locationState: Current
7474
}
7575

7676
if (locationState.syncView) {
77-
// TODO same code as for MoveMapToPoint action, but calling Dispatcher here is ugly
78-
let zoom = map.getView().getZoom()
79-
if (zoom == undefined || zoom < 8) zoom = 8
80-
map.getView().animate({ zoom: zoom, center: coord, duration: 400 })
77+
const currentZoom = map.getView().getZoom()
78+
const targetZoom = currentZoom == undefined || currentZoom < 8 ? 8 : currentZoom
79+
const zoomDifference = Math.abs(targetZoom - (currentZoom || 0))
80+
if (zoomDifference > 0.1) {
81+
map.getView().animate({ zoom: targetZoom, center: coord, duration: 400 })
82+
} else {
83+
// for smaller zoom changes set center without animation to avoid pulsing of map
84+
map.getView().setCenter(coord)
85+
}
8186
}
8287
}, [
8388
locationState.coordinate,

src/map/location_not_in_sync.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)