Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] show/hide scale bar
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni committed Apr 3, 2017
1 parent e28f976 commit e545cb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,14 @@ 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.
Expand Down
8 changes: 6 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ - (void)commonInit
_scaleBarView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_scaleBarView];
_scaleControlViewConstraints = [NSMutableArray array];

_showsScale = YES;

// setup interaction
//
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
Expand Down Expand Up @@ -4804,7 +4805,10 @@ - (void)cameraIsChanging {
}

[self updateCompass];
self.scaleBarView.metersPerPoint = [self metersPerPointAtLatitude:self.centerCoordinate.latitude];

if (self.showsScale) {
self.scaleBarView.metersPerPoint = [self metersPerPointAtLatitude:self.centerCoordinate.latitude];
}

if ([self.delegate respondsToSelector:@selector(mapViewRegionIsChanging:)])
{
Expand Down

0 comments on commit e545cb5

Please sign in to comment.