From e76bd031fcefd6434b7414b334239495954b8f40 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Wed, 7 May 2014 17:35:20 -0700 Subject: refs #147: basic "locate me" button in debug UI --- ios/MBXViewController.mm | 46 ++++++++++++++++++++++++++++++++++++++-------- ios/img/locateUser.png | Bin 0 -> 4924 bytes ios/llmr-app.gyp | 3 ++- 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 ios/img/locateUser.png diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index 4d995fc1ed..dcd2271dc2 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -6,12 +6,13 @@ #import #import #import +#import #include #include #include -@interface MBXViewController () +@interface MBXViewController () @property (nonatomic) EAGLContext *context; @property (nonatomic) CGPoint center; @@ -20,6 +21,7 @@ @property (nonatomic) CGFloat quickZoomStart; @property (nonatomic) BOOL debug; @property (nonatomic) UIView *palette; +@property (nonatomic) CLLocationManager *locationManager; @end @@ -62,6 +64,9 @@ MBXViewController *viewController = nullptr; [self setupInteraction]; [self setupDebugUI]; + self.locationManager = [CLLocationManager new]; + self.locationManager.delegate = self; + map->start(); } @@ -117,7 +122,7 @@ MBXViewController *viewController = nullptr; - (void)setupDebugUI { - NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleRaster" ]; + NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleRaster", @"locateUser" ]; CGFloat buttonSize = 40; CGFloat bufferSize = 20; CGFloat alpha = 0.75; @@ -216,6 +221,15 @@ MBXViewController *viewController = nullptr; map->toggleRaster(); } +- (void)locateUser +{ + [NSObject cancelPreviousPerformRequestsWithTarget:self.locationManager selector:@selector(stopUpdatingLocation) object:nil]; + + [self.locationManager startUpdatingLocation]; + + [self.locationManager performSelector:@selector(stopUpdatingLocation) withObject:nil afterDelay:5.0]; +} + #pragma mark - Destruction - (void)dealloc @@ -254,10 +268,17 @@ MBXViewController *viewController = nullptr; #pragma mark - UI gestures -- (void)handlePanGesture:(UIPanGestureRecognizer *)pan +- (void)cancelPreviousActions { map->cancelTransitions(); + [self.locationManager stopUpdatingLocation]; +} + +- (void)handlePanGesture:(UIPanGestureRecognizer *)pan +{ + [self cancelPreviousActions]; + if (pan.state == UIGestureRecognizerStateBegan) { self.center = CGPointMake(0, 0); @@ -289,7 +310,7 @@ MBXViewController *viewController = nullptr; - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch { - map->cancelTransitions(); + [self cancelPreviousActions]; if (pinch.state == UIGestureRecognizerStateBegan) { @@ -341,7 +362,7 @@ MBXViewController *viewController = nullptr; - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate { - map->cancelTransitions(); + [self cancelPreviousActions]; if (rotate.state == UIGestureRecognizerStateBegan) { @@ -369,7 +390,7 @@ MBXViewController *viewController = nullptr; - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap { - map->cancelTransitions(); + [self cancelPreviousActions]; if (doubleTap.state == UIGestureRecognizerStateEnded) { @@ -379,7 +400,7 @@ MBXViewController *viewController = nullptr; - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap { - map->cancelTransitions(); + [self cancelPreviousActions]; if (twoFingerTap.state == UIGestureRecognizerStateEnded) { @@ -389,7 +410,7 @@ MBXViewController *viewController = nullptr; - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom { - map->cancelTransitions(); + [self cancelPreviousActions]; if (quickZoom.state == UIGestureRecognizerStateBegan) { @@ -414,6 +435,15 @@ MBXViewController *viewController = nullptr; return ([validSimultaneousGestures containsObject:[gestureRecognizer class]] && [validSimultaneousGestures containsObject:[otherGestureRecognizer class]]); } +#pragma mark - User location + +- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations +{ + CLLocation *latestLocation = locations.lastObject; + + map->setLonLatZoom(latestLocation.coordinate.longitude, latestLocation.coordinate.latitude, 17, 0.3); +} + class View : public llmr::View { public: View(MBXViewController *controller) : controller(controller) {} diff --git a/ios/img/locateUser.png b/ios/img/locateUser.png new file mode 100644 index 0000000000..e0599e5425 Binary files /dev/null and b/ios/img/locateUser.png differ diff --git a/ios/llmr-app.gyp b/ios/llmr-app.gyp index 6ae1240e22..e40ffe9a1d 100644 --- a/ios/llmr-app.gyp +++ b/ios/llmr-app.gyp @@ -27,7 +27,8 @@ '$(SDKROOT)/System/Library/Frameworks/UIKit.framework', '$(SDKROOT)/System/Library/Frameworks/OpenGLES.framework', '$(SDKROOT)/System/Library/Frameworks/GLKit.framework', - '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework' + '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreLocation.framework' ], }, 'xcode_settings': { -- cgit v1.2.1