diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2018-03-02 13:13:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-02 13:13:57 -0500 |
commit | 4919099ea9c7e5d2a0ed261b169c7c6a0e86a43f (patch) | |
tree | 3cc8f47f1caf4d0c4cefa561bf35dd2a83f9bd10 /platform/ios/src | |
parent | 4408e2f0bc00019bd6da07514a1117a129cca96f (diff) | |
download | qtlocation-mapboxgl-4919099ea9c7e5d2a0ed261b169c7c6a0e86a43f.tar.gz |
[ios] Add MGLMapView.showsScale to control scale bar visibility (#11335)
- Fixes scale bar not being visible until a camera change event.
- Adds IBInspectable for scale bar visibility.
- Add tests of the scale bar being added to the map view
Diffstat (limited to 'platform/ios/src')
-rw-r--r-- | platform/ios/src/MGLMapView+IBAdditions.h | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.h | 11 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 32 |
3 files changed, 37 insertions, 7 deletions
diff --git a/platform/ios/src/MGLMapView+IBAdditions.h b/platform/ios/src/MGLMapView+IBAdditions.h index 6d5351df2b..64016e8319 100644 --- a/platform/ios/src/MGLMapView+IBAdditions.h +++ b/platform/ios/src/MGLMapView+IBAdditions.h @@ -44,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) IBInspectable BOOL allowsTilting; @property (nonatomic) IBInspectable BOOL showsUserLocation; @property (nonatomic) IBInspectable BOOL showsHeading; +@property (nonatomic) IBInspectable BOOL showsScale; @end diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 44130f3c6d..52d28d871c 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -221,8 +221,17 @@ MGL_EXPORT IB_DESIGNABLE - (IBAction)reloadStyle:(id)sender; /** + A Boolean value indicating whether the map may display scale information. + + The scale bar may not be shown at all zoom levels. The view controlled by this + property is available at `scaleBar`. The default value of this property is + `NO`. + */ +@property (nonatomic, assign) BOOL showsScale; + +/** A control indicating the scale of the map. The scale bar is positioned in the - upper-left corner. The scale bar is hidden by default. + upper-left corner. Enable the scale bar via `showsScale`. */ @property (nonatomic, readonly) UIView *scaleBar; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index bb8948150f..5a68736ec5 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -975,8 +975,8 @@ public: - (void)layoutSubviews { // Calling this here instead of in the scale bar itself because if this is done in the - // scale bar instance, it triggers a call to this this `layoutSubviews` method that - // calls `_mbglMap->setSize()` just below that triggers rendering update which triggers + // scale bar instance, it triggers a call to this `layoutSubviews` method that calls + // `_mbglMap->setSize()` just below that triggers rendering update which triggers // another scale bar update which causes a rendering update loop and a major performace // degradation. The only time the scale bar's intrinsic content size _must_ invalidated // is here as a reaction to this object's view dimension changes. @@ -2362,6 +2362,17 @@ public: self.twoFingerDrag.enabled = pitchEnabled; } +- (void)setShowsScale:(BOOL)showsScale +{ + _showsScale = showsScale; + self.scaleBar.hidden = !showsScale; + + if (showsScale) + { + [self updateScaleBar]; + } +} + #pragma mark - Accessibility - - (NSString *)accessibilityValue @@ -5413,10 +5424,7 @@ public: } [self updateCompass]; - - if (!self.scaleBar.hidden) { - [(MGLScaleBar *)self.scaleBar setMetersPerPoint:[self metersPerPointAtLatitude:self.centerCoordinate.latitude]]; - } + [self updateScaleBar]; if ([self.delegate respondsToSelector:@selector(mapView:regionIsChangingWithReason:)]) { @@ -5434,6 +5442,7 @@ public: } [self updateCompass]; + [self updateScaleBar]; if ( ! [self isSuppressingChangeDelimiters]) { @@ -5878,6 +5887,17 @@ public: } } +- (void)updateScaleBar +{ + // Use the `hidden` property (instead of `self.showsScale`) so that we don't + // break developers who still rely on the <4.0.0 approach of directly + // setting this property. + if ( ! self.scaleBar.hidden) + { + [(MGLScaleBar *)self.scaleBar setMetersPerPoint:[self metersPerPointAtLatitude:self.centerCoordinate.latitude]]; + } +} + + (UIImage *)resourceImageNamed:(NSString *)imageName { UIImage *image = [UIImage imageNamed:imageName |