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

limit animation duration on flyTo with maxDuration option #5349

Merged
merged 6 commits into from
Sep 29, 2017

Conversation

stepankuzmin
Copy link
Contributor

@stepankuzmin stepankuzmin commented Sep 25, 2017

Hi there! I've added the maxDuration option to limit animation duration on flyTo according to #3904.

If this is the right way to do it, I'll add tests and documentation.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • manually test the debug page

@@ -665,6 +665,7 @@ 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.
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @stepankuzmin! I just requested one small change + the resultant documentation change.

@@ -803,6 +805,10 @@ class Camera extends Evented {
options.duration = 1000 * S / V;
}

if (options.maxDuration && options.duration > options.maxDuration) {
options.duration = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to set options.duration = options.maxDuration in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 duration to 0. So should I change it, or not?

Copy link
Member

Choose a reason for hiding this comment

The 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 maxDuration would make the animation too fast, since it's a very long fly path — instead, just switching to the new view in a moment is usually a better experience IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 🤷‍♀️

Copy link
Member

@mourner mourner Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think if a user had a case with a very long "flight path" they would rather explicitly set duration to 0

@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 maxDuration in the first place, and is similar to how other libs like Leaflet and Google Maps do it, disabling animation automatically if the flight path would be too long.

@stepankuzmin
Copy link
Contributor Author

Thanks for the review! I've added the test.

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

Successfully merging this pull request may close these issues.

3 participants