diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index e75f90dd5d2..9f0bdb13fa4 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -5,6 +5,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ## master * The error passed into `-[MGLMapViewDelegate mapViewDidFailLoadingMap:withError:]` now includes a more specific description and failure reason. ([#8418](https://github.com/mapbox/mapbox-gl-native/pull/8418)) +* Added a scale bar to MGLMapView that indicates the scale of the map. ([#7631](https://github.com/mapbox/mapbox-gl-native/pull/7631)) ## 3.5.0 diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 3056c48e97d..de272fe7ea9 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -81,10 +81,6 @@ 3557F7B21E1D27D300CCA5E6 /* MGLDistanceFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3557F7AF1E1D27D300CCA5E6 /* MGLDistanceFormatter.m */; }; 35599DED1D46F14E0048254D /* MGLStyleValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */; }; 35599DEE1D46F14E0048254D /* MGLStyleValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */; }; - 355ADFFD1E9281DA00F3939D /* MGLScaleBarView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 355ADFFA1E9281DA00F3939D /* MGLScaleBarView_Private.h */; }; - 355ADFFE1E9281DA00F3939D /* MGLScaleBarView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 355ADFFA1E9281DA00F3939D /* MGLScaleBarView_Private.h */; }; - 355ADFFF1E9281DA00F3939D /* MGLScaleBarView.h in Headers */ = {isa = PBXBuildFile; fileRef = 355ADFFB1E9281DA00F3939D /* MGLScaleBarView.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 355AE0001E9281DA00F3939D /* MGLScaleBarView.h in Headers */ = {isa = PBXBuildFile; fileRef = 355ADFFB1E9281DA00F3939D /* MGLScaleBarView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 355AE0011E9281DA00F3939D /* MGLScaleBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = 355ADFFC1E9281DA00F3939D /* MGLScaleBarView.m */; }; 355AE0021E9281DA00F3939D /* MGLScaleBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = 355ADFFC1E9281DA00F3939D /* MGLScaleBarView.m */; }; 3566C7661D4A77BA008152BC /* MGLShapeSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3566C7641D4A77BA008152BC /* MGLShapeSource.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -582,7 +578,6 @@ 3557F7AE1E1D27D300CCA5E6 /* MGLDistanceFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLDistanceFormatter.h; sourceTree = ""; }; 3557F7AF1E1D27D300CCA5E6 /* MGLDistanceFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLDistanceFormatter.m; sourceTree = ""; }; 35599DEA1D46F14E0048254D /* MGLStyleValue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLStyleValue.mm; sourceTree = ""; }; - 355ADFFA1E9281DA00F3939D /* MGLScaleBarView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLScaleBarView_Private.h; sourceTree = ""; }; 355ADFFB1E9281DA00F3939D /* MGLScaleBarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLScaleBarView.h; sourceTree = ""; }; 355ADFFC1E9281DA00F3939D /* MGLScaleBarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLScaleBarView.m; sourceTree = ""; }; 3566C7641D4A77BA008152BC /* MGLShapeSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLShapeSource.h; sourceTree = ""; }; @@ -1041,7 +1036,6 @@ 355ADFF91E9281C300F3939D /* Views */ = { isa = PBXGroup; children = ( - 355ADFFA1E9281DA00F3939D /* MGLScaleBarView_Private.h */, 355ADFFB1E9281DA00F3939D /* MGLScaleBarView.h */, 355ADFFC1E9281DA00F3939D /* MGLScaleBarView.m */, ); @@ -1602,7 +1596,6 @@ 350098DC1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */, DA8848231CBAFA6200AB86E3 /* MGLOfflineStorage_Private.h in Headers */, 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */, - 355ADFFF1E9281DA00F3939D /* MGLScaleBarView.h in Headers */, DA88483B1CBAFB8500AB86E3 /* MGLCalloutView.h in Headers */, 35E0CFE61D3E501500188327 /* MGLStyle_Private.h in Headers */, 3510FFF01D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h in Headers */, @@ -1631,7 +1624,6 @@ DD0902AB1DB192A800C5BDCE /* MGLNetworkConfiguration.h in Headers */, DA8848571CBAFB9800AB86E3 /* MGLMapboxEvents.h in Headers */, DA8848311CBAFA6200AB86E3 /* NSString+MGLAdditions.h in Headers */, - 355ADFFD1E9281DA00F3939D /* MGLScaleBarView_Private.h in Headers */, 353933F81D3FB79F003F57D7 /* MGLLineStyleLayer.h in Headers */, DAAF722D1DA903C700312FA4 /* MGLStyleValue_Private.h in Headers */, DA8847F41CBAFA5100AB86E3 /* MGLOfflinePack.h in Headers */, @@ -1750,12 +1742,10 @@ 353933F31D3FB753003F57D7 /* MGLCircleStyleLayer.h in Headers */, 558DE7A11E5615E400C7916D /* MGLFoundation_Private.h in Headers */, 3538AA1E1D542239008EC33D /* MGLForegroundStyleLayer.h in Headers */, - 355AE0001E9281DA00F3939D /* MGLScaleBarView.h in Headers */, 30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */, 40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */, DABFB8631CBE99E500D62B32 /* MGLOfflineRegion.h in Headers */, DA35A2B21CCA141D00E826B2 /* MGLCompassDirectionFormatter.h in Headers */, - 355ADFFE1E9281DA00F3939D /* MGLScaleBarView_Private.h in Headers */, DAF0D8141DFE0EC500B28378 /* MGLVectorSource_Private.h in Headers */, DABFB8731CBE9A9900D62B32 /* Mapbox.h in Headers */, 357FE2DE1E02D2B20068B753 /* NSCoder+MGLAdditions.h in Headers */, diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index a5aca24b2a0..f7155401f87 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -225,6 +225,15 @@ IB_DESIGNABLE */ - (IBAction)reloadStyle:(id)sender; +/** + A control indicating the scale of the map. + + The scale bar becomes visible when a user interacts with the + map and fades out when the interaction stops. It’s positioned + in the upper-left corner. + */ +@property (nonatomic, readonly) UIView *scaleBarView; + /** A control indicating the map’s direction and allowing the user to manipulate the direction, positioned in the upper-right corner. @@ -594,14 +603,6 @@ IB_DESIGNABLE */ @property (nonatomic) CLLocationDirection direction; -/** - Indicates whether the scale bar should become visible when a user interacts with - the map. The scale bar will fade out automatically when the interaction stops. - - The default value for this property is `YES`. - */ -@property (nonatomic) BOOL showsScale; - /** Changes the heading of the map and optionally animates the change. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 8ef4660d558..4d23a8767ea 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -54,7 +54,7 @@ #import "MGLUserLocation_Private.h" #import "MGLAnnotationImage_Private.h" #import "MGLAnnotationView_Private.h" -#import "MGLScaleBarView_Private.h" +#import "MGLScaleBarView.h" #import "MGLStyle_Private.h" #import "MGLStyleLayer_Private.h" #import "MGLMapboxEvents.h" @@ -506,7 +506,6 @@ - (void)commonInit _scaleBarView.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:_scaleBarView]; _scaleControlViewConstraints = [NSMutableArray array]; - _showsScale = YES; // setup interaction // @@ -4806,8 +4805,8 @@ - (void)cameraIsChanging { [self updateCompass]; - if (self.showsScale) { - self.scaleBarView.metersPerPoint = [self metersPerPointAtLatitude:self.centerCoordinate.latitude]; + if (!self.scaleBarView.hidden) { + [(MGLScaleBarView *)self.scaleBarView setMetersPerPoint:[self metersPerPointAtLatitude:self.centerCoordinate.latitude]]; } if ([self.delegate respondsToSelector:@selector(mapViewRegionIsChanging:)]) @@ -5200,7 +5199,7 @@ - (CGPoint)userLocationAnnotationViewCenter - (void)notifyScaleBarGestureDidEnd { - [self.scaleBarView fadeOut]; + [(MGLScaleBarView *)self.scaleBarView fadeOut]; } - (void)updateCompass diff --git a/platform/ios/src/MGLScaleBarView.h b/platform/ios/src/MGLScaleBarView.h index c34fa8c67d0..585d8b42d12 100644 --- a/platform/ios/src/MGLScaleBarView.h +++ b/platform/ios/src/MGLScaleBarView.h @@ -1,5 +1,10 @@ #import +#import @interface MGLScaleBarView : UIView +@property (nonatomic, assign) CLLocationDistance metersPerPoint; + +- (void)fadeOut; + @end diff --git a/platform/ios/src/MGLScaleBarView.m b/platform/ios/src/MGLScaleBarView.m index ba5bc6ebb46..1b11f796ca7 100644 --- a/platform/ios/src/MGLScaleBarView.m +++ b/platform/ios/src/MGLScaleBarView.m @@ -1,12 +1,11 @@ #import +#import "MGLScaleBarView.h" -#import "MGLScaleBarView_Private.h" @class MGLScaleBarLabel; @interface MGLScaleBarView() @property (nonatomic, assign, getter=isVisible) BOOL visible; -@property (nonatomic, assign) CLLocationDistance metersPerPoint; @property (nonatomic) NSArray *labels; @property (nonatomic) NSArray *bars; @property (nonatomic) UIView *containerView; diff --git a/platform/ios/src/MGLScaleBarView_Private.h b/platform/ios/src/MGLScaleBarView_Private.h deleted file mode 100644 index 13f35fc33fc..00000000000 --- a/platform/ios/src/MGLScaleBarView_Private.h +++ /dev/null @@ -1,12 +0,0 @@ -#import -#import - -#import "MGLScaleBarView.h" - -@interface MGLScaleBarView (Private) - -@property (nonatomic, assign) CLLocationDistance metersPerPoint; - -- (void)fadeOut; - -@end