Skip to content

Commit

Permalink
add missing
Browse files Browse the repository at this point in the history
  • Loading branch information
tmshv committed Dec 1, 2022
1 parent c7482d5 commit 0cba67a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/store/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const fitBounds = createAction<FitBoundsPayload>("map/fitBounds")

export const resetNorth = createAction<WithMapId>("map/resetNorth")
export const resize = createAction<string>("map/resize")
export const printViewport = createAction<WithMapId>("map/printViewport")

type ValuePayload<T> = {
mapId: string
Expand All @@ -25,6 +26,7 @@ export const actions = {
resize,
resetNorth,
setInteractive,
printViewport,
}

export const listener = createListenerMiddleware()
Expand Down Expand Up @@ -67,3 +69,21 @@ listener.startListening({
map.resetNorthPitch()
},
})
listener.startListening({
actionCreator: printViewport,
effect: async (action, listenerApi) => {
const { mapId } = action.payload
const map = getMap(mapId)
if (!map) {
return
}

const viewport = {
zoom: map.getZoom(),
center: map.getCenter().toArray(),
bbox: map.getBounds().toArray(),
}

console.log("viewport", viewport)
},
})

0 comments on commit 0cba67a

Please sign in to comment.