From 0ce0a83d607913e76bdafa00c528529f0308eab2 Mon Sep 17 00:00:00 2001 From: Lloyd Sheng Date: Thu, 11 Apr 2019 17:52:34 +0800 Subject: Add position assert for scalebar, logo and compass --- platform/ios/src/MGLMapView.mm | 12 ++++++ platform/ios/test/MGLMapViewLayoutTests.m | 70 +++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index edc127dd88..385dc86392 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -967,6 +967,18 @@ public: [NSException raise:NSInvalidArgumentException format:@"The attribution is not in the visible area of the mapview. Please check your position and offset settings"]; } + if (!CGRectContainsRect(self.bounds, self.scaleBar.frame)) { + [NSException raise:NSInvalidArgumentException + format:@"The scaleBar is not in the visible area of the mapview. Please check your position and offset settings"]; + } + if (!CGRectContainsRect(self.bounds, self.compassView.frame)) { + [NSException raise:NSInvalidArgumentException + format:@"The compassView is not in the visible area of the mapview. Please check your position and offset settings"]; + } + if (!CGRectContainsRect(self.bounds, self.logoView.frame)) { + [NSException raise:NSInvalidArgumentException + format:@"The logoView is not in the visible area of the mapview. Please check your position and offset settings"]; + } } /// Updates `contentInset` to reflect the current window geometry. diff --git a/platform/ios/test/MGLMapViewLayoutTests.m b/platform/ios/test/MGLMapViewLayoutTests.m index f3eeb75c0d..8d443e0260 100644 --- a/platform/ios/test/MGLMapViewLayoutTests.m +++ b/platform/ios/test/MGLMapViewLayoutTests.m @@ -171,6 +171,27 @@ } } +- (void)testCompassPlacementInvalidPosition { + CGFloat margin = -_superView.bounds.size.width; + + UIView *scaleBar = self.mapView.scaleBar; + NSArray *testDataList = [self makeTestDataListWithView:scaleBar margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.compassViewPosition = testData.position; + self.mapView.compassViewMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + XCTAssertThrowsSpecificNamed( + [self.superView layoutIfNeeded], + NSException, + NSInvalidArgumentException, + @"should throw NSInvalidArgumentException" + ); + } +} + - (void)testScalebarPlacement { double accuracy = 0.01; CGFloat margin = 4.0; @@ -191,6 +212,27 @@ } } +- (void)testScalebarPlacementInvalidPosition { + CGFloat margin = -_superView.bounds.size.width; + + UIView *scaleBar = self.mapView.scaleBar; + NSArray *testDataList = [self makeTestDataListWithView:scaleBar margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.scaleBarPosition = testData.position; + self.mapView.scaleBarMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + XCTAssertThrowsSpecificNamed( + [self.superView layoutIfNeeded], + NSException, + NSInvalidArgumentException, + @"should throw NSInvalidArgumentException" + ); + } +} + - (void)testAttributionButtonPlacement { double accuracy = 0.01; CGFloat margin = 4.0; @@ -212,15 +254,15 @@ } - (void)testAttributionButtonPlacementInvalidPosition { - CGFloat margin = -400.0; - + CGFloat margin = -_superView.bounds.size.width; + UIView *attributionButton = self.mapView.attributionButton; NSArray *testDataList = [self makeTestDataListWithView:attributionButton margin:margin]; for (MGLOrnamentTestData *testData in testDataList) { self.mapView.attributionButtonPosition = testData.position; self.mapView.attributionButtonMargins = testData.offset; - + //invoke layout [self.superView setNeedsLayout]; XCTAssertThrowsSpecificNamed( @@ -252,4 +294,26 @@ } } +- (void)testLogoPlacementInvalidPosition { + CGFloat margin = -_superView.bounds.size.width; + + UIView *attributionButton = self.mapView.attributionButton; + NSArray *testDataList = [self makeTestDataListWithView:attributionButton margin:margin]; + + for (MGLOrnamentTestData *testData in testDataList) { + self.mapView.logoViewPosition = testData.position; + self.mapView.logoViewMargins = testData.offset; + + //invoke layout + [self.superView setNeedsLayout]; + XCTAssertThrowsSpecificNamed( + [self.superView layoutIfNeeded], + NSException, + NSInvalidArgumentException, + @"should throw NSInvalidArgumentException" + ); + } +} + + @end -- cgit v1.2.1