diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2017-04-16 17:24:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-16 17:24:17 +0200 |
commit | 8eb23cbac8a6c5821dc5935e27689700216c3f1a (patch) | |
tree | d02fd3667c8e19daf3724384f4956f16ec0bf01c /platform/ios/src/MGLMapView.mm | |
parent | fcf5d1b8af5ca01f8634107f00fbc843c892dd48 (diff) | |
download | qtlocation-mapboxgl-8eb23cbac8a6c5821dc5935e27689700216c3f1a.tar.gz |
[ios] Scale bar (#7631)
* [ios] added a scale bar
* [ios] update design
* [ios] show/hide scale bar
* [ios] Remove the need to localize 0
* [ios] Support for imperial units
* [ios] Round to nearest foot
* [ios] Make scale bar private
* [ios] Update design and clean up
* [ios] Rename and various optimizations
* [ios] RTL support
* [ios] added max scale and removed animations
* [ios] animate scale bar
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 6badb1d857..fc4d39a143 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -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 @@ public: @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 @@ public: _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 @@ public: - (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]]; + + [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 @@ public: { [weakSelf unrotateIfNeededForGesture]; }]; + } else { + [self unrotateIfNeededForGesture]; } } } @@ -4827,7 +4864,11 @@ public: } [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]; |