diff options
author | Lloyd Sheng <i@lloydsheng.com> | 2019-03-11 17:32:05 +0800 |
---|---|---|
committer | Lloyd Sheng <i@lloydsheng.com> | 2019-03-11 17:49:14 +0800 |
commit | fda7d18a04afa6edda76e6515477fcc2de09d3bd (patch) | |
tree | e4100aa7f5713ed47e311a9bc06f685d015e95e4 | |
parent | 4bf024506e793992071ef7057992fef7734e55c0 (diff) | |
download | qtlocation-mapboxgl-fda7d18a04afa6edda76e6515477fcc2de09d3bd.tar.gz |
Use proper API name; Fix code style issues
-rw-r--r-- | platform/ios/CHANGELOG.md | 2 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.h | 8 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 94 | ||||
-rw-r--r-- | platform/ios/test/MGLMapViewLayoutTests.m | 50 |
4 files changed, 74 insertions, 80 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 4a89ed6c60..73d74407fd 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -10,7 +10,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### User interaction -* Added `MGLOrnamentPosition` enum and offset methods to customize MGLMapView's scale bar, compass, logo and attribution position. ([#13911](https://github.com/mapbox/mapbox-gl-native/pull/13911)) +* Added `MGLOrnamentPosition` enum and margins methods to customize MGLMapView's scale bar, compass, logo and attribution position. ([#13911](https://github.com/mapbox/mapbox-gl-native/pull/13911)) ## 4.9.0 - February 27, 2019 diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 3dfecbf683..1ef64a587b 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -312,7 +312,7 @@ MGL_EXPORT IB_DESIGNABLE /** A `CGPoint` indicating the position offset of the scale bar. */ -@property (nonatomic, assign) CGPoint scaleBarOffset; +@property (nonatomic, assign) CGPoint scaleBarMargins; /** A control indicating the map’s direction and allowing the user to manipulate @@ -328,7 +328,7 @@ MGL_EXPORT IB_DESIGNABLE /** A `CGPoint` indicating the position offset of the compass. */ -@property (nonatomic, assign) CGPoint compassViewOffset; +@property (nonatomic, assign) CGPoint compassViewMargins; /** The Mapbox logo, positioned in the lower-left corner. @@ -349,7 +349,7 @@ MGL_EXPORT IB_DESIGNABLE /** A `CGPoint` indicating the position offset of the logo. */ -@property (nonatomic, assign) CGPoint logoViewOffset; +@property (nonatomic, assign) CGPoint logoViewMargins; /** @@ -385,7 +385,7 @@ MGL_EXPORT IB_DESIGNABLE /** A `CGPoint` indicating the position offset of the attribution. */ -@property (nonatomic, assign) CGPoint attributionButtonOffset; +@property (nonatomic, assign) CGPoint attributionButtonMargins; /** Show the attribution and telemetry action sheet. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 4f5b148037..f19f1c8661 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -525,7 +525,7 @@ public: [self addSubview:_logoView]; _logoViewConstraints = [NSMutableArray array]; _logoViewPosition = MGLOrnamentPositionBottomLeft; - _logoViewOffset = MGLOrnamentDefaultPositionOffset; + _logoViewMargins = MGLOrnamentDefaultPositionOffset; // setup attribution // @@ -541,7 +541,7 @@ public: UILongPressGestureRecognizer *attributionLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showAttribution:)]; [_attributionButton addGestureRecognizer:attributionLongPress]; _attributionButtonPosition = MGLOrnamentPositionBottomRight; - _attributionButtonOffset = MGLOrnamentDefaultPositionOffset; + _attributionButtonMargins = MGLOrnamentDefaultPositionOffset; // setup compass // @@ -556,7 +556,7 @@ public: [self addSubview:_compassView]; _compassViewConstraints = [NSMutableArray array]; _compassViewPosition = MGLOrnamentPositionTopRight; - _compassViewOffset = MGLOrnamentDefaultPositionOffset; + _compassViewMargins = MGLOrnamentDefaultPositionOffset; // setup scale control // @@ -565,7 +565,7 @@ public: [self addSubview:_scaleBar]; _scaleBarConstraints = [NSMutableArray array]; _scaleBarPosition = MGLOrnamentPositionTopLeft; - _scaleBarOffset = MGLOrnamentDefaultPositionOffset; + _scaleBarMargins = MGLOrnamentDefaultPositionOffset; [self installConstraints]; @@ -830,10 +830,9 @@ public: [self installScaleBarConstraints]; } -- (void)setScaleBarOffset:(CGPoint)scaleBarOffset { - NSAssert(CGRectContainsPoint(self.bounds, scaleBarOffset), @"The position offset of the scale bar should within the mapview boundaries"); - MGLLogDebug(@"Setting scaleBarOffset: (x:%f, y:%f)", scaleBarOffset.x, scaleBarOffset.y); - _scaleBarOffset = scaleBarOffset; +- (void)setScaleBarMargins:(CGPoint)scaleBarMargins { + MGLLogDebug(@"Setting scaleBarMargins: (x:%f, y:%f)", scaleBarMargins.x, scaleBarMargins.y); + _scaleBarMargins = scaleBarMargins; [self installScaleBarConstraints]; } @@ -843,10 +842,9 @@ public: [self installCompassViewConstraints]; } -- (void)setCompassViewOffset:(CGPoint)compassViewOffset { - NSAssert(CGRectContainsPoint(self.bounds, compassViewOffset), @"The position offset of the compass should within the mapview boundaries"); - MGLLogDebug(@"Setting compassViewOffset: (x:%f, y:%f)", compassViewOffset.x, compassViewOffset.y); - _compassViewOffset = compassViewOffset; +- (void)setCompassViewMargins:(CGPoint)compassViewMargins { + MGLLogDebug(@"Setting compassViewOffset: (x:%f, y:%f)", compassViewMargins.x, compassViewMargins.y); + _compassViewMargins = compassViewMargins; [self installCompassViewConstraints]; } @@ -856,10 +854,9 @@ public: [self installLogoViewConstraints]; } -- (void)setLogoViewOffset:(CGPoint)logoViewOffset { - NSAssert(CGRectContainsPoint(self.bounds, logoViewOffset), @"The position offset of the logo should within the mapview boundaries."); - MGLLogDebug(@"Setting logoViewOffset: (x:%f, y:%f)", logoViewOffset.x, logoViewOffset.y); - _logoViewOffset = logoViewOffset; +- (void)setLogoViewMargins:(CGPoint)logoViewMargins { + MGLLogDebug(@"Setting logoViewMargins: (x:%f, y:%f)", logoViewMargins.x, logoViewMargins.y); + _logoViewMargins = logoViewMargins; [self installLogoViewConstraints]; } @@ -869,38 +866,35 @@ public: [self installAttributionButtonConstraints]; } -- (void)setAttributionButtonOffset:(CGPoint)attributionButtonOffset { - NSAssert(CGRectContainsPoint(self.bounds, attributionButtonOffset), @"The position offset of the attribution should within the mapview boundaries."); - MGLLogDebug(@"Setting attributionButtonOffset: (x:%f, y:%f)", attributionButtonOffset.x, attributionButtonOffset.y); - _attributionButtonOffset = attributionButtonOffset; +- (void)setAttributionButtonMargins:(CGPoint)attributionButtonMargins { + MGLLogDebug(@"Setting attributionButtonMargins: (x:%f, y:%f)", attributionButtonMargins.x, attributionButtonMargins.y); + _attributionButtonMargins = attributionButtonMargins; [self installAttributionButtonConstraints]; } - (void)updateConstraintsForOrnament:(UIView *)view - constraints:(NSMutableArray *)constraints - position:(MGLOrnamentPosition)position - size:(CGSize)size - offset:(CGPoint)offset { + constraints:(NSMutableArray *)constraints + position:(MGLOrnamentPosition)position + size:(CGSize)size + margins:(CGPoint)margins { NSMutableArray *updatedConstraints = [NSMutableArray array]; switch (position) { case MGLOrnamentPositionTopLeft: - [updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:offset.y]]; - [updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:offset.x]]; + [updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:margins.y]]; + [updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:margins.x]]; break; case MGLOrnamentPositionTopRight: - [updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:offset.y]]; - [updatedConstraints addObject:[self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:offset.x]]; + [updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:margins.y]]; + [updatedConstraints addObject:[self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x]]; break; case MGLOrnamentPositionBottomLeft: - [updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:offset.y]]; - [updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:offset.x]]; + [updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y]]; + [updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:margins.x]]; break; case MGLOrnamentPositionBottomRight: - [updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:offset.y]]; - [updatedConstraints addObject: [self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:offset.x]]; - break; - default: + [updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y]]; + [updatedConstraints addObject: [self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x]]; break; } @@ -924,37 +918,37 @@ public: - (void)installCompassViewConstraints { // compass view [self updateConstraintsForOrnament:self.compassView - constraints:self.compassViewConstraints - position:self.compassViewPosition - size:self.compassView.bounds.size - offset:self.compassViewOffset]; + constraints:self.compassViewConstraints + position:self.compassViewPosition + size:self.compassView.bounds.size + margins:self.compassViewMargins]; } - (void)installScaleBarConstraints { // scale bar view [self updateConstraintsForOrnament:self.scaleBar - constraints:self.scaleBarConstraints - position:self.scaleBarPosition - size:self.scaleBar.intrinsicContentSize - offset:self.scaleBarOffset]; + constraints:self.scaleBarConstraints + position:self.scaleBarPosition + size:self.scaleBar.intrinsicContentSize + margins:self.scaleBarMargins]; } - (void)installLogoViewConstraints { // logo view [self updateConstraintsForOrnament:self.logoView - constraints:self.logoViewConstraints - position:self.logoViewPosition - size:self.logoView.bounds.size - offset:self.logoViewOffset]; + constraints:self.logoViewConstraints + position:self.logoViewPosition + size:self.logoView.bounds.size + margins:self.logoViewMargins]; } - (void)installAttributionButtonConstraints { // attribution button [self updateConstraintsForOrnament:self.attributionButton - constraints:self.attributionButtonConstraints - position:self.attributionButtonPosition - size:self.attributionButton.bounds.size - offset:self.attributionButtonOffset]; + constraints:self.attributionButtonConstraints + position:self.attributionButtonPosition + size:self.attributionButton.bounds.size + margins:self.attributionButtonMargins]; } - (BOOL)isOpaque diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m index 88128a60a2..6f67ae48ad 100644 --- a/platform/ios/test/MGLMapViewLayoutTests.m +++ b/platform/ios/test/MGLMapViewLayoutTests.m @@ -129,21 +129,21 @@ } - (void)testOrnamentPlacementInvalidArgument { - XCTAssertThrows([self.mapView setCompassViewOffset:CGPointMake(-4, -4)]); - XCTAssertThrows([self.mapView setCompassViewOffset:CGPointMake(-4, 0)]); - XCTAssertThrows([self.mapView setCompassViewOffset:CGPointMake(0, -4)]); + XCTAssertThrows([self.mapView setCompassViewMargins:CGPointMake(-4, -4)]); + XCTAssertThrows([self.mapView setCompassViewMargins:CGPointMake(-4, 0)]); + XCTAssertThrows([self.mapView setCompassViewMargins:CGPointMake(0, -4)]); - XCTAssertThrows([self.mapView setScaleBarOffset:CGPointMake(-4, -4)]); - XCTAssertThrows([self.mapView setScaleBarOffset:CGPointMake(-4, 0)]); - XCTAssertThrows([self.mapView setScaleBarOffset:CGPointMake(0, -4)]); + XCTAssertThrows([self.mapView setScaleBarMargins:CGPointMake(-4, -4)]); + XCTAssertThrows([self.mapView setScaleBarMargins:CGPointMake(-4, 0)]); + XCTAssertThrows([self.mapView setScaleBarMargins:CGPointMake(0, -4)]); - XCTAssertThrows([self.mapView setAttributionButtonOffset:CGPointMake(-4, -4)]); - XCTAssertThrows([self.mapView setAttributionButtonOffset:CGPointMake(-4, 0)]); - XCTAssertThrows([self.mapView setAttributionButtonOffset:CGPointMake(0, -4)]); + XCTAssertThrows([self.mapView setAttributionButtonMargins:CGPointMake(-4, -4)]); + XCTAssertThrows([self.mapView setAttributionButtonMargins:CGPointMake(-4, 0)]); + XCTAssertThrows([self.mapView setAttributionButtonMargins:CGPointMake(0, -4)]); - XCTAssertThrows([self.mapView setLogoViewOffset:CGPointMake(-4, -4)]); - XCTAssertThrows([self.mapView setLogoViewOffset:CGPointMake(-4, 0)]); - XCTAssertThrows([self.mapView setLogoViewOffset:CGPointMake(0, -4)]); + XCTAssertThrows([self.mapView setLogoViewMargins:CGPointMake(-4, -4)]); + XCTAssertThrows([self.mapView setLogoViewMargins:CGPointMake(-4, 0)]); + XCTAssertThrows([self.mapView setLogoViewMargins:CGPointMake(0, -4)]); } - (NSArray *)makeTestDataListWithView:(UIView *)view margin:(CGFloat)margin { @@ -154,18 +154,18 @@ return @[ [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopLeft - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(margin, margin)], + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(margin, margin)], [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionTopRight - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), 4)], + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), 4)], [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomLeft - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(margin, CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))], + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(margin, CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))], [MGLOrnamentTestData createWithPosition:MGLOrnamentPositionBottomRight - offset:CGPointMake(margin, margin) - expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), - CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))] + offset:CGPointMake(margin, margin) + expectedOrigin:CGPointMake(CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(view.frame), + CGRectGetMaxY(self.mapView.bounds) - margin - bottomSafeAreaInset - CGRectGetHeight(view.frame))] ]; } @@ -178,7 +178,7 @@ for (MGLOrnamentTestData *testData in testDataList) { self.mapView.compassViewPosition = testData.position; - self.mapView.compassViewOffset = testData.offset; + self.mapView.compassViewMargins = testData.offset; //invoke layout [self.superView setNeedsLayout]; @@ -198,7 +198,7 @@ for (MGLOrnamentTestData *testData in testDataList) { self.mapView.scaleBarPosition = testData.position; - self.mapView.scaleBarOffset = testData.offset; + self.mapView.scaleBarMargins = testData.offset; //invoke layout [self.superView setNeedsLayout]; @@ -218,7 +218,7 @@ for (MGLOrnamentTestData *testData in testDataList) { self.mapView.attributionButtonPosition = testData.position; - self.mapView.attributionButtonOffset = testData.offset; + self.mapView.attributionButtonMargins = testData.offset; //invoke layout [self.superView setNeedsLayout]; @@ -238,7 +238,7 @@ for (MGLOrnamentTestData *testData in testDataList) { self.mapView.logoViewPosition = testData.position; - self.mapView.logoViewOffset = testData.offset; + self.mapView.logoViewMargins = testData.offset; //invoke layout [self.superView setNeedsLayout]; |