-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Round tap-zoom gestures to nearest integer #8027
Conversation
@friedbunny, thanks for your PR! By analyzing this pull request, we identified @incanus, @1ec5 and @jfirebaugh to be potential reviewers. |
b64d9cb
to
de6d862
Compare
@@ -1556,18 +1556,20 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap | |||
if (doubleTap.state == UIGestureRecognizerStateEnded) | |||
{ | |||
MGLMapCamera *oldCamera = self.camera; | |||
|
|||
|
|||
double newZoom = round(self.zoomLevel) + 1.0; |
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 you make the corresponding changes to the Zoom In and Zoom Out buttons in the Android and macOS SDKs?
Lines 180 to 184 in e6c15d0
if (zoomIn) { | |
mapView.scaleBy(2.0, x, y, MapboxConstants.ANIMATION_DURATION); | |
} else { | |
mapView.scaleBy(0.5, x, y, MapboxConstants.ANIMATION_DURATION); | |
} |
mapbox-gl-native/platform/macos/src/MGLMapView.mm
Line 1045 in e6c15d0
[self setZoomLevel:self.zoomLevel + zoomDelta animated:animated]; |
/cc @tobrun
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.
Went a bit further on macOS in 4ed80f9 and rounded all of the non-freeform zoom methods gestures and commands.
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.
bb07128
to
4ed80f9
Compare
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 good, and thanks also for the changes on the macOS side. I’ll leave it to you to decide whether the Android SDK should get this fix here or in a separate PR.
platform/macos/CHANGELOG.md
Outdated
@@ -39,6 +39,7 @@ | |||
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574)) | |||
* Added a method to MGLMapViewDelegate, `-mapView:shouldChangeFromCamera:toCamera:`, that you can implement to restrict which parts the user can navigate to using gestures. ([#5584](https://github.com/mapbox/mapbox-gl-native/pull/5584)) | |||
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888)) | |||
* Double-tap, two-finger tap, zoom buttons, and demo app menu items and shortcut keys now zoom to the nearest integer zoom level. ([#8027](https://github.com/mapbox/mapbox-gl-native/pull/8027)) |
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.
FYI, the ⌥↑ and ⌥↓ shortcuts are built into MGLMapView. The menu items (which have their own shortcuts) are defined in MapDocument but could conceivably be moved into MGLMapView as well.
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.
Ah, did not know that — I’ll update the text here.
Round double-tap and two-finger tap zoom gestures to the nearest integer zoom level. This has the benefits for raster tiles, as well as styles with zoom-based functions. This results in a wider possible zoom range — ~0.5-1.5: Old: z4.6 → z5.6 (+1.0), z4.4 → z5.4 (+1.0) New: z4.6 → z6.0 (+1.4), z4.4 → z5.0 (+0.6)
4ed80f9
to
b27ace8
Compare
Affects: - Double-tap gestures - Two-finger tap gestures - +/- button pushes - Shortcut keys - Menu items and shortcut keys (in macapp)
b27ace8
to
4b227ed
Compare
@1ec5 @friedbunny I initially created that PR to showcase the possibility of such a feature but this didn't make it to master at that time as I didn't want to change the "default" behaviour. We could definitely look into reopening it for consistency between the bindings. cc @mapbox/android |
Yeah, let's do that for 5.0. It doesn't look like a big lift. |
The Android side is happening once again in #7630. 🚢 |
iOS changes
Rounds double-tap and two-finger tap zoom gestures to the nearest integer zoom level. This has benefits for raster tiles, as well as styles with zoom-based functions that transition on integers.
This results in a wider possible zoom range per gesticulation — 1.0 → ~0.5-1.5 levels. Here’s a comparison of double-tapping to zoom in with the changes in this PR:
Fixes #2276.
Core changes
Exposes an already-existing
setZoom
variation that takes ananchor
parameter — I did this to avoid calculating scale levels in the iOS zoom code. This makesMap::setZoom(zoom, {}, duration)
ambiguous, so it’s now necessary to specify a type for the middle parameter.