From 5db97ed96ee1b6d5fa7b4ae6065cf5399ae1e2c0 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 10 Aug 2017 14:27:27 -0400 Subject: [ios] Introduce MGLUserLocationHeadingArrowLayer class --- .../ios/src/MGLUserLocationHeadingArrowLayer.m | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 platform/ios/src/MGLUserLocationHeadingArrowLayer.m (limited to 'platform/ios/src/MGLUserLocationHeadingArrowLayer.m') diff --git a/platform/ios/src/MGLUserLocationHeadingArrowLayer.m b/platform/ios/src/MGLUserLocationHeadingArrowLayer.m new file mode 100644 index 0000000000..3365fddb02 --- /dev/null +++ b/platform/ios/src/MGLUserLocationHeadingArrowLayer.m @@ -0,0 +1,55 @@ +#import "MGLUserLocationHeadingArrowLayer.h" + +#import "MGLFaux3DUserLocationAnnotationView.h" +#import "MGLGeometry.h" + +const CGFloat MGLUserLocationHeadingArrowSize = 6; + +@implementation MGLUserLocationHeadingArrowLayer + +- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView +{ + CGFloat size = userLocationView.bounds.size.width + MGLUserLocationHeadingArrowSize; + + self = [super init]; + self.bounds = CGRectMake(0, 0, size, size); + self.position = CGPointMake(CGRectGetMidX(userLocationView.bounds), CGRectGetMidY(userLocationView.bounds)); + self.path = [self arrowPath]; + self.fillColor = userLocationView.tintColor.CGColor; + self.shouldRasterize = YES; + self.rasterizationScale = UIScreen.mainScreen.scale; + self.drawsAsynchronously = YES; + + self.strokeColor = UIColor.whiteColor.CGColor; + self.lineWidth = 1.0; + self.lineJoin = kCALineJoinRound; + + return self; +} + +- (void)updateTintColor:(CGColorRef)color +{ + // redraw the raw tinted gradient + self.fillColor = color; +} + +- (CGPathRef)arrowPath { + CGFloat center = roundf(CGRectGetMidX(self.bounds)); + CGFloat size = MGLUserLocationHeadingArrowSize; + + CGPoint top = CGPointMake(center, 0); + CGPoint left = CGPointMake(center - size, size); + CGPoint right = CGPointMake(center + size, size); + CGPoint middle = CGPointMake(center, size / M_PI); + + UIBezierPath *bezierPath = [UIBezierPath bezierPath]; + [bezierPath moveToPoint:top]; + [bezierPath addLineToPoint:left]; + [bezierPath addQuadCurveToPoint:right controlPoint:middle]; + [bezierPath addLineToPoint:top]; + [bezierPath closePath]; + + return bezierPath.CGPath; +} + +@end -- cgit v1.2.1 From 99616e662704f3c778d002fc711ec1288fd6d142 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Wed, 30 Aug 2017 12:35:20 -0400 Subject: [ios] Introduce MGLUserLocationHeadingIndicator protocol --- platform/ios/src/MGLUserLocationHeadingArrowLayer.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'platform/ios/src/MGLUserLocationHeadingArrowLayer.m') diff --git a/platform/ios/src/MGLUserLocationHeadingArrowLayer.m b/platform/ios/src/MGLUserLocationHeadingArrowLayer.m index 3365fddb02..912ce30c35 100644 --- a/platform/ios/src/MGLUserLocationHeadingArrowLayer.m +++ b/platform/ios/src/MGLUserLocationHeadingArrowLayer.m @@ -27,9 +27,13 @@ const CGFloat MGLUserLocationHeadingArrowSize = 6; return self; } +- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy +{ + // unimplemented +} + - (void)updateTintColor:(CGColorRef)color { - // redraw the raw tinted gradient self.fillColor = color; } -- cgit v1.2.1