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

Add bounds parameter to flyTo() #4894

Closed
gagecarto opened this issue Jun 26, 2017 · 8 comments
Closed

Add bounds parameter to flyTo() #4894

gagecarto opened this issue Jun 26, 2017 · 8 comments

Comments

@gagecarto
Copy link

gagecarto commented Jun 26, 2017

Motivation

When using flyTo() it would be useful to be able to include bounds rather than just center and zoom.

There are many instances when exact map bounds are important, especially when the bearing and pitch is also being adjusted.

Mock-Up

map.flyTo({
    bounds:[
        [-120.85,28.25],
        [-113.06,36.38]
    ],
    pitch:35,
    bearing:-180
  })
@mollymerp
Copy link
Contributor

Hi @gagecarto, thanks for using Mapbox. You can use Map#fitBounds for this. Unfortunately, fitBounds doesn't support pitch and bearing options (that issue is tracked at #2112), but you can apply those parameters with other camera operations if you need them.

@gagecarto
Copy link
Author

Thanks @mollymerp - I am looking to add bounds to a flyTo() event so that the animation is seamless with pitch, bearing and bounds.

@mollymerp
Copy link
Contributor

you can pass pitch, bearing, and linear: false (this is the default) as options and fitBounds will behave like flyTo. The only thing is the pitch and bearing arguments might make it so your bounds are not exactly fit.

@gagecarto
Copy link
Author

gagecarto commented Jun 26, 2017

looks like pitch works in fitBounds but not bearing. trying like below

var initBounds=[
  [-134.88,31.16],
  [-91.87,49.01]
]

map.fitBounds(initBounds,{
  bearing:180,
  pitch:40
})

or am i doing it wrong @mollymerp ?

@mollymerp
Copy link
Contributor

Oh yes you're right. We overwrite options.bearing=0 in the fitBounds function 😞

@gagecarto
Copy link
Author

gagecarto commented Jun 27, 2017

Oh heck.. Any way to overwrite that options.bearing=0 when calling fitBounds() @mollymerp

@andrewharvey
Copy link
Collaborator

@gagecarto I wonder if you could possible use https://github.com/mapbox/geo-viewport to get the center, zoom from your bounds and then use flyTo?

@ted-moke
Copy link

@andrewharvey That was looking promising until the .viewport method there is returning incorrect zoom levels

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

No branches or pull requests

4 participants