Skip to content

Commit b4dfac0

Browse files
tech: add debounce to handleMove
1 parent 64d1bde commit b4dfac0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

frontend/src/domain/shared_slices/Map.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type MapSliceStateType = {
3636
fitToExtent?: Extent
3737
isAreaSelected: boolean
3838
isolatedLayer: IsolatedLayerType | undefined
39-
mapView: MapView
4039
locateOnMap: LocateOnMap | undefined
40+
mapView: MapView
4141
selectedBaseLayer: BaseLayer
4242
zoomToCenter?: Coordinate
4343
}
@@ -112,12 +112,12 @@ const mapSlice = createSlice({
112112
setIsolateMode(state, action: PayloadAction<IsolatedLayerType | undefined>) {
113113
state.isolatedLayer = action.payload
114114
},
115-
setMapView(state, action: PayloadAction<MapView>) {
116-
state.mapView = action.payload
117-
},
118115
setLocateOnMap(state, action: PayloadAction<LocateOnMap | undefined>) {
119116
state.locateOnMap = action.payload
120117
},
118+
setMapView(state, action: PayloadAction<MapView>) {
119+
state.mapView = action.payload
120+
},
121121
setZoomToCenter(state, action) {
122122
state.zoomToCenter = action.payload
123123
}

frontend/src/features/map/hook/useSyncMapView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useAppDispatch } from '@hooks/useAppDispatch'
22
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '@mtes-mct/monitor-ui'
33
import { setMapView } from 'domain/shared_slices/Map'
4-
import { isEqual } from 'lodash'
4+
import { debounce, isEqual } from 'lodash'
55
import { transformExtent } from 'ol/proj'
66
import { useEffect, useRef } from 'react'
77

@@ -21,7 +21,7 @@ export const useSyncMapViewToRedux = (map: OpenLayerMap | undefined) => {
2121

2222
const view = map.getView()
2323

24-
const handleMoveEnd = () => {
24+
const handleMoveEnd = debounce(() => {
2525
const extent3857 = view.calculateExtent(map.getSize())
2626
const extent4326 = transformExtent(extent3857, OPENLAYERS_PROJECTION, WSG84_PROJECTION)
2727
const zoom = view.getZoom()
@@ -36,7 +36,7 @@ export const useSyncMapViewToRedux = (map: OpenLayerMap | undefined) => {
3636

3737
dispatch(setMapView({ bbox: extent4326, zoom: zoomValue }))
3838
}
39-
}
39+
}, 250)
4040

4141
map.on('moveend', handleMoveEnd)
4242

0 commit comments

Comments
 (0)