@@ -1206,7 +1206,6 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
1206
1206
_mbglMap->cancelTransitions();
1207
1207
1208
1208
MGLMapCamera *oldCamera = self.camera;
1209
- MGLMapCamera *toCamera;
1210
1209
1211
1210
if (pan.state == UIGestureRecognizerStateBegan)
1212
1211
{
@@ -1220,13 +1219,11 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
1220
1219
{
1221
1220
CGPoint delta = [pan translationInView:pan.view];
1222
1221
1223
- toCamera = [self cameraByPanningWithTranslation:delta panGesture:pan];
1222
+ MGLMapCamera * toCamera = [self cameraByPanningWithTranslation:delta panGesture:pan];
1224
1223
1225
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1226
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1224
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1225
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1227
1226
{
1228
- self.camera = oldCamera;
1229
- } else {
1230
1227
_mbglMap->moveBy({ delta.x, delta.y });
1231
1228
[pan setTranslation:CGPointZero inView:pan.view];
1232
1229
}
@@ -1246,13 +1243,11 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
1246
1243
if (drift)
1247
1244
{
1248
1245
CGPoint offset = CGPointMake(velocity.x * self.decelerationRate / 4, velocity.y * self.decelerationRate / 4);
1249
- toCamera = [self cameraByPanningWithTranslation:offset panGesture:pan];
1246
+ MGLMapCamera * toCamera = [self cameraByPanningWithTranslation:offset panGesture:pan];
1250
1247
1251
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1252
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1248
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1249
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1253
1250
{
1254
- self.camera = oldCamera;
1255
- } else {
1256
1251
_mbglMap->moveBy({ offset.x, offset.y }, MGLDurationInSecondsFromTimeInterval(self.decelerationRate));
1257
1252
}
1258
1253
}
@@ -1295,19 +1290,15 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
1295
1290
else if (pinch.state == UIGestureRecognizerStateChanged)
1296
1291
{
1297
1292
CGFloat newScale = self.scale * pinch.scale;
1298
-
1299
- if (log2(newScale) < _mbglMap->getMinZoom()) return;
1293
+ double zoom = log2(newScale);
1294
+ if (zoom < _mbglMap->getMinZoom()) return;
1300
1295
1301
1296
// Calculates the final camera zoom, has no effect within current map camera.
1302
- MGLMapCamera *toCamera;
1303
- double zoom = log2(newScale);
1304
- toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1297
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1305
1298
1306
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1307
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1299
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1300
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1308
1301
{
1309
- self.camera = oldCamera;
1310
- } else {
1311
1302
_mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1312
1303
}
1313
1304
// The gesture recognizer only reports the gesture’s current center
@@ -1356,14 +1347,12 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
1356
1347
BOOL drift = velocity && duration;
1357
1348
1358
1349
// Calculates the final camera zoom, this has no effect within current map camera.
1359
- MGLMapCamera *toCamera;
1360
1350
double zoom = log2(newScale);
1361
- toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1351
+ MGLMapCamera * toCamera = [self cameraByZoomingToZoomLevel:zoom aroundAnchorPoint:centerPoint];
1362
1352
1363
1353
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1364
1354
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1365
1355
{
1366
- self.camera = oldCamera;
1367
1356
drift = NO;
1368
1357
} else {
1369
1358
if (drift)
@@ -1388,8 +1377,6 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1388
1377
1389
1378
CGPoint centerPoint = [self anchorPointForGesture:rotate];
1390
1379
MGLMapCamera *oldCamera = self.camera;
1391
- MGLMapCamera *toCamera;
1392
-
1393
1380
1394
1381
if (rotate.state == UIGestureRecognizerStateBegan)
1395
1382
{
@@ -1416,14 +1403,12 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1416
1403
newDegrees = fmaxf(newDegrees, -30);
1417
1404
}
1418
1405
1419
- toCamera = [self cameraByRotatingToDirection:newDegrees aroundAnchorPoint:centerPoint];
1406
+ MGLMapCamera * toCamera = [self cameraByRotatingToDirection:newDegrees aroundAnchorPoint:centerPoint];
1420
1407
1421
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1422
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1408
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1409
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1423
1410
{
1424
- self.camera = oldCamera;
1425
- } else {
1426
- _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1411
+ _mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1427
1412
}
1428
1413
1429
1414
[self notifyMapChange:mbgl::MapChangeRegionIsChanging];
@@ -1439,13 +1424,11 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1439
1424
CGFloat newRadians = radians + velocity * decelerationRate * 0.1;
1440
1425
CGFloat newDegrees = MGLDegreesFromRadians(newRadians) * -1;
1441
1426
1442
- toCamera = [self cameraByRotatingToDirection:newDegrees aroundAnchorPoint:centerPoint];
1427
+ MGLMapCamera * toCamera = [self cameraByRotatingToDirection:newDegrees aroundAnchorPoint:centerPoint];
1443
1428
1444
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1445
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1429
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1430
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1446
1431
{
1447
- self.camera = oldCamera;
1448
- } else {
1449
1432
_mbglMap->setBearing(newDegrees, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationInSecondsFromTimeInterval(decelerationRate));
1450
1433
1451
1434
[self notifyGestureDidEndWithDrift:YES];
@@ -1457,7 +1440,6 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
1457
1440
[weakSelf unrotateIfNeededForGesture];
1458
1441
}];
1459
1442
}
1460
-
1461
1443
}
1462
1444
else
1463
1445
{
@@ -1575,17 +1557,13 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
1575
1557
{
1576
1558
MGLMapCamera *oldCamera = self.camera;
1577
1559
1578
- double zoom = self.zoomLevel;
1579
- double newZoom = zoom + 1.0;
1580
1560
CGPoint gesturePoint = [self anchorPointForGesture:doubleTap];
1581
1561
1582
- MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:gesturePoint];
1562
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:self.zoomLevel + 1.0 aroundAnchorPoint:gesturePoint];
1583
1563
1584
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1585
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1564
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1565
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1586
1566
{
1587
- self.camera = oldCamera;
1588
- } else {
1589
1567
[self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap];
1590
1568
1591
1569
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
@@ -1598,7 +1576,6 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
1598
1576
[weakSelf unrotateIfNeededForGesture];
1599
1577
}];
1600
1578
}
1601
-
1602
1579
}
1603
1580
}
1604
1581
@@ -1619,17 +1596,13 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
1619
1596
MGLMapCamera *oldCamera = self.camera;
1620
1597
1621
1598
double zoom = self.zoomLevel;
1622
- double newZoom = zoom - 1.0;
1623
1599
CGPoint gesturePoint = [self anchorPointForGesture:twoFingerTap];
1624
1600
1625
- MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:gesturePoint];
1601
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:zoom - 1.0 aroundAnchorPoint:gesturePoint];
1626
1602
1627
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1628
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1603
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1604
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1629
1605
{
1630
- self.camera = oldCamera;
1631
- } else {
1632
-
1633
1606
mbgl::ScreenCoordinate center(gesturePoint.x, gesturePoint.y);
1634
1607
_mbglMap->scaleBy(0.5, center, MGLDurationInSecondsFromTimeInterval(MGLAnimationDuration));
1635
1608
@@ -1640,7 +1613,6 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
1640
1613
[weakSelf unrotateIfNeededForGesture];
1641
1614
}];
1642
1615
}
1643
-
1644
1616
}
1645
1617
}
1646
1618
@@ -1679,11 +1651,9 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
1679
1651
1680
1652
MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:estimatedZoom aroundAnchorPoint:centerPoint];
1681
1653
1682
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1683
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1654
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1655
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1684
1656
{
1685
- self.camera = oldCamera;
1686
- } else {
1687
1657
_mbglMap->scaleBy(scale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1688
1658
}
1689
1659
@@ -1702,7 +1672,6 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
1702
1672
1703
1673
_mbglMap->cancelTransitions();
1704
1674
MGLMapCamera *oldCamera = self.camera;
1705
- MGLMapCamera *toCamera;
1706
1675
1707
1676
if (twoFingerDrag.state == UIGestureRecognizerStateBegan)
1708
1677
{
@@ -1719,13 +1688,11 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
1719
1688
1720
1689
CGPoint centerPoint = [self anchorPointForGesture:twoFingerDrag];
1721
1690
1722
- toCamera = [self cameraByTiltingToPitch:pitchNew];
1691
+ MGLMapCamera * toCamera = [self cameraByTiltingToPitch:pitchNew];
1723
1692
1724
- if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
1725
- && ! [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1693
+ if (! [self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
1694
+ [self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
1726
1695
{
1727
- self.camera = oldCamera;
1728
- } else {
1729
1696
_mbglMap->setPitch(pitchNew, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
1730
1697
}
1731
1698
0 commit comments