Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios] snap to north if interaction ends within ±7° #3403

Merged
merged 1 commit into from
Dec 24, 2015

Conversation

friedbunny
Copy link
Contributor

If a user pinch-rotates and the gesture ends within ±7° of north, reset to north (0°).

This behavior is the same as in MapKit.

First proposed in #938, implemented in #1059, reverted in #1064. (Closes #1064.)

/cc @1ec5

@friedbunny friedbunny added feature GL JS parity For feature parity with Mapbox GL JS iOS Mapbox Maps SDK for iOS labels Dec 23, 2015
@friedbunny friedbunny added this to the ios-v3.1.0 milestone Dec 23, 2015
@friedbunny
Copy link
Contributor Author

Going to leave this convenient iosapp debug code here:

- (void)mapViewRegionIsChanging:(__unused MGLMapView *)mapView
{
    [self updateDirectionDebug];
}
- (void)mapView:(__unused MGLMapView *)mapView regionDidChangeAnimated:(__unused BOOL)animated
{
    [self updateDirectionDebug];
}

- (void)updateDirectionDebug
{
    if (! _directionDebug)
    {
        _directionDebug = [[UILabel alloc] initWithFrame:CGRectMake(250, 100, 100, 50)];
        [self.view addSubview:_directionDebug];
    }

    _directionDebug.text = [NSString stringWithFormat:@"%.2f", self.mapView.direction];
}

@1ec5
Copy link
Contributor

1ec5 commented Dec 23, 2015

Could this be done as part of -unrotateIfNeededAnimated:?

@friedbunny
Copy link
Contributor Author

I'm looking into integrating it in -unrotateIfNeededAnimated:. That does get called rather frequently...

@friedbunny
Copy link
Contributor Author

I went ahead and integrated the snapping with -unrotateIfNeededAnimated:. This will cover more cases and be called more frequently.

I've not copied the delayed animations and disabled user interaction that exists just above in -unrotateIfNeededAnimated: because it does not appear to be necessary.

@@ -3053,6 +3055,10 @@ - (void)unrotateIfNeededAnimated:(BOOL)animated
[self resetNorthAnimated:NO];
}
}
else if (self.compassView.alpha > 0 && (self.direction < snapTolerance || self.direction > 360 - snapTolerance))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the developer hides the compass view? Shouldn’t the map view snap to north regardless?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will look at changing this.

@friedbunny
Copy link
Contributor Author

Ergh, accidentally included iosapp debug code. Will back that out.

@friedbunny friedbunny changed the title [ios] snap compass to north if gesture ends within ±7° [ios] snap to north if interaction ends within ±7° Dec 24, 2015
First proposed in #938, implemented in #1059, reverted in #1064.
@friedbunny
Copy link
Contributor Author

Rebased and squashed.

@friedbunny friedbunny merged commit e4d8494 into master Dec 24, 2015
@friedbunny friedbunny deleted the ios-compass-snap branch December 24, 2015 19:10
@friedbunny friedbunny self-assigned this Jan 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature GL JS parity For feature parity with Mapbox GL JS iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants