[ios] Round tap-zoom gestures to nearest integer
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)
This commit is contained in:
@@ -42,6 +42,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
|
||||
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
|
||||
* 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))
|
||||
* Annotations are no longer deselected when the map is panned or zoomed, even if the annotation moves out of the visible bounds. ([#8022](https://github.com/mapbox/mapbox-gl-native/pull/8022))
|
||||
* Double-tap and two-finger tap gestures now zoom to the nearest integer zoom level. ([#8027](https://github.com/mapbox/mapbox-gl-native/pull/8027))
|
||||
|
||||
## 3.4.1 - January 25, 2017
|
||||
|
||||
|
||||
@@ -1556,10 +1556,12 @@ public:
|
||||
if (doubleTap.state == UIGestureRecognizerStateEnded)
|
||||
{
|
||||
MGLMapCamera *oldCamera = self.camera;
|
||||
|
||||
|
||||
double newZoom = round(self.zoomLevel) + 1.0;
|
||||
|
||||
CGPoint gesturePoint = [self anchorPointForGesture:doubleTap];
|
||||
|
||||
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:self.zoomLevel + 1.0 aroundAnchorPoint:gesturePoint];
|
||||
|
||||
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:gesturePoint];
|
||||
|
||||
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
|
||||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
|
||||
@@ -1567,7 +1569,7 @@ public:
|
||||
[self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap];
|
||||
|
||||
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
|
||||
_mbglMap->scaleBy(2, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
|
||||
_mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
|
||||
|
||||
__weak MGLMapView *weakSelf = self;
|
||||
|
||||
@@ -1595,16 +1597,17 @@ public:
|
||||
{
|
||||
MGLMapCamera *oldCamera = self.camera;
|
||||
|
||||
double zoom = self.zoomLevel;
|
||||
double newZoom = round(self.zoomLevel) - 1.0;
|
||||
|
||||
CGPoint gesturePoint = [self anchorPointForGesture:twoFingerTap];
|
||||
|
||||
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:zoom - 1.0 aroundAnchorPoint:gesturePoint];
|
||||
|
||||
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:gesturePoint];
|
||||
|
||||
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
|
||||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
|
||||
{
|
||||
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
|
||||
_mbglMap->scaleBy(0.5, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
|
||||
_mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
|
||||
|
||||
__weak MGLMapView *weakSelf = self;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user