-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Rotating the map does not update its bounds appropriately #2375
Comments
The bounds you get are defined by only two Points But you can use the 4 unprojected corners of the viewport to construct a real "corner-bound" polygon: var canvas = map.getCanvas(),
w = canvas.width,
h = canvas.height,
cUL = map.unproject([0,0]).toArray(),
cUR = map.unproject([w,0]).toArray(),
cLR = map.unproject([w,h]).toArray(),
cLL = map.unproject([0,h]).toArray();
var coordinates = [cUL,cUR,cLR,cLL,cUL]; see: https://jsfiddle.net/kmmky7h5/2/ (Be aware that you may face some problems at ± 180° and towards the poles) |
Awesome! Thanks indus! Still a +1 to accommodate rotations in |
The only thing is that the corners of the canvas are not exactly the corners of the map; the lower-right coordinate of the canvas goes beyond the map view. But it still works well for the most part. |
Thanks @indus, just used this workaround! For anyone feeding this into Postgis with
|
Here's a blog post that describes using this approach when building a "clip and ship" tool. https://medium.com/nycplanninglabs/getbounds-in-the-era-of-pitch-able-and-rotate-able-maps-4de97f35e64b Here's a widget that visually shows the difference between the getBounds() rectangle and the actual map extent: https://chriswhong.github.io/mapboxgl-view-bounds/#12.51/40.7768/-73.964/13.6/43 |
The map bounds do not update correctly as you rotate the map.
See demo: https://jsfiddle.net/kmmky7h5/
As you rotate the map in the demo, we expect to see the map bounds to update to the latest lat-long coordinates at the corners of the viewport, but instead, the bounds nest directly on top of each other based on the original bounds.
The text was updated successfully, but these errors were encountered: