Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] fix user annotation view refresh when switched from course to none
Browse files Browse the repository at this point in the history
  • Loading branch information
muZZkat authored and friedbunny committed Oct 29, 2015
1 parent 58c90ac commit f8c75c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
4 changes: 4 additions & 0 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2628,6 +2628,10 @@ - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated
{
[self.locationManager stopUpdatingHeading];

// Immediately update the annotation view; other cases update inside
// the locationManager:didUpdateLocations: method.
[self updateUserLocationAnnotationView];

break;
}
case MGLUserTrackingModeFollow:
Expand Down
84 changes: 46 additions & 38 deletions platform/ios/MGLUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//
Expand Down

0 comments on commit f8c75c6

Please sign in to comment.