Skip to content

Add "zoom aournd center" option to scrollZoom and touchZoomRotate - #3876

Merged
jfirebaugh merged 1 commit into
mapbox:masterfrom
mohsen1:around-center-pinch-zoom
Jan 17, 2017
Merged

jfirebaugh merged 1 commit into
mapbox:masterfrom
mohsen1:around-center-pinch-zoom

Conversation

@mohsen1

@mohsen1 mohsen1 commented Dec 31, 2016 •

Copy link
Copy Markdown

Launch Checklist

  • briefly describe the changes in this PR
    This change list is implementing Add center parameter to ScrollZoom and TouchZoomRotate handlers #3780.
  • write tests for all new functionality
  • document any changes to public APIs
    Updated JSDoc, please let me know what else needs to be changed
  • post benchmark scores
    How?
  • manually test the debug page
    Works in debug page

@mohsen1 mohsen1 changed the title Add "zoom aournd center" option to scrollZoom Add "zoom aournd center" option to scrollZoom and touchZoomRotate Dec 31, 2016
@jfirebaugh

Copy link
Copy Markdown
Contributor

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 enable an "options" object rather than a single string. That way use of the API can be more self-explanatory: map. doubleClickZoom.enable({around: 'center'}), and we can add additional options without backwards-incompatible API changes. This should extend to handler options passed to the map constructor as well, for example:

var map = new mapboxgl.Map({
   ...,
   doubleClickZoom: { around: 'center' }
});

Comment thread js/ui/map.js Outdated
keyboard: true,
doubleClickZoom: true,
touchZoomRotate: true,
touchZoomRotate: 'center', // temp

Copy link
Copy Markdown
Contributor

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.

@jfirebaugh jfirebaugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per above.

Comment thread js/ui/handler/scroll_zoom.js Outdated
/**
* Enables the "scroll to zoom" interaction.
*
* @param {boolean|Object} options If {around: "center"} is passed, map will zoom around center of map

Copy link
Copy Markdown
Contributor

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.

Comment thread js/ui/handler/scroll_zoom.js Outdated
* @example
* map.scrollZoom.enable();
* @example
* map.scrollZoom.enable('center')

Copy link
Copy Markdown
Contributor

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.

Comment thread js/ui/map.js Outdated
* @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)).

Copy link
Copy Markdown
Contributor

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.

Comment thread js/ui/map.js Outdated
* @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)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto.

Comment thread js/ui/handler/touch_zoom_rotate.js Outdated
/**
* Enables the "pinch to rotate and zoom" interaction.
*
* @param {boolean|Object} options If {around: "center"} is passed, map will zoom around the center

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto.

Comment thread js/ui/handler/touch_zoom_rotate.js Outdated
* @example
* map.touchZoomRotate.enable();
* @example
* map.touchZoomRotate.enable('center');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto.

Comment thread js/ui/handler/touch_zoom_rotate.js Outdated
* map.touchZoomRotate.enable({ around: 'center' });
*/
enable() {
enable(options = {}) {

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

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' && ...?

Copy link
Copy Markdown
Contributor

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

@jfirebaugh
jfirebaugh force-pushed the around-center-pinch-zoom branch from 1824914 to 7974caa Compare January 17, 2017 04:25
@jfirebaugh
jfirebaugh merged commit 7c72ca4 into mapbox:master Jan 17, 2017
@jfirebaugh

Copy link
Copy Markdown
Contributor

Thanks Mohsen!

@skol-pro

Copy link
Copy Markdown

Functionality finally not implemented ? scrollZoom is just accepting boolean...

@Daandeve

Daandeve commented Dec 3, 2019

Copy link
Copy Markdown

@skol-pro It is implemented in mapboxgl.
Usage:
//for touch
touchZoomRotate: {around: "center"}
//for scroll
scrollZoom: {around: "center"}

@skol-pro

skol-pro commented Dec 4, 2019 •

Copy link
Copy Markdown

@Daandeve But not implemented in Mapbox GL JS ?
Getting the following warning for both options using mapbox-gl@^1.5.1:
Type '{ around: string; }' is not assignable to type 'boolean'.ts(2322)

@skol-pro

skol-pro commented Dec 4, 2019

Copy link
Copy Markdown

Seems to work forcing the options. I guess the MapboxOptions interface is not up to date.

@ryanhamley

Copy link
Copy Markdown
Contributor

@skol-pro There's documentation in the Map options as shown below, as well as in the handler docs.
Screen Shot 2019-12-04 at 12 47 48 PM

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!

@skol-pro

skol-pro commented Dec 5, 2019

Copy link
Copy Markdown

Thanks @ryanhamley ! I was actually speaking about the @types/mapbox-gl that does not seems up to date.
Still, managed to make zoom centered working with workaround to bypass typescript complaining, thanks !

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.

6 participants