diff options
author | Justin R. Miller <incanus@codesorcery.net> | 2014-05-07 17:35:20 -0700 |
---|---|---|
committer | Justin R. Miller <incanus@codesorcery.net> | 2014-05-07 17:35:20 -0700 |
commit | e76bd031fcefd6434b7414b334239495954b8f40 (patch) | |
tree | 2ebc63781e9fc48b1bc06089d54a9e7e5009ed15 | |
parent | 2b9fbb0731c94be0217d3e34d89e06945fce387f (diff) | |
download | qtlocation-mapboxgl-e76bd031fcefd6434b7414b334239495954b8f40.tar.gz |
refs #147: basic "locate me" button in debug UI
-rw-r--r-- | ios/MBXViewController.mm | 46 | ||||
-rw-r--r-- | ios/img/locateUser.png | bin | 0 -> 4924 bytes | |||
-rw-r--r-- | ios/llmr-app.gyp | 3 |
3 files changed, 40 insertions, 9 deletions
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 <OpenGLES/EAGL.h> #import <QuartzCore/QuartzCore.h> #import <GLKit/GLKit.h> +#import <CoreLocation/CoreLocation.h> #include <llmr/llmr.hpp> #include <llmr/platform/platform.hpp> #include <llmr/map/tile.hpp> -@interface MBXViewController () <UIGestureRecognizerDelegate> +@interface MBXViewController () <UIGestureRecognizerDelegate, CLLocationManagerDelegate> @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 Binary files differnew file mode 100644 index 0000000000..e0599e5425 --- /dev/null +++ b/ios/img/locateUser.png 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': { |