summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2018-03-08 14:52:43 -0500
committerJason Wray <jason@mapbox.com>2018-03-14 15:46:43 -0400
commit4acd671a65d699903563e5313bf879392f754fd2 (patch)
tree312c1361f3deab2983d1dd5d2041a45f8eb060eb
parentd37edadacbe20cd9fa71100d53098291ee7ea619 (diff)
downloadqtlocation-mapboxgl-4acd671a65d699903563e5313bf879392f754fd2.tar.gz
[ios] Add camera limit debug option to iosapp
Adapted from https://github.com/mapbox/ios-sdk-examples/blob/cdff47276d261d58c7eb2d0ba75d9cce6c308417/Examples/ObjectiveC/BlockingGesturesDelegateExample.m
-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 4da810a7af..a472e3a221 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) {
@@ -86,6 +91,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousToggleTwoMaps,
MBXSettingsMiscellaneousCountryLabels,
MBXSettingsMiscellaneousShowSnapshots,
+ MBXSettingsMiscellaneousShouldLimitCameraChanges,
MBXSettingsMiscellaneousPrintLogFile,
MBXSettingsMiscellaneousDeleteLogFile,
};
@@ -124,6 +130,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@property (nonatomic) BOOL usingLocaleBasedCountryLabels;
@property (nonatomic) BOOL reuseQueueStatsEnabled;
@property (nonatomic) BOOL showZoomLevelEnabled;
+@property (nonatomic) BOOL shouldLimitCameraChanges;
@end
@@ -371,7 +378,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)
@@ -663,6 +671,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;
@@ -1886,6 +1902,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];