Hei!
fitBounds fires off either easeTo or FlyTo. Both are animated. Would be great if we could pass along a param to trigger jumpTo.
jumpTo() is the equivalent of easeTo() with a duration of 0. Try setting duration: 0 in the options object you pass in.
@1ec5 Ah, makes sense. Just one thing, fitBounds does a check for a linear option. This isn't documented nor used in any other public methods, just internally. Makes it slightly tricky to follow. Anyway, feel free to close this issue unless you want to keep it open as an doc-improvement issue.
fitBounds: function(options) {
(...)
return options.linear ?
this.easeTo(options) :
this.flyTo(options);
I think we should add sync API methods and clear ways to use them: setting a duration of 0 is not a very good way to express this.
@1ec5 Request for clarification: the docs on jumpTo indicate there's no transition, but easeTo with duration:0 (or linear: true) still shows a (very fast) animation. Is this the expected behavior? If so, we still do need a way to fitBounds() with no transition.
@1ec5 Request for clarification: the docs on jumpTo indicate there's no transition, but easeTo with duration:0 (or linear: true) still shows a (very fast) animation. Is this the expected behavior?
In my opinion, this is wrong - we should special case duration:0 and have it call jumpTo, instead of triggering a very fast animation.
Thoughts, @1ec5 ?
I agree. gl-native runs zero-second transitions atomically and synchronously. Should the change take place in _ease(), to benefit all the camera methods, or would that introduce unexpected behavior? I see there's already an animated option that would become redundant.
It is in fact special-cased already. So the 0-duration @peckjon describes is definitely a bug.
Can someone else verify the bug please? Want to be sure it's not just my codebase.
On Jan 22, 2016, at 07:29, Vladimir Agafonkin [email protected] wrote:
It is in fact special-cased already. So the 0-duration @peckjon describes is definitely a bug.
—
Reply to this email directly or view it on GitHub.
fitBounds() with duration: 0 does run synchronously without animation in GL JS 0.12.4. Are you setting any other options?
@mourner @1ec5 thank you for your help! I've been able to confirm it was a bug in my local code, and 0.12.4 works properly with no-animation.
Presumably, then, the best way to create a Map with specific bounds (and no other side effects) is to call fitBounds with {duration: 0} immediately after creation?
cross-ref: https://github.com/mapbox/mapbox-gl-js/issues/1970
@peckjon Yes, that's correct.
In terms of API here, I think we should add jumpToBounds, easeToBounds, and flyToBounds and remove fitBounds. Internally the new methods would call a common method to calculate the effective zoom and center for the bounds, then delegate to jumpTo/easeTo/flyTo.
gl-native publicly exposes a cameraForBounds() method that can be passed into *to() or used for any other purpose.
In terms of API here, I think we should add jumpToBounds, easeToBounds, and flyToBounds and remove fitBounds
I'm :+1: on this, and also adding map.getBoundsZoom or something like this.
Before fitBounds can be subsumed by the *to() methods, the padding camera option needs to be ported from mapbox/mapbox-gl-native#3583.
.getBoundsZoom() is a somewhat confusing name, since it wouldn't get the current bounds or zoom level. How about .toCameraOptions()?
Merged into #2801
I might be stupid, but hey
how to fit bounds without an animation ?
jumpTo with duration 0, or stuff like panTo and panBy are all about a combination of center and zoom, while a bound is like a rectangle.
I know best zoom / center combination can be calculated from a bounds, but the purpose of fitBounds was also to add sugar auto-calculating that, beyond the fact of centering / zooming the map.
I'm aware of #2801, and cameraForBounds or bounds inside a fresh new method are great proposals. I know this is on backlog too, but I'm looking for a kinda workaround solution here
@cyrilchapon Did you find one?
@cyrilchapon @Erutan409 you can use duration: 0 in the fitBounds options
map.fitBounds([[
32.958984,
-5.353521
], [
43.50585,
5.615985
]], {duration: 0});
Map#fitBounds supports all the options in CameraOptions and AnimationOptions. The documentation for this method is not generating correctly. I'm working on a fix.
@mollymerp Thank you for this! I didn't connect that duration was available in AnimationOptions on fitBounds. I glossed right the statement in the docs that says
Options supports all properties from AnimationOptions and CameraOptions in addition to the fields below.
This doesn't work for me
this.map.fitBounds(this.bounds, {padding: 30, duration: 0})
Also how I can listed to fitBounds end event?
@vedmant could you create working fiddle which is reproducing the issue? For the fitBounds end event, you can try to use moveend event with once.
@cs09g It works actually, it was my mistake. you can try to use moveend event with once. - thanks, I'll try this.
Most helpful comment
@cyrilchapon @Erutan409 you can use
duration: 0in thefitBoundsoptionsMap#fitBoundssupports all the options inCameraOptionsandAnimationOptions. The documentation for this method is not generating correctly. I'm working on a fix.