summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadia Barbosa <nadiabarbosa@me.com>2018-10-02 16:27:27 -0400
committerNadia Barbosa <nadiabarbosa@me.com>2018-10-02 16:27:27 -0400
commitd6be976e5c611a5aa4fe4f0c2952176df6d3c738 (patch)
tree6f53eb00a010af684e2faa37059d19ed97e5254d
parent53b6b47c4f4408a256ee1fdc8acd37dfc867d117 (diff)
downloadqtlocation-mapboxgl-upstream/user-location-delegate-demo.tar.gz
Add user location annotation offset to debug appupstream/user-location-delegate-demo
-rw-r--r--platform/ios/app/MBXViewController.m62
1 files changed, 62 insertions, 0 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 02652b5490..2a7aa75f07 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -55,6 +55,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) {
MBXSettingsAnnotationsCustomCallout,
MBXSettingsAnnotationsQueryAnnotations,
MBXSettingsAnnotationsCustomUserDot,
+ MBXSettingsOffsetUserLocationAnnotation,
+ MBXSettingsResetUserLocationAnnotationOffset,
MBXSettingsAnnotationsRemoveAnnotations,
MBXSettingsAnnotationSelectRandomOffscreenPointAnnotation,
MBXSettingsAnnotationCenterSelectedAnnotation,
@@ -199,6 +201,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@property (nonatomic) BOOL mapInfoHUDEnabled;
@property (nonatomic) BOOL shouldLimitCameraChanges;
@property (nonatomic) BOOL randomWalk;
+@property (nonatomic) CGPoint userLocationOffset;
@end
@interface MGLMapView (MBXViewController)
@@ -237,6 +240,12 @@ CLLocationCoordinate2D randomWorldCoordinate() {
self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];
self.mapView.showsScale = YES;
self.mapView.showsUserHeadingIndicator = YES;
+
+ if (self.mapView.showsUserLocation) {
+ self.userLocationOffset = [self centerUserLocationAnchorPoint];
+ [self.mapView updateUserLocationAnnotationView];
+ }
+
self.hudLabel.titleLabel.font = [UIFont monospacedDigitSystemFontOfSize:10 weight:UIFontWeightRegular];
if ([MGLAccountManager accessToken].length)
@@ -410,6 +419,8 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@"Add Point With Custom Callout",
@"Query Annotations",
[NSString stringWithFormat:@"%@ Custom User Dot", (_customUserLocationAnnnotationEnabled ? @"Disable" : @"Enable")],
+ @"Offset user location annotation",
+ @"Reset user location annotation offset",
@"Remove Annotations",
@"Select an offscreen point annotation",
@"Center selected annotation",
@@ -542,6 +553,12 @@ CLLocationCoordinate2D randomWorldCoordinate() {
case MBXSettingsAnnotationsCustomUserDot:
[self toggleCustomUserDot];
break;
+ case MBXSettingsOffsetUserLocationAnnotation:
+ [self offsetUserLocationAnnotation];
+ break;
+ case MBXSettingsResetUserLocationAnnotationOffset:
+ [self resetUserLocationAnnotationOffset];
+ break;
case MBXSettingsAnnotationsRemoveAnnotations:
[self.mapView removeAnnotations:self.mapView.annotations];
break;
@@ -1580,6 +1597,47 @@ CLLocationCoordinate2D randomWorldCoordinate() {
self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
}
+- (void)offsetUserLocationAnnotation
+{
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Set anchor point"
+ message:@"Enter a X/Y value"
+ preferredStyle:UIAlertControllerStyleAlert];
+ [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+ textField.keyboardType = UIKeyboardTypeDecimalPad;
+ textField.placeholder = @"Center X offset";
+ }];
+
+ [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
+ textField.keyboardType = UIKeyboardTypeDecimalPad;
+ textField.placeholder = @"Center Y offset";
+ }];
+
+ UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * action) {
+ CGFloat xOffset = [alert.textFields[0].text floatValue];
+ CGFloat yOffset = [alert.textFields[1].text floatValue];
+
+ self.userLocationOffset = CGPointMake(xOffset, yOffset);
+ [self.mapView updateUserLocationAnnotationView];
+ }];
+
+ [alert addAction:defaultAction];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)resetUserLocationAnnotationOffset
+{
+ self.userLocationOffset = [self centerUserLocationAnchorPoint];
+ [self.mapView updateUserLocationAnnotationView];
+}
+
+-(CGPoint)centerUserLocationAnchorPoint
+{
+ CGFloat centerX = CGRectGetMidX(self.mapView.frame);
+ CGFloat centerY = CGRectGetMidY(self.mapView.frame) - self.mapView.contentInset.top;
+ return CGPointMake(centerX, centerY);
+}
+
- (void)testQueryPointAnnotations {
NSNumber *visibleAnnotationCount = @(self.mapView.visibleAnnotations.count);
NSString *message;
@@ -2114,6 +2172,10 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}];
}
+- (CGPoint)mapViewUserLocationAnchorPoint:(MGLMapView *)mapView {
+ return self.userLocationOffset;
+}
+
- (nullable id <MGLCalloutView>)mapView:(__unused MGLMapView *)mapView calloutViewForAnnotation:(id<MGLAnnotation>)annotation
{
if ([annotation respondsToSelector:@selector(title)]