refs #147: basic "locate me" button in debug UI

This commit is contained in:
Justin R. Miller
2014-05-07 17:35:20 -07:00
parent 2b9fbb0731
commit e76bd031fc
3 changed files with 40 additions and 9 deletions

View File

@@ -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) {}

BIN
ios/img/locateUser.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -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': {