summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-08-31 16:45:21 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-08-31 16:45:21 -0700
commitabc1c84fb817a8e31dd1226a633dc895fdae602e (patch)
tree0eef59c9f60a19b722b413f9deef20982cb77b45 /platform
parent119a9fbf776fc488b19668f54cc68998ebdfb12a (diff)
parent831df11ec47cb44f6664490a361ff42ef288ce9b (diff)
downloadqtlocation-mapboxgl-abc1c84fb817a8e31dd1226a633dc895fdae602e.tar.gz
Merge branch 'master' into node
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/settings_nsuserdefaults.mm7
-rw-r--r--platform/ios/MGLMapView.mm125
-rw-r--r--platform/ios/MGLMapboxEvents.h1
-rw-r--r--platform/ios/MGLMapboxEvents.m1
4 files changed, 125 insertions, 9 deletions
diff --git a/platform/darwin/settings_nsuserdefaults.mm b/platform/darwin/settings_nsuserdefaults.mm
index f6f9bbeedb..548ee9b220 100644
--- a/platform/darwin/settings_nsuserdefaults.mm
+++ b/platform/darwin/settings_nsuserdefaults.mm
@@ -11,6 +11,7 @@ Settings_NSUserDefaults::Settings_NSUserDefaults()
@"latitude" : @(latitude),
@"zoom" : @(zoom),
@"bearing" : @(bearing),
+ @"pitch" : @(pitch),
@"userTrackingMode" : @(userTrackingMode),
@"showsUserLocation" : @(showsUserLocation),
@"debug" : @(debug),
@@ -26,9 +27,10 @@ void Settings_NSUserDefaults::load()
latitude = [settings[@"latitude"] doubleValue];
zoom = [settings[@"zoom"] doubleValue];
bearing = [settings[@"bearing"] doubleValue];
+ pitch = [settings[@"pitch"] doubleValue];
debug = [settings[@"debug"] boolValue];
- unsigned uncheckedTrackingMode = [settings[@"trackingMode"] unsignedIntValue];
+ unsigned uncheckedTrackingMode = [settings[@"userTrackingMode"] unsignedIntValue];
if (uncheckedTrackingMode > MGLUserTrackingModeNone &&
uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
{
@@ -44,6 +46,7 @@ void Settings_NSUserDefaults::save()
@"latitude" : @(latitude),
@"zoom" : @(zoom),
@"bearing" : @(bearing),
+ @"pitch" : @(pitch),
@"userTrackingMode" : @(userTrackingMode),
@"showsUserLocation" : @(showsUserLocation),
@"debug" : @(debug),
@@ -54,4 +57,4 @@ void Settings_NSUserDefaults::save()
void Settings_NSUserDefaults::clear()
{
[NSUserDefaults resetStandardUserDefaults];
-} \ No newline at end of file
+}
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 803cef9f5b..4b9f30e298 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -85,6 +85,7 @@ CLLocationDegrees MGLDegreesFromRadians(CGFloat radians)
@property (nonatomic) UIPinchGestureRecognizer *pinch;
@property (nonatomic) UIRotationGestureRecognizer *rotate;
@property (nonatomic) UILongPressGestureRecognizer *quickZoom;
+@property (nonatomic) UIPanGestureRecognizer *twoFingerDrag;
@property (nonatomic) NSMapTable *annotationIDsByAnnotation;
@property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImages;
@property (nonatomic) std::vector<uint32_t> annotationsNearbyLastTap;
@@ -279,7 +280,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
[self addSubview:_attributionButton];
_attributionButtonConstraints = [NSMutableArray array];
- _attributionSheet = [[UIActionSheet alloc] initWithTitle:@"Mapbox for iOS"
+ _attributionSheet = [[UIActionSheet alloc] initWithTitle:@"Mapbox iOS SDK"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
@@ -338,6 +339,15 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
[twoFingerTap requireGestureRecognizerToFail:_pinch];
[twoFingerTap requireGestureRecognizerToFail:_rotate];
[self addGestureRecognizer:twoFingerTap];
+
+ _twoFingerDrag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerDragGesture:)];
+ _twoFingerDrag.minimumNumberOfTouches = 2;
+ _twoFingerDrag.maximumNumberOfTouches = 2;
+ _twoFingerDrag.delegate = self;
+ [_twoFingerDrag requireGestureRecognizerToFail:twoFingerTap];
+ [_twoFingerDrag requireGestureRecognizerToFail:_pan];
+ [self addGestureRecognizer:_twoFingerDrag];
+ _pitchEnabled = YES;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
@@ -1326,6 +1336,59 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
}
}
+- (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
+{
+ if ( ! self.isPitchEnabled) return;
+
+ _mbglMap->cancelTransitions();
+
+ if (twoFingerDrag.state == UIGestureRecognizerStateBegan)
+ {
+ [self trackGestureEvent:MGLEventGesturePitchStart forRecognizer:twoFingerDrag];
+ }
+ else if (twoFingerDrag.state == UIGestureRecognizerStateBegan || twoFingerDrag.state == UIGestureRecognizerStateChanged)
+ {
+ CGFloat gestureDistance = CGPoint([twoFingerDrag translationInView:twoFingerDrag.view]).y;
+ double currentPitch = _mbglMap->getPitch();
+ double minPitch = 0;
+ double maxPitch = 60.0;
+ double slowdown = 20.0;
+
+ double pitchNew = fmax(fmin(currentPitch - (gestureDistance / slowdown), maxPitch), minPitch);
+
+ _mbglMap->setPitch(pitchNew);
+ }
+ else if (twoFingerDrag.state == UIGestureRecognizerStateEnded || twoFingerDrag.state == UIGestureRecognizerStateCancelled)
+ {
+ [self unrotateIfNeededAnimated:YES];
+
+ //[self notifyMapChange:(mbgl::MapChangeRegionDidChange)];
+ }
+
+}
+
+- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
+{
+ if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
+ {
+ UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer;
+
+ if (panGesture.minimumNumberOfTouches == 2)
+ {
+ CGPoint velocity = [panGesture velocityInView:panGesture.view];
+ double gestureAngle = MGLDegreesFromRadians(atan(velocity.y / velocity.x));
+ double horizontalToleranceDegrees = 20.0;
+
+ // cancel if gesture angle is not 90º±20º (more or less vertical)
+ if ( ! (fabs((fabs(gestureAngle) - 90.0)) < horizontalToleranceDegrees))
+ {
+ return NO;
+ }
+ }
+ }
+ return YES;
+}
+
- (void)handleCalloutAccessoryTapGesture:(UITapGestureRecognizer *)tap
{
if ([self.delegate respondsToSelector:@selector(mapView:annotation:calloutAccessoryControlTapped:)])
@@ -1419,6 +1482,11 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
return [NSSet setWithObject:@"allowsRotating"];
}
++ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingPitchEnabled
+{
+ return [NSSet setWithObject:@"allowsPitching"];
+}
+
- (void)setDebugActive:(BOOL)debugActive
{
_mbglMap->setDebug(debugActive);
@@ -1617,6 +1685,25 @@ mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBounds coord
[self setDirection:direction animated:NO];
}
+- (double)pitch
+{
+ return _mbglMap->getPitch();
+}
+
+- (void)setPitch:(double)pitch
+{
+ // constrain pitch to between 0º and 60º
+ //
+ _mbglMap->setPitch(fmax(fmin(pitch, 60), 0));
+
+ //[self notifyMapChange:(mbgl::MapChangeRegionDidChange)];
+}
+
+- (void)resetPitch
+{
+ [self setPitch:0];
+}
+
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view
{
CGPoint convertedPoint = [self convertPoint:point fromView:view];
@@ -2214,7 +2301,15 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
[NSException raise:@"Missing Location Services usage description" format:
@"In iOS 8 and above, this app must have a value for NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in its Info.plist."];
}
- [self.locationManager requestWhenInUseAuthorization];
+ // request location permissions, if both keys exist ask for less permissive
+ if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"])
+ {
+ [self.locationManager requestWhenInUseAuthorization];
+ }
+ else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"])
+ {
+ [self.locationManager requestAlwaysAuthorization];
+ }
}
#endif
@@ -2302,6 +2397,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
break;
}
case MGLUserTrackingModeFollow:
+ case MGLUserTrackingModeFollowWithCourse:
{
self.showsUserLocation = YES;
@@ -2315,7 +2411,6 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
break;
}
case MGLUserTrackingModeFollowWithHeading:
- case MGLUserTrackingModeFollowWithCourse:
{
self.showsUserLocation = YES;
@@ -2622,10 +2717,11 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
{
[self updateCompass];
- if (self.pan.state == UIGestureRecognizerStateChanged ||
- self.pinch.state == UIGestureRecognizerStateChanged ||
- self.rotate.state == UIGestureRecognizerStateChanged ||
- self.quickZoom.state == UIGestureRecognizerStateChanged) return;
+ if (self.pan.state == UIGestureRecognizerStateChanged ||
+ self.pinch.state == UIGestureRecognizerStateChanged ||
+ self.rotate.state == UIGestureRecognizerStateChanged ||
+ self.quickZoom.state == UIGestureRecognizerStateChanged ||
+ self.twoFingerDrag.state == UIGestureRecognizerStateChanged) return;
if (self.isAnimatingGesture) return;
@@ -3059,6 +3155,21 @@ class MBGLView : public mbgl::View
self.rotateEnabled = allowsRotating;
}
++ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingAllowsPitching
+{
+ return [NSSet setWithObject:@"pitchEnabled"];
+}
+
+- (BOOL)allowsPitching
+{
+ return self.pitchEnabled;
+}
+
+- (void)setAllowsPitching:(BOOL)allowsPitching
+{
+ self.pitchEnabled = allowsPitching;
+}
+
- (void)didReceiveMemoryWarning
{
_mbglMap->onLowMemory();
diff --git a/platform/ios/MGLMapboxEvents.h b/platform/ios/MGLMapboxEvents.h
index 9efb53c5ea..45f8094954 100644
--- a/platform/ios/MGLMapboxEvents.h
+++ b/platform/ios/MGLMapboxEvents.h
@@ -30,6 +30,7 @@ extern NSString *const MGLEventGestureQuickZoom;
extern NSString *const MGLEventGesturePanStart;
extern NSString *const MGLEventGesturePinchStart;
extern NSString *const MGLEventGestureRotateStart;
+extern NSString *const MGLEventGesturePitchStart;
typedef NS_DICTIONARY_OF(NSString *, id) MGLMapboxEventAttributes;
typedef NS_MUTABLE_DICTIONARY_OF(NSString *, id) MGLMutableMapboxEventAttributes;
diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m
index 314d50dd01..77e68ddde0 100644
--- a/platform/ios/MGLMapboxEvents.m
+++ b/platform/ios/MGLMapboxEvents.m
@@ -45,6 +45,7 @@ NSString *const MGLEventGestureQuickZoom = @"QuickZoom";
NSString *const MGLEventGesturePanStart = @"Pan";
NSString *const MGLEventGesturePinchStart = @"Pinch";
NSString *const MGLEventGestureRotateStart = @"Rotation";
+NSString *const MGLEventGesturePitchStart = @"Pitch";
const NSUInteger MGLMaximumEventsPerFlush = 20;
const NSTimeInterval MGLFlushInterval = 60;