Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 9363cb4

Browse files
committed
[ios] gesture delegate methods refactoring
1 parent 94ccf97 commit 9363cb4

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

platform/ios/src/MGLMapView.mm

+25-24
Original file line numberDiff line numberDiff line change
@@ -1575,14 +1575,10 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
15751575
{
15761576
MGLMapCamera *oldCamera = self.camera;
15771577

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];
15861582

15871583
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
15881584
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1621,15 +1617,11 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
16211617
else if (twoFingerTap.state == UIGestureRecognizerStateEnded)
16221618
{
16231619
MGLMapCamera *oldCamera = self.camera;
1620+
1621+
double zoom = [self currentCameraZoom];
1622+
double newZoom = zoom - 1.0;
16241623

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];
16331625

16341626
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
16351627
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1680,16 +1672,12 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
16801672

16811673
MGLMapCamera *oldCamera = self.camera;
16821674

1683-
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1684-
mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1685-
double zoom = 0.0;
1675+
double zoom = [self currentCameraZoom];
16861676
double scale = powf(2, newZoom) / _mbglMap->getScale();
16871677

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];
16931681

16941682
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
16951683
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1817,6 +1805,19 @@ - (MGLMapCamera *)currentCameraWithEstimatedPitch:(CGFloat)pitch anchorPoint:(CG
18171805
return camera;
18181806
}
18191807

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+
18201821
- (CGPoint)anchorPointForGesture:(UIGestureRecognizer *)gesture {
18211822
if (self.userTrackingMode != MGLUserTrackingModeNone)
18221823
{

0 commit comments

Comments
 (0)