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
Fitbounds with center option not doing expected thing #11337
Comments
I think that center is not an option for the fitBounds method. |
@ai-santos I think, You are wrong |
Hmmm, now that you mention it, it should be available as part of the CameraOptions, I will look into it. |
Just to follow up because I have the same problem. I'm using v2.7.0. |
It's been a while, I can still reproduce it. Any updates? |
I got it working with following code. |
Did not work for me. But the following works fine.. let bounds = new Mapbox.LngLatBounds()
addresses.forEach(el => bounds.extend([el.longitude, el.latitude]));
const options = {
padding: 80,
duration: 0,
// center: this.center
}
// calculate center related offset
const ne = bounds.getNorthEast()
const sw = bounds.getSouthWest()
const offset = {
ne: [
this.center[0] - ne.lng,
this.center[1] - ne.lat,
],
sw: [
this.center[0] - sw.lng,
this.center[1] - sw.lat,
]
}
bounds.extend([this.center[0] + offset.ne[0], this.center[1] + offset.ne[1]])
bounds.extend([this.center[0] + offset.sw[0], this.center[1] + offset.sw[1]])
map.fitBounds(bounds, options) basically I'm calculating the opposite positions related to the center |
mapbox-gl-js version:2.6.1
browser:Chrome
Steps to Trigger Behavior
1.create LngLatBounds as
bounds
2 .use
map.fitBounds
and pass thecenter
option to itLink to Demonstration
check out this link for more info:
https://jsbin.com/zodotod/edit?html,output
Expected Behavior
The
bounds
should be in the view and thecenter
of the map should be thecenter
optionActual Behavior
Just
flyTo
the centerThe text was updated successfully, but these errors were encountered: