diff options
Diffstat (limited to 'platform')
6 files changed, 54 insertions, 19 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 9a610fc4e6..9057391fe8 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -224,6 +224,7 @@ 966FCF551F3C323500F2B6DE /* MGLUserLocationHeadingArrowLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 966FCF511F3C321000F2B6DE /* MGLUserLocationHeadingArrowLayer.m */; }; 968F36B51E4D128D003A5522 /* MGLDistanceFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3557F7AE1E1D27D300CCA5E6 /* MGLDistanceFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 96E027231E57C76E004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027251E57C76E004B8E66 /* Localizable.strings */; }; + 96F3F73C1F57124B003E2D2C /* MGLUserLocationHeadingIndicator.h in Headers */ = {isa = PBXBuildFile; fileRef = 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */; }; DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8F1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC901D5EEB0D009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */; }; @@ -706,6 +707,7 @@ 96E0272C1E57C7E5004B8E66 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; }; 96E0272D1E57C7E6004B8E66 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = "<group>"; }; 96E0272E1E57C7E7004B8E66 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; }; + 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLUserLocationHeadingIndicator.h; sourceTree = "<group>"; }; DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; }; DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; }; DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; }; @@ -1622,6 +1624,7 @@ 966FCF511F3C321000F2B6DE /* MGLUserLocationHeadingArrowLayer.m */, 966FCF4A1F3A5C9200F2B6DE /* MGLUserLocationHeadingBeamLayer.h */, 966FCF4B1F3A5C9200F2B6DE /* MGLUserLocationHeadingBeamLayer.m */, + 96F3F73B1F5711F1003E2D2C /* MGLUserLocationHeadingIndicator.h */, ); name = Annotations; sourceTree = "<group>"; @@ -1708,6 +1711,7 @@ DA8847F41CBAFA5100AB86E3 /* MGLOfflinePack.h in Headers */, DA88482E1CBAFA6200AB86E3 /* NSException+MGLAdditions.h in Headers */, DA8848551CBAFB9800AB86E3 /* MGLLocationManager.h in Headers */, + 96F3F73C1F57124B003E2D2C /* MGLUserLocationHeadingIndicator.h in Headers */, 408AA8571DAEDA1700022900 /* NSDictionary+MGLAdditions.h in Headers */, DA88483F1CBAFB8500AB86E3 /* MGLUserLocation.h in Headers */, 558DE7A01E5615E400C7916D /* MGLFoundation_Private.h in Headers */, diff --git a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m index ee45865b0a..158bb01d8e 100644 --- a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m +++ b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m @@ -2,8 +2,9 @@ #import "MGLMapView.h" #import "MGLUserLocation.h" -#import "MGLUserLocationHeadingBeamLayer.h" +#import "MGLUserLocationHeadingIndicator.h" #import "MGLUserLocationHeadingArrowLayer.h" +#import "MGLUserLocationHeadingBeamLayer.h" @implementation MGLFaux3DUserLocationAnnotationView { @@ -12,14 +13,13 @@ CALayer *_puckDot; CAShapeLayer *_puckArrow; - MGLUserLocationHeadingBeamLayer *_headingIndicatorLayer; - //MGLUserLocationHeadingArrowLayer *_headingIndicatorLayer; + CALayer<MGLUserLocationHeadingIndicator> *_headingIndicatorLayer; CALayer *_accuracyRingLayer; CALayer *_dotBorderLayer; CALayer *_dotLayer; CALayer *_haloLayer; - double _oldHeadingAccuracy; + CLLocationDirection _oldHeadingAccuracy; CLLocationAccuracy _oldHorizontalAccuracy; double _oldZoom; double _oldPitch; @@ -215,28 +215,43 @@ [self updateFrameWithSize:MGLUserLocationAnnotationDotSize]; } - BOOL showHeadingIndicator = YES;//self.mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading; - - // update heading indicator + // heading indicator (tinted, beam or arrow) // + BOOL headingTrackingModeEnabled = self.mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading; + BOOL showHeadingIndicator = self.mapView.showsUserHeadingIndicator || headingTrackingModeEnabled; + if (showHeadingIndicator) { _headingIndicatorLayer.hidden = NO; CLLocationDirection headingAccuracy = self.userLocation.heading.headingAccuracy; - // heading indicator (tinted, semi-circle) - // + if (([_headingIndicatorLayer isMemberOfClass:[MGLUserLocationHeadingBeamLayer class]] && ! headingTrackingModeEnabled) || + ([_headingIndicatorLayer isMemberOfClass:[MGLUserLocationHeadingArrowLayer class]] && headingTrackingModeEnabled)) + { + [_headingIndicatorLayer removeFromSuperlayer]; + _headingIndicatorLayer = nil; + _oldHeadingAccuracy = -1; + } + if ( ! _headingIndicatorLayer && headingAccuracy) { - _headingIndicatorLayer = [[MGLUserLocationHeadingBeamLayer alloc] initWithUserLocationAnnotationView:self]; - //_headingIndicatorLayer = [[MGLUserLocationHeadingArrowLayer alloc] initWithUserLocationAnnotationView:self]; - [self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer]; + if (headingTrackingModeEnabled) + { + _headingIndicatorLayer = [[MGLUserLocationHeadingBeamLayer alloc] initWithUserLocationAnnotationView:self]; + [self.layer insertSublayer:_headingIndicatorLayer below:_dotBorderLayer]; + } + else + { + _headingIndicatorLayer = [[MGLUserLocationHeadingArrowLayer alloc] initWithUserLocationAnnotationView:self]; + [self.layer addSublayer:_headingIndicatorLayer]; + _headingIndicatorLayer.zPosition = 1; + } } if (_oldHeadingAccuracy != headingAccuracy) { - //[_headingIndicatorLayer updateHeadingAccuracy:headingAccuracy]; - _oldHeadingAccuracy = headingAccuracy; + [_headingIndicatorLayer updateHeadingAccuracy:headingAccuracy]; + _oldHeadingAccuracy = headingAccuracy; } if (self.userLocation.heading.trueHeading >= 0) @@ -256,7 +271,6 @@ _headingIndicatorLayer = nil; } - // update accuracy ring (if zoom or horizontal accuracy have changed) // if (_accuracyRingLayer && (_oldZoom != self.mapView.zoomLevel || _oldHorizontalAccuracy != self.userLocation.location.horizontalAccuracy)) diff --git a/platform/ios/src/MGLUserLocationHeadingArrowLayer.h b/platform/ios/src/MGLUserLocationHeadingArrowLayer.h index 2b7dea4e62..6c01356944 100644 --- a/platform/ios/src/MGLUserLocationHeadingArrowLayer.h +++ b/platform/ios/src/MGLUserLocationHeadingArrowLayer.h @@ -1,9 +1,11 @@ #import <QuartzCore/QuartzCore.h> #import "MGLUserLocationAnnotationView.h" +#import "MGLUserLocationHeadingIndicator.h" -@interface MGLUserLocationHeadingArrowLayer : CAShapeLayer +@interface MGLUserLocationHeadingArrowLayer : CAShapeLayer <MGLUserLocationHeadingIndicator> - (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; +- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; - (void)updateTintColor:(CGColorRef)color; @end 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; } diff --git a/platform/ios/src/MGLUserLocationHeadingBeamLayer.h b/platform/ios/src/MGLUserLocationHeadingBeamLayer.h index 9a5d4a8f14..93f8ea17ab 100644 --- a/platform/ios/src/MGLUserLocationHeadingBeamLayer.h +++ b/platform/ios/src/MGLUserLocationHeadingBeamLayer.h @@ -1,9 +1,10 @@ #import <QuartzCore/QuartzCore.h> #import "MGLUserLocationAnnotationView.h" +#import "MGLUserLocationHeadingIndicator.h" -@interface MGLUserLocationHeadingBeamLayer : CALayer +@interface MGLUserLocationHeadingBeamLayer : CALayer <MGLUserLocationHeadingIndicator> -- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; +- (MGLUserLocationHeadingBeamLayer *)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; - (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; - (void)updateTintColor:(CGColorRef)color; diff --git a/platform/ios/src/MGLUserLocationHeadingIndicator.h b/platform/ios/src/MGLUserLocationHeadingIndicator.h new file mode 100644 index 0000000000..61476b96a2 --- /dev/null +++ b/platform/ios/src/MGLUserLocationHeadingIndicator.h @@ -0,0 +1,10 @@ +#import <QuartzCore/QuartzCore.h> +#import "MGLUserLocationAnnotationView.h" + +@protocol MGLUserLocationHeadingIndicator <NSObject> + +- (instancetype)initWithUserLocationAnnotationView:(MGLUserLocationAnnotationView *)userLocationView; +- (void)updateHeadingAccuracy:(CLLocationDirection)accuracy; +- (void)updateTintColor:(CGColorRef)color; + +@end |