This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Scale bar #7631
Merged
Merged
[ios] Scale bar #7631
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1027a46
[ios] added a scale bar
frederoni 9f28d3e
[ios] update design
frederoni 7bcc763
[ios] show/hide scale bar
frederoni 33af33b
[ios] Remove the need to localize 0
frederoni f486864
[ios] Support for imperial units
frederoni f3b3875
[ios] Round to nearest foot
frederoni 53fa92b
[ios] Make scale bar private
frederoni 225352f
[ios] Update design and clean up
frederoni 930f1ec
[ios] Rename and various optimizations
frederoni 50af838
[ios] RTL support
frederoni 724cda5
[ios] added max scale and removed animations
frederoni c6fa267
[ios] animate scale bar
frederoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
#import "MGLUserLocation_Private.h" | ||
#import "MGLAnnotationImage_Private.h" | ||
#import "MGLAnnotationView_Private.h" | ||
#import "MGLScaleBar.h" | ||
#import "MGLStyle_Private.h" | ||
#import "MGLStyleLayer_Private.h" | ||
#import "MGLMapboxEvents.h" | ||
|
@@ -229,6 +230,8 @@ @interface MGLMapView () <UIGestureRecognizerDelegate, | |
@property (nonatomic) EAGLContext *context; | ||
@property (nonatomic) GLKView *glView; | ||
@property (nonatomic) UIImageView *glSnapshotView; | ||
@property (nonatomic, readwrite) MGLScaleBar *scaleBar; | ||
@property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *scaleBarConstraints; | ||
@property (nonatomic, readwrite) UIImageView *compassView; | ||
@property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *compassViewConstraints; | ||
@property (nonatomic, readwrite) UIImageView *logoView; | ||
|
@@ -493,7 +496,14 @@ - (void)commonInit | |
_compassView.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self addSubview:_compassView]; | ||
_compassViewConstraints = [NSMutableArray array]; | ||
|
||
|
||
// setup scale control | ||
// | ||
_scaleBar = [[MGLScaleBar alloc] init]; | ||
_scaleBar.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self addSubview:_scaleBar]; | ||
_scaleBarConstraints = [NSMutableArray array]; | ||
|
||
// setup interaction | ||
// | ||
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; | ||
|
@@ -774,6 +784,31 @@ - (UIViewController *)viewControllerForLayoutGuides | |
|
||
- (void)updateConstraints | ||
{ | ||
// scale control | ||
// | ||
[self removeConstraints:self.scaleBarConstraints]; | ||
[self.scaleBarConstraints removeAllObjects]; | ||
|
||
[self.scaleBarConstraints addObject: | ||
[NSLayoutConstraint constraintWithItem:self.scaleBar | ||
attribute:NSLayoutAttributeTop | ||
relatedBy:NSLayoutRelationEqual | ||
toItem:self | ||
attribute:NSLayoutAttributeTop | ||
multiplier:1 | ||
constant:5+self.contentInset.top]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we stick to a more standard constant like 4 points? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been using 5 on the compassView for quite a while. Let's revisit when we replace these constraints in #7716 |
||
|
||
[self.scaleBarConstraints addObject: | ||
[NSLayoutConstraint constraintWithItem:self.scaleBar | ||
attribute:NSLayoutAttributeLeading | ||
relatedBy:NSLayoutRelationEqual | ||
toItem:self | ||
attribute:NSLayoutAttributeLeading | ||
multiplier:1 | ||
constant:8 + self.contentInset.left]]; | ||
|
||
[self addConstraints:self.scaleBarConstraints]; | ||
|
||
// compass | ||
// | ||
[self removeConstraints:self.compassViewConstraints]; | ||
|
@@ -1564,6 +1599,8 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap | |
{ | ||
[weakSelf unrotateIfNeededForGesture]; | ||
}]; | ||
} else { | ||
[self unrotateIfNeededForGesture]; | ||
} | ||
} | ||
} | ||
|
@@ -4833,7 +4870,11 @@ - (void)cameraIsChanging { | |
} | ||
|
||
[self updateCompass]; | ||
|
||
|
||
if (!self.scaleBar.hidden) { | ||
[(MGLScaleBar *)self.scaleBar setMetersPerPoint:[self metersPerPointAtLatitude:self.centerCoordinate.latitude]]; | ||
} | ||
|
||
if ([self.delegate respondsToSelector:@selector(mapViewRegionIsChanging:)]) | ||
{ | ||
[self.delegate mapViewRegionIsChanging:self]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#import <UIKit/UIKit.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
|
||
@interface MGLScaleBar : UIView | ||
|
||
// Sets the scale and redraws the scale bar | ||
@property (nonatomic, assign) CLLocationDistance metersPerPoint; | ||
|
||
@end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should explicitly constrain the scale bar and compass to each other and the scale bar and logo to each other, the way we currently constrain the logo and attribution button to each other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any constraints between the logo and the attribution button.
The maximum width of the scale bar is
screenWidth/2-padding
which might be a bit too wide, especially on iPads but I don't think the answer is to constrain it to the compass. It makes positioning the components withcontentInsets
more prone to misplacement.