From ae398caf9b6591ffe57eee36537661805d9b51a2 Mon Sep 17 00:00:00 2001 From: Murray Hughes Date: Fri, 16 Oct 2015 16:36:49 +0200 Subject: [PATCH 1/2] [ios] fix user annotation view refresh when switched from course to none. --- platform/ios/MGLMapView.mm | 3 + platform/ios/MGLUserLocationAnnotationView.m | 84 +++++++++++--------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 163f3c6c7fa..205fbb85177 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -2656,6 +2656,9 @@ - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated case MGLUserTrackingModeNone: { [self.locationManager stopUpdatingHeading]; + // Only update the annotation view for this case, other cases update the view inside + // the did update location method. + [self updateUserLocationAnnotationView]; break; } diff --git a/platform/ios/MGLUserLocationAnnotationView.m b/platform/ios/MGLUserLocationAnnotationView.m index b477b1088bb..103ec886019 100644 --- a/platform/ios/MGLUserLocationAnnotationView.m +++ b/platform/ios/MGLUserLocationAnnotationView.m @@ -212,56 +212,64 @@ - (void)drawDot _puckDot = nil; _puckArrow = nil; } - + + BOOL showHeadingIndicator = _mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading; + // update heading indicator // - if (_headingIndicatorLayer) + if (showHeadingIndicator) { - _headingIndicatorLayer.hidden = !(_mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading || - _mapView.userTrackingMode == MGLUserTrackingModeFollowWithCourse); - - if (_oldHeadingAccuracy != self.annotation.heading.headingAccuracy) + _headingIndicatorLayer.hidden = NO; + + // heading indicator (tinted, semi-circle) + // + if ( ! _headingIndicatorLayer && self.annotation.heading.headingAccuracy) + { + CGFloat headingIndicatorSize = MGLUserLocationAnnotationHaloSize; + + _headingIndicatorLayer = [CALayer layer]; + _headingIndicatorLayer.bounds = CGRectMake(0, 0, headingIndicatorSize, headingIndicatorSize); + _headingIndicatorLayer.position = CGPointMake(super.bounds.size.width / 2.0, super.bounds.size.height / 2.0); + _headingIndicatorLayer.contents = (__bridge id)[[self headingIndicatorTintedGradientImage] CGImage]; + _headingIndicatorLayer.contentsGravity = kCAGravityBottom; + _headingIndicatorLayer.contentsScale = [UIScreen mainScreen].scale; + _headingIndicatorLayer.opacity = 0.4; + _headingIndicatorLayer.shouldRasterize = YES; + _headingIndicatorLayer.rasterizationScale = [UIScreen mainScreen].scale; + _headingIndicatorLayer.drawsAsynchronously = YES; + + [self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer]; + } + + // heading indicator accuracy mask (fan-shaped) + // + if ( ! _headingIndicatorMaskLayer && self.annotation.heading.headingAccuracy) + { + _headingIndicatorMaskLayer = [CAShapeLayer layer]; + _headingIndicatorMaskLayer.frame = _headingIndicatorLayer.bounds; + _headingIndicatorMaskLayer.path = [[self headingIndicatorClippingMask] CGPath]; + + // apply the mask to the halo-radius-sized gradient layer + _headingIndicatorLayer.mask = _headingIndicatorMaskLayer; + + _oldHeadingAccuracy = self.annotation.heading.headingAccuracy; + + } + else if (_oldHeadingAccuracy != self.annotation.heading.headingAccuracy) { // recalculate the clipping mask based on updated accuracy _headingIndicatorMaskLayer.path = [[self headingIndicatorClippingMask] CGPath]; - + _oldHeadingAccuracy = self.annotation.heading.headingAccuracy; } + } - - // heading indicator (tinted, semi-circle) - // - if ( ! _headingIndicatorLayer && self.annotation.heading.headingAccuracy) + else { - CGFloat headingIndicatorSize = MGLUserLocationAnnotationHaloSize; - - _headingIndicatorLayer = [CALayer layer]; - _headingIndicatorLayer.bounds = CGRectMake(0, 0, headingIndicatorSize, headingIndicatorSize); - _headingIndicatorLayer.position = CGPointMake(super.bounds.size.width / 2.0, super.bounds.size.height / 2.0); - _headingIndicatorLayer.contents = (__bridge id)[[self headingIndicatorTintedGradientImage] CGImage]; - _headingIndicatorLayer.contentsGravity = kCAGravityBottom; - _headingIndicatorLayer.contentsScale = [UIScreen mainScreen].scale; - _headingIndicatorLayer.opacity = 0.4; - _headingIndicatorLayer.shouldRasterize = YES; - _headingIndicatorLayer.rasterizationScale = [UIScreen mainScreen].scale; - _headingIndicatorLayer.drawsAsynchronously = YES; - - [self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer]; + _headingIndicatorLayer = nil; + _headingIndicatorMaskLayer = nil; } - // heading indicator accuracy mask (fan-shaped) - // - if ( ! _headingIndicatorMaskLayer && self.annotation.heading.headingAccuracy) - { - _headingIndicatorMaskLayer = [CAShapeLayer layer]; - _headingIndicatorMaskLayer.frame = _headingIndicatorLayer.bounds; - _headingIndicatorMaskLayer.path = [[self headingIndicatorClippingMask] CGPath]; - - // apply the mask to the halo-radius-sized gradient layer - _headingIndicatorLayer.mask = _headingIndicatorMaskLayer; - - _oldHeadingAccuracy = self.annotation.heading.headingAccuracy; - } // update accuracy ring (if zoom or horizontal accuracy have changed) // From d0022ee74ff8df574682a0fb333a695e293b06a4 Mon Sep 17 00:00:00 2001 From: Murray Hughes Date: Sat, 17 Oct 2015 13:35:05 +0200 Subject: [PATCH 2/2] [ios] fix removal of heading view when changing user tracking modes. --- platform/ios/MGLUserLocationAnnotationView.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/ios/MGLUserLocationAnnotationView.m b/platform/ios/MGLUserLocationAnnotationView.m index 103ec886019..cc4f58804ca 100644 --- a/platform/ios/MGLUserLocationAnnotationView.m +++ b/platform/ios/MGLUserLocationAnnotationView.m @@ -266,6 +266,8 @@ - (void)drawDot } else { + [_headingIndicatorLayer removeFromSuperlayer]; + [_headingIndicatorMaskLayer removeFromSuperlayer]; _headingIndicatorLayer = nil; _headingIndicatorMaskLayer = nil; }