[ios] Set a heading indicator update threshold

This commit is contained in:
Jason Wray
2017-08-14 15:27:07 -04:00
parent 5db97ed96e
commit c35b1cd56b
2 changed files with 12 additions and 4 deletions

View File

@@ -7,6 +7,9 @@ const CGFloat MGLUserLocationAnnotationHaloSize = 115.0;
const CGFloat MGLUserLocationAnnotationPuckSize = 45.0;
const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuckSize * 0.6;
// Threshold in radians between heading indicator rotation updates.
const CGFloat MGLUserLocationHeadingUpdateThreshold = 0.01;
@interface MGLFaux3DUserLocationAnnotationView : MGLUserLocationAnnotationView
@end

View File

@@ -231,10 +231,9 @@
_headingIndicatorLayer = [[MGLUserLocationHeadingBeamLayer alloc] initWithUserLocationAnnotationView:self];
//_headingIndicatorLayer = [[MGLUserLocationHeadingArrowLayer alloc] initWithUserLocationAnnotationView:self];
[self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer];
_oldHeadingAccuracy = headingAccuracy;
}
else if (_oldHeadingAccuracy != headingAccuracy)
if (_oldHeadingAccuracy != headingAccuracy)
{
//[_headingIndicatorLayer updateHeadingAccuracy:headingAccuracy];
_oldHeadingAccuracy = headingAccuracy;
@@ -242,7 +241,13 @@
if (self.userLocation.heading.trueHeading >= 0)
{
_headingIndicatorLayer.affineTransform = CGAffineTransformRotate(CGAffineTransformIdentity, -MGLRadiansFromDegrees(self.mapView.direction - self.userLocation.heading.trueHeading));
CGFloat rotation = -MGLRadiansFromDegrees(self.mapView.direction - self.userLocation.heading.trueHeading);
// Don't rotate if the change is imperceptible.
if (fabs(rotation) > MGLUserLocationHeadingUpdateThreshold)
{
_headingIndicatorLayer.affineTransform = CGAffineTransformRotate(CGAffineTransformIdentity, rotation);
}
}
}
else