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
Next Next commit
Change style implementation from struct to an object.
  • Loading branch information
fabian-guerra committed Sep 2, 2020
commit 8a0db7531f897d4b9c8ebea12a30e9ff0ebe8142
4 changes: 2 additions & 2 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2368,8 +2368,8 @@ - (void)mapView:(nonnull MGLMapView *)mapView didChangeLocationManagerAuthorizat
}
}

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

style.approximateHaloFillColor = UIColor.redColor;
style.approximateHaloOpacity = 0.15;
Expand Down
12 changes: 12 additions & 0 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
1F6A82A321360F9D00BA5B41 /* MGLLoggingConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F6A82A021360F9C00BA5B41 /* MGLLoggingConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F6A82A82138871900BA5B41 /* MGLLoggingConfiguration_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F6A82A62138871900BA5B41 /* MGLLoggingConfiguration_Private.h */; };
1F6A82A92138871900BA5B41 /* MGLLoggingConfiguration_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F6A82A62138871900BA5B41 /* MGLLoggingConfiguration_Private.h */; };
1F716F1324FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F716F1124FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F716F1424FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F716F1124FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F716F1524FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F716F1224FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m */; };
1F716F1624FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F716F1224FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m */; };
1F7454921ECBB42C00021D39 /* MGLLight.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F0666891EC64F8E001C16D7 /* MGLLight.mm */; };
1F7454931ECBB43F00021D39 /* MGLLight.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F0666881EC64F8E001C16D7 /* MGLLight.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F7454961ECD450D00021D39 /* MGLLight_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F7454941ECD450D00021D39 /* MGLLight_Private.h */; };
Expand Down Expand Up @@ -826,6 +830,8 @@
1F2B94BF221636D800210640 /* MGLNetworkConfiguration_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLNetworkConfiguration_Private.h; sourceTree = "<group>"; };
1F6A82A021360F9C00BA5B41 /* MGLLoggingConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLLoggingConfiguration.h; sourceTree = "<group>"; };
1F6A82A62138871900BA5B41 /* MGLLoggingConfiguration_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLLoggingConfiguration_Private.h; sourceTree = "<group>"; };
1F716F1124FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationAnnotationViewStyle.h; sourceTree = "<group>"; };
1F716F1224FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLUserLocationAnnotationViewStyle.m; sourceTree = "<group>"; };
1F7454941ECD450D00021D39 /* MGLLight_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLLight_Private.h; sourceTree = "<group>"; };
1F7454A61ED08AB400021D39 /* MGLLightTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLLightTest.mm; path = ../../darwin/test/MGLLightTest.mm; sourceTree = "<group>"; };
1F78399D235AA1E600D4D606 /* libmbgl-core.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libmbgl-core.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -2070,6 +2076,8 @@
5580B45A229570A10091291B /* MGLMapView+OpenGL.mm */,
DA8848371CBAFB8500AB86E3 /* MGLMapView+IBAdditions.h */,
DA737EE01D056A4E005BDA16 /* MGLMapViewDelegate.h */,
1F716F1124FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h */,
1F716F1224FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m */,
);
name = Kit;
path = src;
Expand Down Expand Up @@ -2413,6 +2421,7 @@
DAAF722D1DA903C700312FA4 /* MGLStyleValue_Private.h in Headers */,
071BBB031EE76146001FB02A /* MGLImageSource.h in Headers */,
74CB5EBB219B280400102936 /* MGLFillExtrusionStyleLayer_Private.h in Headers */,
1F716F1324FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h in Headers */,
DA8847F41CBAFA5100AB86E3 /* MGLOfflinePack.h in Headers */,
DA88482E1CBAFA6200AB86E3 /* NSException+MGLAdditions.h in Headers */,
74CB5ED1219B286400102936 /* MGLSymbolStyleLayer_Private.h in Headers */,
Expand Down Expand Up @@ -2582,6 +2591,7 @@
CAC3A3E122E75AC200BC8DEF /* MGLSignpost.h in Headers */,
96E516F02000595800A02306 /* NSBundle+MGLAdditions.h in Headers */,
96E516F920005A3500A02306 /* MGLFaux3DUserLocationAnnotationView.h in Headers */,
1F716F1424FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.h in Headers */,
96E516F22000596D00A02306 /* NSException+MGLAdditions.h in Headers */,
96E516EC2000560B00A02306 /* MGLUserLocationAnnotationView_Private.h in Headers */,
1FC4817F2098CD80000D09B4 /* NSPredicate+MGLPrivateAdditions.h in Headers */,
Expand Down Expand Up @@ -3293,6 +3303,7 @@
AC518E03201BB56000EBC820 /* MGLTelemetryConfig.m in Sources */,
DA8848271CBAFA6200AB86E3 /* MGLPolyline.mm in Sources */,
35CE61841D4165D9004F2359 /* UIColor+MGLAdditions.mm in Sources */,
1F716F1524FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m in Sources */,
3EA93369F61CF70AFA50465D /* MGLRendererConfiguration.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -3395,6 +3406,7 @@
DAA4E41C1CBB730400178DFB /* MGLAccountManager.m in Sources */,
35CE61851D4165D9004F2359 /* UIColor+MGLAdditions.mm in Sources */,
DAA4E4241CBB730400178DFB /* MGLPolyline.mm in Sources */,
1F716F1624FFEA6500C574BD /* MGLUserLocationAnnotationViewStyle.m in Sources */,
3EA9366247780E4F252652A8 /* MGLRendererConfiguration.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
61 changes: 40 additions & 21 deletions platform/ios/src/MGLFaux3DUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "MGLUserLocationHeadingArrowLayer.h"
#import "MGLUserLocationHeadingBeamLayer.h"
#import "MGLLocationManager_Private.h"
#import "MGLUserLocationAnnotationViewStyle.h"

const CGFloat MGLUserLocationAnnotationDotSize = 22.0;
const CGFloat MGLUserLocationAnnotationHaloSize = 115.0;
Expand Down Expand Up @@ -88,25 +89,43 @@ - (void)drawPreciseLocationPuck {

- (void)setTintColor:(UIColor *)tintColor
{
CGColorRef newTintColor = [tintColor CGColor];
UIColor *puckArrowFillColor = tintColor;
UIColor *puckArrowStrokeColor = tintColor;

if (![self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
if (_puckModeActivated)
{
_puckArrow.fillColor = newTintColor;
_puckArrow.strokeColor = newTintColor;
}
else if (_approximateModeActivated)
{
_approximateLayer.backgroundColor = newTintColor;
}
else
{
_accuracyRingLayer.backgroundColor = newTintColor;
_haloLayer.backgroundColor = newTintColor;
_dotLayer.backgroundColor = newTintColor;
[_headingIndicatorLayer updateTintColor:newTintColor];
}
UIColor *approximateFillColor = tintColor;

UIColor *accuracyFillColor = tintColor;
UIColor *haloFillColor = tintColor;
UIColor *dotFillColor = tintColor;
UIColor *headingFillColor = tintColor;

if ([self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
MGLUserLocationAnnotationViewStyle *style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];

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

approximateFillColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : approximateFillColor;

haloFillColor = style.haloFillColor ? style.haloFillColor : haloFillColor;
dotFillColor = style.puckFillColor ? style.puckFillColor : dotFillColor;
headingFillColor = style.puckFillColor ? style.puckFillColor : headingFillColor;
}

if (_puckModeActivated)
{
_puckArrow.fillColor = [puckArrowFillColor CGColor];
_puckArrow.strokeColor = [puckArrowStrokeColor CGColor];
}
else if (_approximateModeActivated)
{
_approximateLayer.backgroundColor = [approximateFillColor CGColor];
}
else
{
_accuracyRingLayer.backgroundColor = [accuracyFillColor CGColor];
_haloLayer.backgroundColor = [haloFillColor CGColor];
_dotLayer.backgroundColor = [dotFillColor CGColor];
[_headingIndicatorLayer updateTintColor:[headingFillColor CGColor]];
}

}
Expand Down Expand Up @@ -189,7 +208,7 @@ - (void)drawPuck


if ([self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
MGLUserLocationAnnotationViewStyle style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
MGLUserLocationAnnotationViewStyle *style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
arrowColor = style.puckArrowFillColor ? style.puckArrowFillColor : arrowColor;
puckShadowColor = style.puckShadowColor ? style.puckShadowColor : puckShadowColor;
shadowOpacity = style.puckShadowOpacity;
Expand Down Expand Up @@ -284,7 +303,7 @@ - (void)drawDot


if ([self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
MGLUserLocationAnnotationViewStyle style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
MGLUserLocationAnnotationViewStyle *style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
haloColor = style.haloFillColor ? style.haloFillColor : haloColor;
puckBackgroundColor = style.puckFillColor ? style.puckFillColor : puckBackgroundColor;
puckShadowColor = style.puckShadowColor ? style.puckShadowColor : puckShadowColor;
Expand Down Expand Up @@ -525,7 +544,7 @@ - (void)drawApproximate
CGFloat opacity = 0.25;

if ([self.mapView.delegate respondsToSelector:@selector(mapViewStyleForDefaultUserLocationAnnotationView:)]) {
MGLUserLocationAnnotationViewStyle style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
MGLUserLocationAnnotationViewStyle *style = [self.mapView.delegate mapViewStyleForDefaultUserLocationAnnotationView:self.mapView];
backgroundColor = style.approximateHaloFillColor ? style.approximateHaloFillColor : backgroundColor;
strokeColor = style.approximateHaloBorderColor ? style.approximateHaloBorderColor : strokeColor;
opacity = style.approximateHaloOpacity;
Expand Down
45 changes: 0 additions & 45 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,51 +133,6 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLMapViewPreferredFramesPerSecond MGLMapView
FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLMissingLocationServicesUsageDescriptionException;
FOUNDATION_EXTERN MGL_EXPORT MGLExceptionName const MGLUserLocationAnnotationTypeException;

/**
A structure containing information about the default User Location annotation view style.
*/
typedef struct __attribute__((objc_boxable)) MGLUserLocationAnnotationViewStyle {
/**
The puck's view fill color.
*/
UIColor *puckFillColor;
/**
The puck's view shadow color.
*/
UIColor *puckShadowColor;
/**
The puck's view shadow opacity.
Set any value between 0.0 and 1.0
*/
CGFloat puckShadowOpacity;
/**
The puck's arrow fill color.
*/
UIColor *puckArrowFillColor;
/**
The puck's halo fill color.
*/
UIColor *haloFillColor;
/**
The approximate's view halo fill color.
*/
UIColor *approximateHaloFillColor;
/**
The approximate's view halo border color.
*/
UIColor *approximateHaloBorderColor;
/**
The approximate's view halo border width.
*/
CGFloat approximateHaloBorderWidth;
/**
The approximate's view halo opacity.
Set any value between 0.0 and 1.0
*/
CGFloat approximateHaloOpacity;

} MGLUserLocationAnnotationViewStyle;

/**
An interactive, customizable map view with an interface similar to the one
provided by Apple’s MapKit.
Expand Down
4 changes: 3 additions & 1 deletion platform/ios/src/MGLMapViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
NS_ASSUME_NONNULL_BEGIN

@class MGLMapView;
@class MGLUserLocationAnnotationViewStyle;

/**
The `MGLMapViewDelegate` protocol defines a set of optional methods that you
Expand Down Expand Up @@ -327,7 +328,8 @@ NS_ASSUME_NONNULL_BEGIN

@param mapView The map view that is tracking the user’s location.
*/
- (MGLUserLocationAnnotationViewStyle)mapViewStyleForDefaultUserLocationAnnotationView:(MGLMapView *)mapView;
- (MGLUserLocationAnnotationViewStyle *)mapViewStyleForDefaultUserLocationAnnotationView:(MGLMapView *)mapView NS_SWIFT_NAME(mapView(styleForDefaultUserLocationAnnotationView:));


/**
Tells the delegate that the location of the user was updated.
Expand Down
57 changes: 57 additions & 0 deletions platform/ios/src/MGLUserLocationAnnotationViewStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#import <UIKit/UIKit.h>

#import "MGLFoundation.h"

NS_ASSUME_NONNULL_BEGIN

/**
A class containing information about the default User Location annotation view style.
*/
MGL_EXPORT
@interface MGLUserLocationAnnotationViewStyle : NSObject

/**
The puck's view fill color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The puck view's fill color.

or, since the possessive form of "view" feels odd here, maybe:

The fill color for the puck view.

*/
@property (nonatomic) UIColor *puckFillColor;
/**
The puck's view shadow color.
*/
@property (nonatomic) UIColor *puckShadowColor;
/**
The puck's view shadow opacity.
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.
*/
@property (nonatomic) UIColor *puckArrowFillColor;
/**
The puck's halo fill color.
*/
@property (nonatomic) UIColor *haloFillColor;
/**
The approximate's view halo fill color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think The halo fill color for the approximate view makes more sense (and for the rest of the properties below).

*/
@property (nonatomic) UIColor *approximateHaloFillColor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we note that any properties for the approximate view will only work in iOS 14+ when the user has enabled approximate location?

/**
The approximate's view halo border color.
*/
@property (nonatomic) UIColor *approximateHaloBorderColor;
/**
The approximate's view halo border width.
The default value of this property is equal to `2.0`
*/
@property (nonatomic, assign) CGFloat approximateHaloBorderWidth;
/**
The approximate's view halo opacity.
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;

@end

NS_ASSUME_NONNULL_END
60 changes: 60 additions & 0 deletions platform/ios/src/MGLUserLocationAnnotationViewStyle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#import "MGLUserLocationAnnotationViewStyle.h"
#import "MGLLoggingConfiguration_Private.h"

@implementation MGLUserLocationAnnotationViewStyle

- (instancetype)init {
if ((self = [super init])) {
self.puckShadowOpacity = 0.25;
self.approximateHaloBorderWidth = 2.0;
self.approximateHaloOpacity = 0.15;
}
return self;
}

- (void)setPuckFillColor:(UIColor *)puckFillColor {
MGLLogDebug(@"Setting puckFillColor: %@", puckFillColor);
_puckFillColor = puckFillColor;
}

- (void)setPuckShadowColor:(UIColor *)puckShadowColor {
MGLLogDebug(@"Setting puckShadowColor: %@", puckShadowColor);
_puckShadowColor = puckShadowColor;
}

- (void)setPuckShadowOpacity:(CGFloat)puckShadowOpacity {
MGLLogDebug(@"Setting puckShadowOpacity: %.2f", puckShadowOpacity);
_puckShadowOpacity = puckShadowOpacity;
}

- (void)setPuckArrowFillColor:(UIColor *)puckArrowFillColor {
MGLLogDebug(@"Setting puckArrowFillColor: %@", puckArrowFillColor);
_puckArrowFillColor = puckArrowFillColor;
}

- (void)setHaloFillColor:(UIColor *)haloFillColor {
MGLLogDebug(@"Setting haloFillColor: %@", haloFillColor);
_haloFillColor = haloFillColor;
}

- (void)setApproximateHaloFillColor:(UIColor *)approximateHaloFillColor {
MGLLogDebug(@"Setting approximateHaloFillColor: %@", approximateHaloFillColor);
_approximateHaloFillColor = approximateHaloFillColor;
}

- (void)setApproximateHaloBorderColor:(UIColor *)approximateHaloBorderColor {
MGLLogDebug(@"Setting approximateHaloBorderColor: %@", approximateHaloBorderColor);
_approximateHaloBorderColor = approximateHaloBorderColor;
}

- (void)setApproximateHaloBorderWidth:(CGFloat)approximateHaloBorderWidth {
MGLLogDebug(@"Setting approximateHaloBorderWidth: %.2f", approximateHaloBorderWidth);
_approximateHaloBorderWidth = approximateHaloBorderWidth;
}

- (void)setApproximateHaloOpacity:(CGFloat)approximateHaloOpacity {
MGLLogDebug(@"Setting approximateHaloOpacity: %.2f", approximateHaloOpacity);
_approximateHaloOpacity = approximateHaloOpacity;
}

@end
1 change: 1 addition & 0 deletions platform/ios/src/Mapbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ FOUNDATION_EXPORT MGL_EXPORT const unsigned char MapboxVersionString[];
#import "NSExpression+MGLAdditions.h"
#import "NSPredicate+MGLAdditions.h"
#import "NSValue+MGLAdditions.h"
#import "MGLUserLocationAnnotationViewStyle.h"
4 changes: 4 additions & 0 deletions platform/ios/test/MGLMapViewDelegateIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ extension MGLMapViewDelegateIntegrationTests: MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false }

func mapView(_ mapView: MGLMapView, didChangeLocationManagerAuthorization manager: MGLLocationManager) {}

func mapView(styleForDefaultUserLocationAnnotationView mapView: MGLMapView) -> MGLUserLocationAnnotationViewStyle { return MGLUserLocationAnnotationViewStyle() }


}