@@ -1575,14 +1575,10 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
1575
1575
{
1576
1576
MGLMapCamera *oldCamera = self.camera;
1577
1577
1578
- mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1579
- mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1580
- double zoom = 0.0;
1581
- if (currentCameraOptions.zoom) {
1582
- zoom = *currentCameraOptions.zoom + 1.0;
1583
- }
1584
- currentCameraOptions.zoom = mbgl::util::clamp(zoom, self.minimumZoomLevel, self.maximumZoomLevel);
1585
- MGLMapCamera *toCamera = [self cameraForCameraOptions:currentCameraOptions];
1578
+ double zoom = [self currentCameraZoom];
1579
+ double newZoom = zoom + 1.0;
1580
+
1581
+ MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom:newZoom];
1586
1582
1587
1583
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1588
1584
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1621,15 +1617,11 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
1621
1617
else if (twoFingerTap.state == UIGestureRecognizerStateEnded)
1622
1618
{
1623
1619
MGLMapCamera *oldCamera = self.camera;
1620
+
1621
+ double zoom = [self currentCameraZoom];
1622
+ double newZoom = zoom - 1.0;
1624
1623
1625
- mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1626
- mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1627
- double zoom = 0.0;
1628
- if (currentCameraOptions.zoom) {
1629
- zoom = *currentCameraOptions.zoom - 1.0;
1630
- }
1631
- currentCameraOptions.zoom = mbgl::util::clamp(zoom, self.minimumZoomLevel, self.maximumZoomLevel);
1632
- MGLMapCamera *toCamera = [self cameraForCameraOptions:currentCameraOptions];
1624
+ MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom:newZoom];
1633
1625
1634
1626
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1635
1627
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1680,16 +1672,12 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
1680
1672
1681
1673
MGLMapCamera *oldCamera = self.camera;
1682
1674
1683
- mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1684
- mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1685
- double zoom = 0.0;
1675
+ double zoom = [self currentCameraZoom];
1686
1676
double scale = powf(2, newZoom) / _mbglMap->getScale();
1687
1677
1688
- if (currentCameraOptions.zoom) {
1689
- zoom = *currentCameraOptions.zoom * scale;
1690
- }
1691
- currentCameraOptions.zoom = mbgl::util::clamp(zoom, self.minimumZoomLevel, self.maximumZoomLevel);
1692
- MGLMapCamera *toCamera = [self cameraForCameraOptions:currentCameraOptions];
1678
+ double estimatedZoom = zoom * scale;
1679
+
1680
+ MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom:estimatedZoom];
1693
1681
1694
1682
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1695
1683
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1817,6 +1805,19 @@ - (MGLMapCamera *)currentCameraWithEstimatedPitch:(CGFloat)pitch anchorPoint:(CG
1817
1805
return camera;
1818
1806
}
1819
1807
1808
+ - (double)currentCameraZoom
1809
+ {
1810
+ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1811
+ mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1812
+ double zoom = 0.0;
1813
+
1814
+ if (currentCameraOptions.zoom) {
1815
+ zoom = *currentCameraOptions.zoom;
1816
+ }
1817
+
1818
+ return zoom;
1819
+ }
1820
+
1820
1821
- (CGPoint)anchorPointForGesture:(UIGestureRecognizer *)gesture {
1821
1822
if (self.userTrackingMode != MGLUserTrackingModeNone)
1822
1823
{
0 commit comments