summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2015-03-22 12:14:20 -0700
committerJustin R. Miller <incanus@codesorcery.net>2015-03-22 12:14:20 -0700
commit9dd9bd6e9ddf40ae3ae1746b191ce7d0a8ea0842 (patch)
tree527c5af5b23506f52e1f3f5677457e8648158d58 /platform
parenteded1d90aa4fa607bb5bd804a9da2cdc690aa16d (diff)
downloadqtlocation-mapboxgl-9dd9bd6e9ddf40ae3ae1746b191ce7d0a8ea0842.tar.gz
bring in tweaked compass snapping fixes from @friedbunny
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/MGLMapView.mm20
1 files changed, 19 insertions, 1 deletions
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 8593e9da5c..96ae0b5c25 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -703,6 +703,8 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
[self unrotateIfNeededAnimated:YES];
+ [self snapCompassIfNeeded];
+
[self notifyMapChange:@(mbgl::MapChangeRegionDidChangeAnimated)];
}
}
@@ -1710,7 +1712,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
return (self.zoomLevel > 3);
}
-// correct rotations to north as needed
+// correct rotations to north as needed at low zooms
//
- (void)unrotateIfNeededAnimated:(BOOL)animated
{
@@ -1884,6 +1886,22 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
}
}
+// reset north on very small gesture-induced angles
+//
+- (void)snapCompassIfNeeded
+{
+ double degrees = mbglMap->getBearing() * -1;
+ while (degrees >= 360) degrees -= 360;
+ while (degrees < 0) degrees += 360;
+
+ double tolerance = 7;
+
+ if (self.compass.alpha > 0 && (degrees < tolerance || degrees > 360 - tolerance))
+ {
+ [self resetNorthAnimated:YES];
+ }
+}
+
+ (UIImage *)resourceImageNamed:(NSString *)imageName
{
if ( ! [[imageName pathExtension] length])