@@ -1220,7 +1220,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
1220
1220
{
1221
1221
CGPoint delta = [pan translationInView:pan.view];
1222
1222
1223
- toCamera = [self currentCameraWithEstimatedEndPoint :delta panGesture:pan];
1223
+ toCamera = [self cameraByPanningWithTranslation :delta panGesture:pan];
1224
1224
1225
1225
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1226
1226
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1246,7 +1246,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
1246
1246
if (drift)
1247
1247
{
1248
1248
CGPoint offset = CGPointMake(velocity.x * self.decelerationRate / 4, velocity.y * self.decelerationRate / 4);
1249
- toCamera = [self currentCameraWithEstimatedEndPoint :offset panGesture:pan];
1249
+ toCamera = [self cameraByPanningWithTranslation :offset panGesture:pan];
1250
1250
1251
1251
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1252
1252
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1283,8 +1283,6 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
1283
1283
1284
1284
CGPoint centerPoint = [self anchorPointForGesture:pinch];
1285
1285
MGLMapCamera *oldCamera = self.camera;
1286
- MGLMapCamera *toCamera;
1287
- double zoom = 0.0;
1288
1286
1289
1287
if (pinch.state == UIGestureRecognizerStateBegan)
1290
1288
{
@@ -1301,8 +1299,9 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
1301
1299
if (log2(newScale) < _mbglMap->getMinZoom()) return;
1302
1300
1303
1301
// Calculates the final camera zoom, has no effect within current map camera.
1304
- zoom = log2(newScale);
1305
- toCamera = [self currentCameraWithEstimatedZoom:zoom];
1302
+ MGLMapCamera *toCamera;
1303
+ double zoom = log2(newScale);
1304
+ toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1306
1305
1307
1306
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1308
1307
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1357,15 +1356,16 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
1357
1356
BOOL drift = velocity && duration;
1358
1357
1359
1358
// Calculates the final camera zoom, this has no effect within current map camera.
1360
- zoom = log2(newScale);
1361
- toCamera = [self currentCameraWithEstimatedZoom:zoom];
1359
+ MGLMapCamera *toCamera;
1360
+ double zoom = log2(newScale);
1361
+ toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1362
1362
1363
1363
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1364
1364
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1365
1365
{
1366
1366
self.camera = oldCamera;
1367
1367
drift = NO;
1368
- }else {
1368
+ } else {
1369
1369
if (drift)
1370
1370
{
1371
1371
_mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(duration));
@@ -1416,7 +1416,7 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1416
1416
newDegrees = fmaxf(newDegrees, -30);
1417
1417
}
1418
1418
1419
- toCamera = [self currentCameraWithEstimatedDegrees :newDegrees anchorPoint :centerPoint];
1419
+ toCamera = [self cameraByRotatingToDirection :newDegrees aroundAnchorPoint :centerPoint];
1420
1420
1421
1421
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1422
1422
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1439,7 +1439,7 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1439
1439
CGFloat newRadians = radians + velocity * decelerationRate * 0.1;
1440
1440
CGFloat newDegrees = MGLDegreesFromRadians(newRadians) * -1;
1441
1441
1442
- toCamera = [self currentCameraWithEstimatedDegrees :newDegrees anchorPoint :centerPoint];
1442
+ toCamera = [self cameraByRotatingToDirection :newDegrees aroundAnchorPoint :centerPoint];
1443
1443
1444
1444
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1445
1445
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1575,18 +1575,18 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
1575
1575
{
1576
1576
MGLMapCamera *oldCamera = self.camera;
1577
1577
1578
- double zoom = [ self currentCameraZoom] ;
1578
+ double zoom = self.zoomLevel ;
1579
1579
double newZoom = zoom + 1.0;
1580
+ CGPoint gesturePoint = [self anchorPointForGesture:doubleTap];
1580
1581
1581
- MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom :newZoom];
1582
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel :newZoom aroundAnchorPoint:gesturePoint ];
1582
1583
1583
1584
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1584
1585
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1585
1586
{
1586
1587
self.camera = oldCamera;
1587
1588
} else {
1588
1589
[self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap];
1589
- CGPoint gesturePoint = [self anchorPointForGesture:doubleTap];
1590
1590
1591
1591
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
1592
1592
_mbglMap->scaleBy(2, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
@@ -1618,17 +1618,17 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
1618
1618
{
1619
1619
MGLMapCamera *oldCamera = self.camera;
1620
1620
1621
- double zoom = [ self currentCameraZoom] ;
1621
+ double zoom = self.zoomLevel ;
1622
1622
double newZoom = zoom - 1.0;
1623
+ CGPoint gesturePoint = [self anchorPointForGesture:twoFingerTap];
1623
1624
1624
- MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom :newZoom];
1625
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel :newZoom aroundAnchorPoint:gesturePoint ];
1625
1626
1626
1627
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1627
1628
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1628
1629
{
1629
1630
self.camera = oldCamera;
1630
1631
} else {
1631
- CGPoint gesturePoint = [self anchorPointForGesture:twoFingerTap];
1632
1632
1633
1633
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
1634
1634
_mbglMap->scaleBy(0.5, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
@@ -1672,18 +1672,18 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
1672
1672
1673
1673
MGLMapCamera *oldCamera = self.camera;
1674
1674
1675
- double zoom = [ self currentCameraZoom] ;
1675
+ double zoom = self.zoomLevel ;
1676
1676
double scale = powf(2, newZoom) / _mbglMap->getScale();
1677
1677
1678
1678
double estimatedZoom = zoom * scale;
1679
1679
1680
- MGLMapCamera *toCamera = [self currentCameraWithEstimatedZoom :estimatedZoom];
1680
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel :estimatedZoom aroundAnchorPoint:centerPoint ];
1681
1681
1682
1682
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1683
1683
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1684
1684
{
1685
1685
self.camera = oldCamera;
1686
- }else {
1686
+ } else {
1687
1687
_mbglMap->scaleBy(scale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1688
1688
}
1689
1689
@@ -1719,7 +1719,7 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
1719
1719
1720
1720
CGPoint centerPoint = [self anchorPointForGesture:twoFingerDrag];
1721
1721
1722
- toCamera = [self currentCameraWithEstimatedPitch :pitchNew anchorPoint:centerPoint ];
1722
+ toCamera = [self cameraByTiltingToPitch :pitchNew];
1723
1723
1724
1724
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1725
1725
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
@@ -1739,43 +1739,34 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
1739
1739
1740
1740
}
1741
1741
1742
- - (MGLMapCamera *)currentCameraWithEstimatedEndPoint :(CGPoint)endPoint panGesture:(UIPanGestureRecognizer *)pan
1742
+ - (MGLMapCamera *)cameraByPanningWithTranslation :(CGPoint)endPoint panGesture:(UIPanGestureRecognizer *)pan
1743
1743
{
1744
1744
MGLMapCamera *panCamera = [self.camera copy];
1745
- CGFloat width = CGRectGetWidth(self.bounds);
1746
- CGFloat height = CGRectGetHeight(self.bounds);
1747
1745
1748
- mbgl::ScreenCoordinate screenCenter = {
1749
- width/2.,
1750
- height/2.,
1751
- };
1752
-
1753
- mbgl::ScreenCoordinate centerOffset = {
1754
- endPoint.x,
1755
- -endPoint.y,
1756
- };
1757
-
1758
- mbgl::ScreenCoordinate centerPoint = screenCenter - centerOffset;
1759
- CGPoint endCameraPoint = CGPointMake(centerPoint.x, centerPoint.y);
1746
+ CGPoint centerPoint = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
1747
+ CGPoint endCameraPoint = CGPointMake(centerPoint.x - endPoint.x, centerPoint.y - endPoint.y);
1760
1748
CLLocationCoordinate2D panCoordinate = [self convertPoint:endCameraPoint toCoordinateFromView:pan.view];
1749
+
1761
1750
panCamera.centerCoordinate = panCoordinate;
1762
1751
1763
1752
return panCamera;
1764
1753
}
1765
1754
1766
- - (MGLMapCamera *)currentCameraWithEstimatedZoom :(double)zoom
1755
+ - (MGLMapCamera *)cameraByZoomingToZoomLevel :(double)zoom aroundAnchorPoint:(CGPoint)anchorPoint
1767
1756
{
1768
1757
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1769
1758
mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1770
1759
MGLMapCamera *camera;
1771
1760
1761
+ mbgl::ScreenCoordinate anchor = mbgl::ScreenCoordinate { anchorPoint.x, anchorPoint.y };
1772
1762
currentCameraOptions.zoom = mbgl::util::clamp(zoom, self.minimumZoomLevel, self.maximumZoomLevel);
1763
+ currentCameraOptions.anchor = anchor;
1773
1764
camera = [self cameraForCameraOptions:currentCameraOptions];
1774
1765
1775
1766
return camera;
1776
1767
}
1777
1768
1778
- - (MGLMapCamera *)currentCameraWithEstimatedDegrees:(CGFloat )degrees anchorPoint :(CGPoint)anchorPoint
1769
+ - (MGLMapCamera *)cameraByRotatingToDirection:(CLLocationDirection )degrees aroundAnchorPoint :(CGPoint)anchorPoint
1779
1770
{
1780
1771
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1781
1772
mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
@@ -1790,34 +1781,19 @@ - (MGLMapCamera *)currentCameraWithEstimatedDegrees:(CGFloat)degrees anchorPoint
1790
1781
return camera;
1791
1782
}
1792
1783
1793
- - (MGLMapCamera *)currentCameraWithEstimatedPitch :(CGFloat)pitch anchorPoint:(CGPoint)anchorPoint
1784
+ - (MGLMapCamera *)cameraByTiltingToPitch :(CGFloat)pitch
1794
1785
{
1795
1786
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
1796
1787
mbgl::CameraOptions currentCameraOptions = _mbglMap->getCameraOptions(padding);
1797
1788
1798
1789
MGLMapCamera *camera;
1799
-
1800
- mbgl::ScreenCoordinate anchor = mbgl::ScreenCoordinate { anchorPoint.x, anchorPoint.y };
1790
+
1801
1791
currentCameraOptions.pitch = pitch * mbgl::util::DEG2RAD;
1802
- currentCameraOptions.anchor = anchor;
1803
1792
camera = [self cameraForCameraOptions:currentCameraOptions];
1804
1793
1805
1794
return camera;
1806
1795
}
1807
1796
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
-
1821
1797
- (CGPoint)anchorPointForGesture:(UIGestureRecognizer *)gesture {
1822
1798
if (self.userTrackingMode != MGLUserTrackingModeNone)
1823
1799
{
0 commit comments