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

Commit

Permalink
[ios] added max scale and removed animations
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni committed Apr 12, 2017
1 parent 94fe3ac commit c113e89
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 63 deletions.
2 changes: 1 addition & 1 deletion platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ - (void)viewDidLoad
[self restoreState:nil];

self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"];

self.mapView.scaleBar.hidden = NO;
self.hudLabel.hidden = YES;

if ([MGLAccountManager accessToken].length)
Expand Down
7 changes: 2 additions & 5 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,8 @@ 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. The scale bar is positioned in the upper-left
corner.
A control indicating the scale of the map. The scale bar is positioned in the
upper-left corner.
*/
@property (nonatomic, readonly) UIView *scaleBar;

Expand Down
13 changes: 0 additions & 13 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,6 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan
}

[self notifyGestureDidEndWithDrift:drift];
[self notifyScaleBarGestureDidEnd];

// metrics: pan end
CGPoint pointInView = CGPointMake([pan locationInView:pan.view].x, [pan locationInView:pan.view].y);
Expand Down Expand Up @@ -1385,7 +1384,6 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch

[self notifyGestureDidEndWithDrift:drift];
[self unrotateIfNeededForGesture];
[self notifyScaleBarGestureDidEnd];
}

_previousPinchCenterCoordinate = [self convertPoint:centerPoint toCoordinateFromView:self];
Expand Down Expand Up @@ -1466,7 +1464,6 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
else
{
[self notifyGestureDidEndWithDrift:NO];
[self notifyScaleBarGestureDidEnd];
[self unrotateIfNeededForGesture];
}
}
Expand Down Expand Up @@ -1604,11 +1601,9 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
[self animateWithDelay:MGLAnimationDuration animations:^
{
[weakSelf unrotateIfNeededForGesture];
[weakSelf notifyScaleBarGestureDidEnd];
}];
} else {
[self unrotateIfNeededForGesture];
[self notifyScaleBarGestureDidEnd];
}
}
}
Expand Down Expand Up @@ -1646,7 +1641,6 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
[self animateWithDelay:MGLAnimationDuration animations:^
{
[weakSelf unrotateIfNeededForGesture];
[weakSelf notifyScaleBarGestureDidEnd];
}];
}
}
Expand Down Expand Up @@ -1698,7 +1692,6 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
else if (quickZoom.state == UIGestureRecognizerStateEnded || quickZoom.state == UIGestureRecognizerStateCancelled)
{
[self notifyGestureDidEndWithDrift:NO];
[self notifyScaleBarGestureDidEnd];
[self unrotateIfNeededForGesture];
}
}
Expand Down Expand Up @@ -1738,7 +1731,6 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag
else if (twoFingerDrag.state == UIGestureRecognizerStateEnded || twoFingerDrag.state == UIGestureRecognizerStateCancelled)
{
[self notifyGestureDidEndWithDrift:NO];
[self notifyScaleBarGestureDidEnd];
[self unrotateIfNeededForGesture];
}

Expand Down Expand Up @@ -5205,11 +5197,6 @@ - (CGPoint)userLocationAnnotationViewCenter
return center;
}

- (void)notifyScaleBarGestureDidEnd
{
[(MGLScaleBar *)self.scaleBar fadeOut];
}

- (void)updateCompass
{
CLLocationDirection direction = self.direction;
Expand Down
5 changes: 1 addition & 4 deletions platform/ios/src/MGLScaleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

@interface MGLScaleBar : UIView

// Sets the scale and fades in the scale bar
// Sets the scale and redraws the scale bar
@property (nonatomic, assign) CLLocationDistance metersPerPoint;

// Fades out the scale bar
- (void)fadeOut;

@end
58 changes: 18 additions & 40 deletions platform/ios/src/MGLScaleBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
{.distance = 500000, .numberOfBars = 2},
{.distance = 600000, .numberOfBars = 3},
{.distance = 800000, .numberOfBars = 2},
{.distance = 1000000, .numberOfBars = 2},
{.distance = 1200000, .numberOfBars = 2},
{.distance = 1600000, .numberOfBars = 2},
{.distance = 2000000, .numberOfBars = 2},
{.distance = 3500000, .numberOfBars = 2},
{.distance = 5000000, .numberOfBars = 2},
};

static const MGLRow MGLImperialTable[] ={
Expand Down Expand Up @@ -76,17 +70,11 @@
{.distance = 200*MGLFeetPerMile, .numberOfBars = 2},
{.distance = 300*MGLFeetPerMile, .numberOfBars = 3},
{.distance = 400*MGLFeetPerMile, .numberOfBars = 2},
{.distance = 800*MGLFeetPerMile, .numberOfBars = 2},
{.distance = 1000*MGLFeetPerMile, .numberOfBars = 2},
{.distance = 2000*MGLFeetPerMile, .numberOfBars = 2},
{.distance = 3000*MGLFeetPerMile, .numberOfBars = 3},
{.distance = 4000*MGLFeetPerMile, .numberOfBars = 2},
};

@class MGLScaleBarLabel;

@interface MGLScaleBar()
@property (nonatomic, assign, getter=isVisible) BOOL visible;
@property (nonatomic) NSArray<MGLScaleBarLabel *> *labels;
@property (nonatomic) NSArray<UIView *> *bars;
@property (nonatomic) UIView *containerView;
Expand Down Expand Up @@ -145,13 +133,12 @@ - (instancetype)initWithFrame:(CGRect)frame {
}

- (void)commonInit {
_visible = NO;
_primaryColor = [UIColor colorWithRed:18.0/255.0 green:45.0/255.0 blue:17.0/255.0 alpha:1];
_secondaryColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1];
_borderWidth = 1.0f;

self.clipsToBounds = NO;
self.alpha = 0;
self.hidden = YES;

_containerView = [[UIView alloc] init];
_containerView.clipsToBounds = YES;
Expand Down Expand Up @@ -219,47 +206,38 @@ - (MGLRow)preferredRow {
return row;
}

- (void)fadeIn {
if (self.isVisible) {
return;
}

self.visible = YES;

[UIView animateWithDuration:.2 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.alpha = 1.0;
} completion:nil];
}

- (void)fadeOut {
if (!self.isVisible) {
return;
}

self.visible = NO;

[UIView animateWithDuration:.3 delay:0.7 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.alpha = 0.0;
} completion:nil];
}

#pragma mark - Setters

- (void)setMetersPerPoint:(CLLocationDistance)metersPerPoint {
if (_metersPerPoint == metersPerPoint) {
return;
}

[self fadeIn];

_metersPerPoint = metersPerPoint;

[self updateVisibility];

self.row = [self preferredRow];

[self invalidateIntrinsicContentSize];
[self setNeedsLayout];
}

- (void)updateVisibility {
BOOL metric = [self usesMetricSystem];

NSUInteger count = metric
? sizeof(MGLMetricTable) / sizeof(MGLMetricTable[0])
: sizeof(MGLImperialTable) / sizeof(MGLImperialTable[0]);

CLLocationDistance maximumDistance = [self maximumWidth] * [self unitsPerPoint];
CLLocationDistance allowedDistance = metric
? MGLMetricTable[count-1].distance
: MGLImperialTable[count-1].distance;

self.alpha = maximumDistance > allowedDistance ? 0 : 1;
}

- (void)setRow:(MGLRow)row {
if (_row.distance == row.distance) {
return;
Expand Down

0 comments on commit c113e89

Please sign in to comment.