-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Control animation in setView/panTo/setZoom/fitBounds/etc. #1617
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
Conversation
| @@ -4,24 +4,22 @@ | |||
|
|
|||
| L.Map.include({ | |||
|
|
|||
| setView: function (center, zoom, forceReset) { | |||
| setView: function (center, zoom, options) { | |||
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.
Can we keep compatibility here and when options === true set options = {reset: true}?
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.
We can, but the more general question is whether we should keep any compatibility/legacy code in major releases, or always force users to upgrade the code in breaking places (documenting upgrade thoroughly) and keep the codebase clean. It's hard to compromise between these options, as it's a half-measure. Full measure on the compatibility side would lead to OpenLayers-like API hell, and full measure on the other side is pretty acceptable for Leaflet in my opinion. That's one of the reasons why I didn't release 1.0 yet BTW — I want the API to mature first.
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.
You've decided differently in the latest patches, but I would fall on the side of dumping the compatibility. Or at least deprecating the option, to be removed before 1.0. Warn to console?
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.
@jfirebaugh can you comment more on the compatibility here? it it more of a "nice to have" or a dependency in the Mapbox code?
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.
Looks like we have one example that uses it, but we don't use it directly. Downstream users of mapbox.js could be using it, of course.
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.
In that case, how about deprecating it? Warn users calling on the console if they pass in true. This won't affect site visitors, but will be seen by developers.
|
Do you have a map.setView(center, zoom, {pan: {animate: true}}); |
|
Good suggestion, renamed to |
|
Do we need zoomOptions and panOptions to be sub-things or could we just put all the options in the main closure? Not sure if it is necessary to differentiate between the two. Thoughts? |
I can imagine wanting only one or the other of the animations. However I can also see wanting a single flag to turn both on or off for convenience. You could achieve both by combining both approaches, possibly with the more specific would be equivalent to and you'd also be able to just do as you suggest. Documentation would fairly straightforward: just state the more specific overrides the less specific. Implementation should not be too hard either. Not sure what I think of it, though. |
I think we should have the possibility to configure it separately, because zooming and panning have different animations. ZoomOptions is currently barebones (only I like the suggestion from @kmrhb though. Best of both worlds. The only problem is to document it clearly, as it gets a bit confusing with all the different options... |
|
Also decided to add |
|
So, good to merge then I guess? Any objections? |
|
Meant to look over this sooner. Oops. Taking a look now. |
| if (canBeAnimated) { | ||
| if (options.animate !== undefined) { | ||
| options.zoom = L.extend({animate: options.animate}, options.zoom); | ||
| options.pan = L.extend({animate: options.animate}, options.pan); |
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.
Maybe pull this out into a user-callable normalizeOptions or similar? This is good for now, but if more properties get added that are shared, would be nice to simplify it. Also allows users to get the behaviour without copy/paste.
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.
I'll rewrite this part when more options get shared in future. No need for normalizeOptions option I think.
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.
Reasonable.
I'm new to the codebase, so I'm not clear on the flow: this is the only place you've added this normalization code. Is it the only entry point where the full options object could be passed in?
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.
Yep. All other entry points (such as fitBounds) use setView internally so they pass options through as is.
|
No further comments, so merging the pull. |
Control animation in setView/panTo/setZoom/fitBounds/etc.
|
I had a minor comment above that I don't think were looked at, but it's not important to the API. And API-wise I'm happy! Is there a release scheduled? I'm looking forward to scrapping my |
|
I think there's no need to comment every simple statement in the code, otherwise it will get overcrowded with comments. If there's a strict equality comparison of an expected object with true, we have a shortcut in place — easy enough in my opinion. |
|
Sure, not every comment, but maybe ones that are a little counter-intuitive. My only thought here was that as a newcomer to this code base—or even returning to it after some time—it would look strange, and I would wonder why that was going on; a comment stating it was to maintain backwards compatibility would help. Since the documentation is in the Of course, as a newcomer to the codebase, I defer to your style. |
|
Is there a way to set animation option's in L.map? One won't invoke |
Implements #1616. Since zooming and panning have different animation mechanisms, I propose the following API:
ZoomPanOptions:
Both
zoomOptionsandpanOptionshaveanimateoption. Panning behavior:Zooming behavior:
It may look a bit complicated at first but it's the simplest API I could think of that covers all the use cases.
@danzel @tmcw @jfirebaugh Comments? Suggestions?