summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-07-09 15:47:01 -0700
committerJason Wray <jason@mapbox.com>2019-07-09 16:10:20 -0700
commit593e8cb210934b0422f77797a4748b7ef1ef1e2b (patch)
tree6a4ca3fda1f7e045420bc4c48e84b3362f5d7066
parent08a4ab802a6591d64f9e6a9f517083093a4c1b08 (diff)
downloadqtlocation-mapboxgl-593e8cb210934b0422f77797a4748b7ef1ef1e2b.tar.gz
Add MGLCompassButton_Private.h, move gesture to view implementation
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj6
-rw-r--r--platform/ios/src/MGLCompassButton.h7
-rw-r--r--platform/ios/src/MGLCompassButton.mm20
-rw-r--r--platform/ios/src/MGLCompassButton_Private.h20
-rw-r--r--platform/ios/src/MGLMapView.mm24
5 files changed, 48 insertions, 29 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index eb12c046e9..2d9f82e27e 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -372,6 +372,8 @@
9620BB3B1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */; };
9621F2502091020E005B3800 /* NSExpression+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3510FFEE1D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
96381C0222C6F3950053497D /* MGLMapViewPitchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 96381C0122C6F3950053497D /* MGLMapViewPitchTests.m */; };
+ 9641771F22D546DA00332422 /* MGLCompassButton_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9641771E22D546DA00332422 /* MGLCompassButton_Private.h */; };
+ 9641772022D546DA00332422 /* MGLCompassButton_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9641771E22D546DA00332422 /* MGLCompassButton_Private.h */; };
9654C1261FFC1AB900DB6A19 /* MGLPolyline_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9654C1251FFC1AB900DB6A19 /* MGLPolyline_Private.h */; };
9654C1291FFC1CCD00DB6A19 /* MGLPolygon_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9654C1271FFC1CC000DB6A19 /* MGLPolygon_Private.h */; };
9658C155204761FC00D8A674 /* MGLMapViewScaleBarTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9658C154204761FC00D8A674 /* MGLMapViewScaleBarTests.m */; };
@@ -1109,6 +1111,7 @@
9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLSDKUpdateChecker.h; sourceTree = "<group>"; };
9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MGLSDKUpdateChecker.mm; sourceTree = "<group>"; };
96381C0122C6F3950053497D /* MGLMapViewPitchTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewPitchTests.m; sourceTree = "<group>"; };
+ 9641771E22D546DA00332422 /* MGLCompassButton_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLCompassButton_Private.h; sourceTree = "<group>"; };
9654C1251FFC1AB900DB6A19 /* MGLPolyline_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPolyline_Private.h; sourceTree = "<group>"; };
9654C1271FFC1CC000DB6A19 /* MGLPolygon_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLPolygon_Private.h; sourceTree = "<group>"; };
9658C154204761FC00D8A674 /* MGLMapViewScaleBarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLMapViewScaleBarTests.m; sourceTree = "<group>"; };
@@ -1667,6 +1670,7 @@
isa = PBXGroup;
children = (
96E6145722CC169000109F14 /* MGLCompassButton.h */,
+ 9641771E22D546DA00332422 /* MGLCompassButton_Private.h */,
96E6145822CC169000109F14 /* MGLCompassButton.mm */,
355ADFFB1E9281DA00F3939D /* MGLScaleBar.h */,
355ADFFC1E9281DA00F3939D /* MGLScaleBar.mm */,
@@ -2422,6 +2426,7 @@
DA35A2BB1CCA9A6900E826B2 /* MGLClockDirectionFormatter.h in Headers */,
353933FE1D3FB7DD003F57D7 /* MGLSymbolStyleLayer.h in Headers */,
DA8848201CBAFA6200AB86E3 /* MGLOfflinePack_Private.h in Headers */,
+ 9641771F22D546DA00332422 /* MGLCompassButton_Private.h in Headers */,
DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */,
DA8847FA1CBAFA5100AB86E3 /* MGLPolyline.h in Headers */,
3566C7711D4A9198008152BC /* MGLSource_Private.h in Headers */,
@@ -2614,6 +2619,7 @@
96E516DE200054F700A02306 /* MGLGeometry_Private.h in Headers */,
353933FC1D3FB7C0003F57D7 /* MGLRasterStyleLayer.h in Headers */,
3566C76D1D4A8DFA008152BC /* MGLRasterTileSource.h in Headers */,
+ 9641772022D546DA00332422 /* MGLCompassButton_Private.h in Headers */,
DAED38641D62D0FC00D7640F /* NSURL+MGLAdditions.h in Headers */,
DABFB85E1CBE99E500D62B32 /* MGLAnnotation.h in Headers */,
DABFB8641CBE99E500D62B32 /* MGLOfflineStorage.h in Headers */,
diff --git a/platform/ios/src/MGLCompassButton.h b/platform/ios/src/MGLCompassButton.h
index f42d5f315d..081b89e762 100644
--- a/platform/ios/src/MGLCompassButton.h
+++ b/platform/ios/src/MGLCompassButton.h
@@ -1,7 +1,6 @@
#import <UIKit/UIKit.h>
-#import <CoreLocation/CoreLocation.h>
-#import "MGLTypes.h"
+#import <Mapbox/MGLTypes.h>
NS_ASSUME_NONNULL_BEGIN
@@ -17,10 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign) MGLOrnamentVisibility compassVisibility;
-// TODO: Make these private
-+ (instancetype)compassButton;
-- (void)updateCompassWithDirection:(CLLocationDirection)direction;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLCompassButton.mm b/platform/ios/src/MGLCompassButton.mm
index 6d62793915..9d0ade4121 100644
--- a/platform/ios/src/MGLCompassButton.mm
+++ b/platform/ios/src/MGLCompassButton.mm
@@ -1,4 +1,4 @@
-#import "MGLCompassButton.h"
+#import "MGLCompassButton_Private.h"
#import "MGLCompassDirectionFormatter.h"
#import <Mapbox/MGLGeometry.h>
@@ -11,18 +11,20 @@
@interface MGLCompassButton ()
+@property (nonatomic, weak) MGLMapView *mapView;
@property (nonatomic) MGLCompassDirectionFormatter *accessibilityCompassFormatter;
@end
@implementation MGLCompassButton
-+ (instancetype)compassButton {
- return [[MGLCompassButton alloc] init];
++ (instancetype)compassButtonWithMapView:(MGLMapView *)mapView {
+ return [[MGLCompassButton alloc] initWithMapView:mapView];
}
-- (instancetype)init {
+- (instancetype)initWithMapView:(MGLMapView *)mapView {
if (self = [super init]) {
+ self.mapView = mapView;
[self commonInit];
}
return self;
@@ -37,6 +39,9 @@
self.userInteractionEnabled = YES;
self.translatesAutoresizingMaskIntoConstraints = NO;
+ UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
+ [self addGestureRecognizer:tapGesture];
+
self.accessibilityTraits = UIAccessibilityTraitButton;
self.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label");
self.accessibilityHint = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_HINT", nil, nil, @"Rotates the map to face due north", @"Accessibility hint");
@@ -66,8 +71,11 @@
return image;
}
-- (void)updateCompassWithDirection:(CLLocationDirection)direction
-{
+- (void)handleTapGesture:(__unused UITapGestureRecognizer *)sender {
+ [self.mapView resetNorth];
+}
+
+- (void)updateCompassWithDirection:(CLLocationDirection)direction {
CLLocationDirection plateDirection = mbgl::util::wrap(-direction, 0., 360.);
self.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(plateDirection));
diff --git a/platform/ios/src/MGLCompassButton_Private.h b/platform/ios/src/MGLCompassButton_Private.h
new file mode 100644
index 0000000000..50918d8c45
--- /dev/null
+++ b/platform/ios/src/MGLCompassButton_Private.h
@@ -0,0 +1,20 @@
+#import <UIKit/UIKit.h>
+#import <CoreLocation/CoreLocation.h>
+
+#import <Mapbox/MGLCompassButton.h>
+
+@class MGLMapView;
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MGLCompassButton (Private)
+
++ (instancetype)compassButtonWithMapView:(MGLMapView *)mapView;
+
+@property (nonatomic, weak) MGLMapView *mapView;
+
+- (void)updateCompassWithDirection:(CLLocationDirection)direction;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index ec3766c3a0..97617be517 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -55,11 +55,11 @@
#import "MGLUserLocation_Private.h"
#import "MGLAnnotationImage_Private.h"
#import "MGLAnnotationView_Private.h"
+#import "MGLCompassButton_Private.h"
#import "MGLScaleBar.h"
#import "MGLStyle_Private.h"
#import "MGLStyleLayer_Private.h"
#import "MGLMapboxEvents.h"
-#import "MMEConstants.h"
#import "MGLSDKUpdateChecker.h"
#import "MGLCompactCalloutView.h"
#import "MGLAnnotationContainerView.h"
@@ -68,6 +68,7 @@
#import "MGLMapAccessibilityElement.h"
#import "MGLLocationManager_Private.h"
#import "MGLLoggingConfiguration_Private.h"
+#import "MMEConstants.h"
#include <algorithm>
#include <cstdlib>
@@ -534,8 +535,7 @@ public:
// setup compass
//
- _compassView = [MGLCompassButton compassButton];
- [_compassView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCompassTapGesture:)]];
+ _compassView = [MGLCompassButton compassButtonWithMapView:self];
[self addSubview:_compassView];
_compassViewConstraints = [NSMutableArray array];
_compassViewPosition = MGLOrnamentPositionTopRight;
@@ -1492,19 +1492,6 @@ public:
#pragma mark - Gestures -
-- (void)handleCompassTapGesture:(__unused id)sender
-{
- self.cameraChangeReasonBitmask |= MGLCameraChangeReasonResetNorth;
-
- [self resetNorthAnimated:YES];
-
- if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading ||
- self.userTrackingMode == MGLUserTrackingModeFollowWithCourse)
- {
- self.userTrackingMode = MGLUserTrackingModeFollow;
- }
-}
-
- (void)touchesBegan:(__unused NSSet<UITouch *> *)touches withEvent:(__unused UIEvent *)event
{
if (!self.zoomEnabled && !self.pitchEnabled && !self.rotateEnabled && !self.scrollEnabled)
@@ -2517,6 +2504,8 @@ public:
- (void)resetNorthAnimated:(BOOL)animated
{
+ self.cameraChangeReasonBitmask |= MGLCameraChangeReasonResetNorth;
+
[self setDirection:0 animated:animated];
}
@@ -3437,7 +3426,8 @@ public:
MGLLogDebug(@"Setting direction: %f animated: %@", direction, MGLStringFromBOOL(animated));
if ( ! animated && ! self.rotationAllowed) return;
- if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
+ if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading ||
+ self.userTrackingMode == MGLUserTrackingModeFollowWithCourse)
{
self.userTrackingMode = MGLUserTrackingModeFollow;
}