summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLloyd Sheng <i@lloydsheng.com>2019-04-11 17:52:34 +0800
committerLloyd Sheng <i@lloydsheng.com>2019-09-20 10:18:23 +0800
commit0ce0a83d607913e76bdafa00c528529f0308eab2 (patch)
treee771f488f085ea1823305c074bdca7dda8c64f61
parent283894f3739eecbe2e502626c13b1a3aa1371592 (diff)
downloadqtlocation-mapboxgl-0ce0a83d607913e76bdafa00c528529f0308eab2.tar.gz
Add position assert for scalebar, logo and compass
-rw-r--r--platform/ios/src/MGLMapView.mm12
-rw-r--r--platform/ios/test/MGLMapViewLayoutTests.m70
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