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

[Bug] defaultBounds not working as expected without fractional zoom enbled #575

Open
kodonnell opened this issue Oct 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kodonnell
Copy link

Description

When I specify defaultBounds I would expect it to fit the bounds such that calling fitBounds afterward has no effect. I have found this is only true when isFractionalZoomEnabled={true}. Without that, the initial map wouldn't match the fitBounds call, so when I 'reset' the map state (calling fitBounds) it would differ to the initial state.

I mention this because it took me hours to figure out. To be fair I'm not a Google Maps expert, but I tried lots of different approaches and I couldn't find any other way to make the map initialize to the correct bounds. (Manually calling fitBounds does. But when? And it's time dependent - if you do it too early in the load it fails. What about onIdle / onBoundsChanged? Works but how to do so without blocking user interaction? Etc.) So, unless I'm missing something, it'd be really good to have a warning or something in the console, or default to isFractionalZoomEnabled={true} if you specify defaultBounds.

Steps to Reproduce

I can provide if needed, but I'm hoping someone understands the root of the issue without testing, as it's relatively straightforward.

Environment

  • Library version: 9.0.29
  • Google maps version: ?
  • Browser and Version: Edge 129.0.2792.89 (Official build) (64-bit)
  • OS: Windows

Logs

No response

@kodonnell kodonnell added the bug Something isn't working label Oct 16, 2024
@mrMetalWood
Copy link
Collaborator

@kodonnell sorry for the late reply here. I understand the issue but I'm having a hard time reproducing it.

I understand it like this:

  • You have initial bounds which you set via defaultBounds
  • You then call fitBounds with the exact same bounds once the map is available
  • You are then seeing a shift or jump on the map after your fitBounds call.
  • The issue only exists when using isFractionalZoomEnabled={false}

Correct?

I tried to replicate it here: https://codesandbox.io/p/devbox/default-bounds-example-z27635?file=%2Fsrc%2Fapp.tsx%3A14%2C28

In this example it looks to me like it is behaving consistently correct. Are you seeing the issue here as well? The bounds are different depending on isFractionalZoomEnabled={true/false} but that makes sense since the when using false the map can can only use whole number zoom levels. But either way it looks to be consistent and I'm not seeing any jumps.

Can you provide a running example where you are seeing the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants