Repository navigation
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' }
}); |
| keyboard: true, | ||
| doubleClickZoom: true, | ||
| touchZoomRotate: true, | ||
| touchZoomRotate: 'center', // temp |
There was a problem hiding this comment.
Don't forget to remove this.
| /** | ||
| * 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.
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.
Example needs to be updated.
| * @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.
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.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)). |
| /** | ||
| * Enables the "pinch to rotate and zoom" interaction. | ||
| * | ||
| * @param {boolean|Object} options If {around: "center"} is passed, map will zoom around the center |
| * @example | ||
| * map.touchZoomRotate.enable(); | ||
| * @example | ||
| * map.touchZoomRotate.enable('center'); |
| * map.touchZoomRotate.enable({ around: 'center' }); | ||
| */ | ||
| enable() { | ||
| enable(options = {}) { |
There was a problem hiding this comment.
Our code conventions don't currently permit the use of default parameters.
There was a problem hiding this comment.
so back to if (typeof options === 'object' && ...?
There was a problem hiding this comment.
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
centerparameter toScrollZoomandTouchZoomRotatehandlers #3780.Updated JSDoc, please let me know what else needs to be changed
How?
Works in debug page