-
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
Add "zoom aournd center" option to scrollZoom and touchZoomRotate #3876
Conversation
Thanks for contributing @mohsen1! I have a suggestion for how we could make the public API being added here more coherent and amenable to future expansions: let's make the optional argument passed to var map = new mapboxgl.Map({
...,
doubleClickZoom: { around: 'center' }
}); |
@@ -40,7 +40,7 @@ const defaultOptions = { | |||
dragPan: true, | |||
keyboard: true, | |||
doubleClickZoom: true, | |||
touchZoomRotate: true, | |||
touchZoomRotate: 'center', // temp |
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.
Don't forget to remove this.
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.
Per above.
@@ -37,14 +37,23 @@ class ScrollZoomHandler { | |||
/** | |||
* Enables the "scroll to zoom" interaction. | |||
* | |||
* @param {boolean|Object} options If {around: "center"} is passed, map will zoom around center of map |
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.
boolean|Object
here is incorrect. options
should be documented as an optional object, and options.around
as a separate subitem.
* @example | ||
* map.scrollZoom.enable(); | ||
* @example | ||
* map.scrollZoom.enable('center') |
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.
Example needs to be updated.
@@ -101,13 +101,13 @@ const defaultOptions = { | |||
* GL JS would be dramatically worse than expected (i.e. a software renderer would be used). | |||
* @param {boolean} [options.preserveDrawingBuffer=false] If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization. | |||
* @param {LngLatBoundsLike} [options.maxBounds] If set, the map will be constrained to the given bounds. | |||
* @param {boolean} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled (see [`ScrollZoomHandler`](#ScrollZoomHandler)). | |||
* @param {boolean|Object} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled, if {around: 'center'} is passed interaction is enabled and map zooms around the center (see [`ScrollZoomHandler`](#ScrollZoomHandler)). |
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.
Rather than re-documenting the specific option, here the documentation can simply state that if an Object is passed it can contain any options supported by ScrollZoomHandler#enable
.
* @param {boolean} [options.boxZoom=true] If `true`, the "box zoom" interaction is enabled (see [`BoxZoomHandler`](#BoxZoomHandler)). | ||
* @param {boolean} [options.dragRotate=true] If `true`, the "drag to rotate" interaction is enabled (see [`DragRotateHandler`](#DragRotateHandler)). | ||
* @param {boolean} [options.dragPan=true] If `true`, the "drag to pan" interaction is enabled (see [`DragPanHandler`](#DragPanHandler)). | ||
* @param {boolean} [options.keyboard=true] If `true`, keyboard shortcuts are enabled (see [`KeyboardHandler`](#KeyboardHandler)). | ||
* @param {boolean} [options.doubleClickZoom=true] If `true`, the "double click to zoom" interaction is enabled (see [`DoubleClickZoomHandler`](#DoubleClickZoomHandler)). | ||
* @param {boolean} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled (see [`TouchZoomRotateHandler`](#TouchZoomRotateHandler)). | ||
* @param {boolean|Object} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled, if {around: 'center'} is passed interaction is enabled and map zooms around the center (see [`TouchZoomRotateHandler`](#TouchZoomRotateHandler)). |
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.
Ditto.
@@ -41,13 +41,22 @@ class TouchZoomRotateHandler { | |||
/** | |||
* Enables the "pinch to rotate and zoom" interaction. | |||
* | |||
* @param {boolean|Object} options If {around: "center"} is passed, map will zoom around the center |
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.
Ditto.
* @example | ||
* map.touchZoomRotate.enable(); | ||
* @example | ||
* map.touchZoomRotate.enable('center'); |
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.
Ditto.
*/ | ||
enable() { | ||
enable(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.
Our code conventions don't currently permit the use of default parameters.
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.
so back to if (typeof options === 'object' &&
...?
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 would just write this._aroundCenter = options && options.around === 'center'
.
1824914
to
7974caa
Compare
Thanks Mohsen! |
Functionality finally not implemented ? |
@skol-pro It is implemented in mapboxgl. |
@Daandeve But not implemented in Mapbox GL JS ? |
Seems to work forcing the options. I guess the |
@skol-pro There's documentation in the Map options as shown below, as well as in the handler docs. I agree that it could be more explicit though. We're planning on doing some major refactoring of our handlers over the next few months though which will likely include rewriting many of the docs, so we'll try to make things like this more clear. Thanks! |
Thanks @ryanhamley ! I was actually speaking about the |
Launch Checklist
This change list is implementing Add
center
parameter toScrollZoom
andTouchZoomRotate
handlers #3780.Updated JSDoc, please let me know what else needs to be changed
How?
Works in debug page