From 9cdbac043d0eac4beaa666e15d34ab49ffb3e183 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 23 Aug 2016 11:46:53 -0400 Subject: [PATCH] [ios] Clean-up user location annotation heading calculations - Use MGLRadiansFromDegrees(). - Make indentation more readable. --- .../src/MGLFaux3DUserLocationAnnotationView.m | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m index 2cccc1880..9a3b17a6c 100644 --- a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m +++ b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m @@ -459,10 +459,11 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck - (CGFloat)calculateAccuracyRingSize { - CGFloat latRadians = self.userLocation.coordinate.latitude * M_PI / 180.0f; - CGFloat pixelRadius = self.userLocation.location.horizontalAccuracy / cos(latRadians) / [self.mapView metersPerPointAtLatitude:self.userLocation.coordinate.latitude]; + CGFloat latitudeRadians = MGLRadiansFromDegrees(self.userLocation.coordinate.latitude); + CGFloat metersPerPoint = [self.mapView metersPerPointAtLatitude:self.userLocation.coordinate.latitude]; + CGFloat pixelRadius = self.userLocation.location.horizontalAccuracy / cos(latitudeRadians) / metersPerPoint; - return pixelRadius * 2; + return pixelRadius * 2.0; } - (UIImage *)headingIndicatorTintedGradientImage @@ -479,8 +480,11 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck // gradient from the tint color to no-alpha tint color CGFloat gradientLocations[] = {0.0, 1.0}; CGGradientRef gradient = CGGradientCreateWithColors( - colorSpace, (__bridge CFArrayRef)@[(id)[self.mapView.tintColor CGColor], - (id)[[self.mapView.tintColor colorWithAlphaComponent:0] CGColor]], gradientLocations); + colorSpace, + (__bridge CFArrayRef)@[ + (id)[self.mapView.tintColor CGColor], + (id)[[self.mapView.tintColor colorWithAlphaComponent:0] CGColor]], + gradientLocations); // draw the gradient from the center point to the edge (full halo radius) CGPoint centerPoint = CGPointMake(haloRadius, haloRadius); @@ -513,8 +517,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck // clip the oval to ± incoming accuracy degrees (converted to radians), from the top [ovalPath addArcWithCenter:CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect)) radius:CGRectGetWidth(ovalRect) / 2.0 - startAngle:(-180 + clippingDegrees) * M_PI / 180 - endAngle:-clippingDegrees * M_PI / 180 + startAngle:MGLRadiansFromDegrees(-180 + clippingDegrees) + endAngle:MGLRadiansFromDegrees(-clippingDegrees) clockwise:YES]; [ovalPath addLineToPoint:CGPointMake(CGRectGetMidX(ovalRect), CGRectGetMidY(ovalRect))];