Skip to content

Commit

Permalink
Merge pull request #105 from carbonplan/check-tiles
Browse files Browse the repository at this point in the history
Fix invalid tile key issues when swapping rasters when region picker active
  • Loading branch information
Shane98c committed Feb 15, 2024
2 parents 6e624d2 + d4e264a commit 8601213
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const createTiles = (regl, opts) => {
}) => {
if (setMetadata) setMetadata(metadata)
this.maxZoom = maxZoom
this.level = zoomToLevel(this.zoom, maxZoom)
const position = getPositions(tileSize, mode)
this.position = regl.buffer(position)
this.size = tileSize
Expand Down
10 changes: 5 additions & 5 deletions src/use-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { flushSync } from 'react-dom'
import { useMapbox } from './mapbox'

export const useControls = () => {
const [zoom, setZoom] = useState()
const [center, setCenter] = useState()
const { map } = useMapbox()
const [zoom, setZoom] = useState(map.getZoom())
const [center, setCenter] = useState(map.getCenter())

const updateControlsSync = useCallback(() => {
flushSync(() => {
Expand All @@ -15,10 +15,10 @@ export const useControls = () => {
}, [])

useEffect(() => {
setZoom(map.getZoom())
setCenter(map.getCenter())
map.on('load', updateControlsSync)
map.on('move', updateControlsSync)
return () => {
map.off('move', updateControlsSync)
}
}, [map])

return { center: center, zoom: zoom }
Expand Down

0 comments on commit 8601213

Please sign in to comment.