-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retrieving bounds and zoom of map #3344
Comments
Yes, this is the correct callback to use to listen to map state changes. To intercept and manipulate camera changes, you can do something like: onViewStateChange: ({viewState}) => {
return {
...viewState,
zoom: Math.max(viewState.zoom, 3)
};
} To get the bounds of the map: import {WebMercatorViewport} from '@deck.gl/core';
onViewStateChange: ({viewState}) => {
const viewport = new WebMercatorViewport(viewState);
const nw = viewport.unproject([0, 0]);
const se = viewport.unproject([viewport.width, viewport.height]);
// do what you need to do
} |
Thanks, I'll give it a go! |
@Pessimistress The documentation for
However, using Reproducible steps, log the state change onViewStateChange: ({viewState}) => {
const viewport = new WebMercatorViewport(viewState);
const nw = viewport.unproject([0, 0]);
const se = viewport.unproject([viewport.width, viewport.height]);
console.log("north: ", nw[1], ", south: ", se[1]);
console.log("east: ", se[0], "west: ", nw[0] );
}); and scroll the map east/west I think another adjustment is required in |
@tgorkin do you think it's worth reopening this? |
You will want to manage view state in your react app with deck's viewState and onViewStateChange prop. People usually hook this up to a useState hook. |
From the
onViewStateChange
documentation we know that aSo we can observe / listen for interaction and use the
viewState
data by putting a function insideonViewStateChange
, for exampleWhich gives us something like
Questions
The text was updated successfully, but these errors were encountered: