summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2018-03-08 14:52:43 -0500
committerJason Wray <jason@mapbox.com>2018-03-08 17:13:44 -0500
commite690e7cf1e91ba33017575ed9d068f2f38acab03 (patch)
treee586e17232bf9c7850a328c4e9b554c14f723c3b /platform/ios
parentc815c1e2d661ae43584db0e6eed2a2aaf5fe7e14 (diff)
downloadqtlocation-mapboxgl-e690e7cf1e91ba33017575ed9d068f2f38acab03.tar.gz
[ios] Add camera limit debug option to iosappupstream/fb-fix-camera-limit-pinch-drift
Adapted from https://github.com/mapbox/ios-sdk-examples/blob/cdff47276d261d58c7eb2d0ba75d9cce6c308417/Examples/ObjectiveC/BlockingGesturesDelegateExample.m
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/app/MBXViewController.m43
1 files changed, 42 insertions, 1 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 1046644f8c..63b06af583 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -18,6 +18,11 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
{ .latitude = -13.15589555, .longitude = -74.2178961777998 },
};
+static const MGLCoordinateBounds colorado = {
+ .sw = { .latitude = 36.986207, .longitude = -109.049896},
+ .ne = { .latitude = 40.989329, .longitude = -102.062592},
+};
+
static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXViewControllerAnnotationViewReuseIdentifer";
typedef NS_ENUM(NSInteger, MBXSettingsSections) {
@@ -85,6 +90,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousToggleTwoMaps,
MBXSettingsMiscellaneousCountryLabels,
MBXSettingsMiscellaneousShowSnapshots,
+ MBXSettingsMiscellaneousShouldLimitCameraChanges,
MBXSettingsMiscellaneousPrintLogFile,
MBXSettingsMiscellaneousDeleteLogFile,
};
@@ -122,6 +128,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
@property (nonatomic) BOOL reuseQueueStatsEnabled;
@property (nonatomic) BOOL showZoomLevelEnabled;
+@property (nonatomic) BOOL shouldLimitCameraChanges;
@end
@@ -363,7 +370,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@"Embedded Map View",
[NSString stringWithFormat:@"%@ Second Map", ([self.view viewWithTag:2] == nil ? @"Show" : @"Hide")],
[NSString stringWithFormat:@"Show Labels in %@", (_usingLocaleBasedCountryLabels ? @"Default Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
- @"Show Snapshots"
+ @"Show Snapshots",
+ [NSString stringWithFormat:@"%@ Camera Changes", (_shouldLimitCameraChanges ? @"Unlimit" : @"Limit")],
]];
if (self.debugLoggingEnabled)
@@ -652,6 +660,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self performSegueWithIdentifier:@"ShowSnapshots" sender:nil];
break;
}
+ case MBXSettingsMiscellaneousShouldLimitCameraChanges:
+ {
+ self.shouldLimitCameraChanges = !self.shouldLimitCameraChanges;
+ if (self.shouldLimitCameraChanges) {
+ [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(39.748947, -104.995882) zoomLevel:10 direction:0 animated:NO];
+ }
+ break;
+ }
default:
NSAssert(NO, @"All miscellaneous setting rows should be implemented");
break;
@@ -1880,6 +1896,31 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
_usingLocaleBasedCountryLabels = [[self bestLanguageForUser] isEqualToString:@"en"];
}
+- (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera *)oldCamera toCamera:(MGLMapCamera *)newCamera {
+ if (_shouldLimitCameraChanges) {
+ // Get the current camera to restore it after.
+ MGLMapCamera *currentCamera = mapView.camera;
+
+ // From the new camera obtain the center to test if it’s inside the boundaries.
+ CLLocationCoordinate2D newCameraCenter = newCamera.centerCoordinate;
+
+ // Set the map’s visible bounds to newCamera.
+ mapView.camera = newCamera;
+ MGLCoordinateBounds newVisibleCoordinates = mapView.visibleCoordinateBounds;
+
+ // Revert the camera.
+ mapView.camera = currentCamera;
+
+ // Test if the newCameraCenter and newVisibleCoordinates are inside Colorado.
+ BOOL inside = MGLCoordinateInCoordinateBounds(newCameraCenter, colorado);
+ BOOL intersects = MGLCoordinateInCoordinateBounds(newVisibleCoordinates.ne, colorado) && MGLCoordinateInCoordinateBounds(newVisibleCoordinates.sw, colorado);
+
+ return inside && intersects;
+ } else {
+ return YES;
+ }
+}
+
- (void)mapViewRegionIsChanging:(MGLMapView *)mapView
{
[self updateHUD];