-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
limit animation duration on flyTo with maxDuration option #5349
Changes from all commits
5a0facc
3886d82
c019780
4100e87
f941090
ed8fdc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,6 +665,8 @@ class Camera extends Evented { | |
* It does not correspond to a fixed physical distance, but varies by zoom level. | ||
* @param {number} [options.screenSpeed] The average speed of the animation measured in screenfuls | ||
* per second, assuming a linear timing curve. If `options.speed` is specified, this option is ignored. | ||
* @param {number} [options.maxDuration] The animation's maximum duration, measured in milliseconds. | ||
* If duration exceeds maximum duration, it resets to 0. | ||
* @param eventData Additional properties to be added to event objects of events triggered by this method. | ||
* @fires movestart | ||
* @fires zoomstart | ||
|
@@ -803,6 +805,10 @@ class Camera extends Evented { | |
options.duration = 1000 * S / V; | ||
} | ||
|
||
if (options.maxDuration && options.duration > options.maxDuration) { | ||
options.duration = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would make more sense to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review, @mollymerp! According to the last @mourner's comment in #3904, it was decided to reset There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mollymerp yeah, that was intentional — consider a use case where you need to switch to a view from another part of the world, but you don't want it to take forever to animate. Setting to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So everything is fine, then? Should I write tests and add a new example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stepankuzmin definitely worth adding a test! I don't think a small option like this needs a separate example though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mourner alright fair enough! I would think if a user had a case with a very long "flight path" they would rather explicitly set duration to 0 but I can definitely see both as valid 🤷♀️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mollymerp the user doesn't know beforehand how long the flight will take between two given positions (e.g. say you have a list of locations around the world and you click to switch between them in arbitrary order) — this is the primary reason for introducing |
||
} | ||
|
||
this.zooming = true; | ||
this.rotating = (startBearing !== bearing); | ||
this.pitching = (pitch !== startPitch); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clarify what happens if duration exceeds maxDuration in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I've updated the PR.