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

Expose styling options for the user location annotation. #403

Merged
merged 7 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update documentation
  • Loading branch information
fabian-guerra committed Sep 2, 2020
commit 0322857f115dd7553db22f5b84c6b74c60a34d77
19 changes: 0 additions & 19 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2368,25 +2368,6 @@ - (void)mapView:(nonnull MGLMapView *)mapView didChangeLocationManagerAuthorizat
}
}

- (MGLUserLocationAnnotationViewStyle *)mapViewStyleForDefaultUserLocationAnnotationView:(MGLMapView *)mapView {
MGLUserLocationAnnotationViewStyle *style = [[MGLUserLocationAnnotationViewStyle alloc] init];

style.approximateHaloFillColor = UIColor.redColor;
style.approximateHaloOpacity = 0.15;
style.approximateHaloBorderColor = UIColor.blueColor;
style.approximateHaloBorderWidth = 4.0;

style.puckShadowColor = UIColor.grayColor;
style.puckFillColor = UIColor.cyanColor;
style.puckArrowFillColor = UIColor.cyanColor;
style.puckShadowOpacity = 0.25;

style.haloFillColor = UIColor.cyanColor;


return style;
}

- (void)alertAccuracyChanges {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Mapbox GL works best with your precise location."
message:@"You'll get turn-by-turn directions."
Expand Down
14 changes: 9 additions & 5 deletions platform/ios/src/MGLFaux3DUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ - (void)setTintColor:(UIColor *)tintColor

puckArrowFillColor = style.puckArrowFillColor ? style.puckArrowFillColor : puckArrowFillColor;

approximateFillColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : approximateFillColor;
if (@available(iOS 14, *)) {
approximateFillColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : approximateFillColor;
}

haloFillColor = style.haloFillColor ? style.haloFillColor : haloFillColor;
dotFillColor = style.puckFillColor ? style.puckFillColor : dotFillColor;
Expand Down Expand Up @@ -545,10 +547,12 @@ - (void)drawApproximate

if ([self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
MGLUserLocationAnnotationViewStyle *style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
backgroundColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : backgroundColor;
strokeColor = style.approximateHaloBorderColor ? style.approximateHaloBorderColor : strokeColor;
opacity = style.approximateHaloOpacity;
borderSize = style.approximateHaloBorderWidth;
if (@available(iOS 14, *)) {
backgroundColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : backgroundColor;
strokeColor = style.approximateHaloBorderColor ? style.approximateHaloBorderColor : strokeColor;
opacity = style.approximateHaloOpacity;
borderSize = style.approximateHaloBorderWidth;
}
}

// update approximate ring (if zoom or horizontal accuracy have changed)
Expand Down
26 changes: 13 additions & 13 deletions platform/ios/src/MGLUserLocationAnnotationViewStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@ MGL_EXPORT
@interface MGLUserLocationAnnotationViewStyle : NSObject

/**
The puck's view fill color.
The fill color for the puck view.
*/
@property (nonatomic) UIColor *puckFillColor;
/**
The puck's view shadow color.
The shadow color for the puck view.
*/
@property (nonatomic) UIColor *puckShadowColor;
/**
The puck's view shadow opacity.
The shadow opacity for the puck view.
Set any value between 0.0 and 1.0.
The default value of this property is equal to `0.25`
*/
@property (nonatomic, assign) CGFloat puckShadowOpacity;
/**
The puck's arrow fill color.
The fill color for the arrow puck.
*/
@property (nonatomic) UIColor *puckArrowFillColor;
/**
The puck's halo fill color.
The fill color for the puck view.
*/
@property (nonatomic) UIColor *haloFillColor;
/**
The approximate's view halo fill color.
The halo fill color for the approximate view.
*/
@property (nonatomic) UIColor *approximateHaloFillColor;
@property (nonatomic) UIColor *approximateHaloFillColor API_AVAILABLE(ios(14));
/**
The approximate's view halo border color.
The halo border color for the approximate view.
*/
@property (nonatomic) UIColor *approximateHaloBorderColor;
@property (nonatomic) UIColor *approximateHaloBorderColor API_AVAILABLE(ios(14));
/**
The approximate's view halo border width.
The halo border width for the approximate view.
The default value of this property is equal to `2.0`
*/
@property (nonatomic, assign) CGFloat approximateHaloBorderWidth;
@property (nonatomic, assign) CGFloat approximateHaloBorderWidth API_AVAILABLE(ios(14));
/**
The approximate's view halo opacity.
The halo opacity for the approximate view.
Set any value between 0.0 and 1.0
The default value of this property is equal to `0.15`
*/
@property (nonatomic, assign) CGFloat approximateHaloOpacity;
@property (nonatomic, assign) CGFloat approximateHaloOpacity API_AVAILABLE(ios(14));

@end

Expand Down
6 changes: 4 additions & 2 deletions platform/ios/src/MGLUserLocationAnnotationViewStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ @implementation MGLUserLocationAnnotationViewStyle
- (instancetype)init {
if ((self = [super init])) {
self.puckShadowOpacity = 0.25;
self.approximateHaloBorderWidth = 2.0;
self.approximateHaloOpacity = 0.15;
if (@available(iOS 14, *)) {
self.approximateHaloBorderWidth = 2.0;
self.approximateHaloOpacity = 0.15;
}
}
return self;
}
Expand Down