Skip to content
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

getBounds value is wrong when I set fitBounds with padding #10169

Closed
csimpi opened this issue Dec 9, 2020 · 4 comments
Closed

getBounds value is wrong when I set fitBounds with padding #10169

csimpi opened this issue Dec 9, 2020 · 4 comments

Comments

@csimpi
Copy link

csimpi commented Dec 9, 2020

mapbox-gl-js version: ^1.12.0

browser: Chrome (newest)

Steps to Trigger Behavior

  1. map.fitBounds(bbox,{padding:{top:45, bottom:10, right:10, left: 10}});
  2. let bbox2 = map.getBounds;
  3. bbox should be equal with bbox2 but it's not

This causes a lot of troubles since we can't tell what is the real bbox.
We have a lot of icons and search tool on the map, so the padding is necessary, BUT still the bbox's value should be the same that I set. When I touch and move the map I'm getting a bad bbox value so when I reload the map it appears with bbox + padding values x 2, another reload makes it 3x etc etc ...

Link to Demonstration

https://jsbin.com/

Expected Behavior

fitbounds with padding should maintain the bbox's original value and shouldn't change it

Actual Behavior

Above

@mourner
Copy link
Member

mourner commented Dec 10, 2020

Yeah, I think that's a reasonable suggestion. This would involve updating these two methods to take transform.padding into account.

@antoineclaval
Copy link

Hi Peter,

I think I'm facing a similar issue. Could you update your Jsbin link, please? I see it pointing to the root jsbin.com.

Thanks

@andrewharvey
Copy link
Collaborator

map.fitBounds(bbox,{padding:{top:45, bottom:10, right:10, left: 10}});
let bbox2 = map.getBounds;
bbox should be equal with bbox2 but it's not

In my view, in this case bbox should not equal bbox2 as you'd like. My reasoning is that while you've asked the map to fit to bbox with a padding, the maps bounds you get after are going to be the full (outset) map bounds.

In #10386 I've proposed that when a global padding is set (map.setPadding) then fitBounds/getBounds will equal, instead of passing a padding to fitBounds you could apply it to the map globally instead.

@andrewharvey
Copy link
Collaborator

This should be fixed by #10386.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants