summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
authorJason Wray <friedbunny@users.noreply.github.com>2018-03-02 13:13:57 -0500
committerGitHub <noreply@github.com>2018-03-02 13:13:57 -0500
commit4919099ea9c7e5d2a0ed261b169c7c6a0e86a43f (patch)
tree3cc8f47f1caf4d0c4cefa561bf35dd2a83f9bd10 /platform/ios/src/MGLMapView.mm
parent4408e2f0bc00019bd6da07514a1117a129cca96f (diff)
downloadqtlocation-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/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm32
1 files changed, 26 insertions, 6 deletions
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