summaryrefslogtreecommitdiff
path: root/platform/ios/app/MBXViewController.m
diff options
context:
space:
mode:
authorAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-13 23:02:05 +0300
committerAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-28 14:38:01 +0300
commit9809c9f8f5583739e07d1a02df4c6cb96dfc4a10 (patch)
treef61c9979ad7943c1975aad6725054b2458c22b36 /platform/ios/app/MBXViewController.m
parentddb6f749ec8992c363c067b6ad5871b31ccb7b8a (diff)
downloadqtlocation-mapboxgl-9809c9f8f5583739e07d1a02df4c6cb96dfc4a10.tar.gz
[core] Offset viewport center when edge insets are specified
The change is implemented in TransformState::getProjMatrix, the rest of the code is making sure that existing API contracts stay and there are tests verifyingrendering and render query processing only items within screen and given tolerance around screen edges. MapView: don't bake edge insets into relalculated camera center. Keep edge insets as property of camera in TransformState (similar to pitch, zoom, bearing) independent from specified camera center. Interpolate edge insets in animation. iOS Demo app: "Turn On/Off Content Insets" pitch the camera and navigate to convenient location in Denver, where streets are parallel to cardinal directions, to illustrate viewport center offset when edge insets are set. Tests: ViewFrustumCulling: although Annotations are deprecated, queryRenderedFeatures related tests in Annotations would need to get ported and decided to add the edge insets related query tests next to them. Verify frustum culling (render+queryRenderedFeatures) With different camera and edge insets setups. TODO: port Annotations tests. Transform.Padding: Verify that coordinates take proper place on screen after applying edge insets. LocalGlyphRasterizer: verify text rendering when applying padding. Related to #11882: both use projection matrix elements [8] and [9]. Alternative approach to this was to increase and offset map origin so that the screen would be a sub-rectangle in larger map viewport. This approach has a drawback of unecessary processing the items that are outside screen area. Fixes #12107, #12728, navigation-sdks/issues/120
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r--platform/ios/app/MBXViewController.m77
1 files changed, 77 insertions, 0 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 3335606f98..567ca151f7 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -105,6 +105,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MBXSettingsMiscellaneousShowSnapshots,
MBXSettingsMiscellaneousMissingIcon,
MBXSettingsMiscellaneousShouldLimitCameraChanges,
+ MBXSettingsMiscellaneousSetContentInsets,
MBXSettingsMiscellaneousShowCustomLocationManager,
MBXSettingsMiscellaneousOrnamentsPlacement,
MBXSettingsMiscellaneousPrintLogFile,
@@ -209,6 +210,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@property (nonatomic) BOOL shouldLimitCameraChanges;
@property (nonatomic) BOOL randomWalk;
@property (nonatomic) NSMutableArray<UIWindow *> *helperWindows;
+@property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays;
@end
@@ -219,6 +221,8 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@implementation MBXViewController
{
BOOL _isTouringWorld;
+ BOOL _contentInsetsEnabled;
+ UIEdgeInsets _originalContentInsets;
}
#pragma mark - Setup & Teardown
@@ -475,6 +479,7 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@"Show Snapshots",
@"Missing Icon",
[NSString stringWithFormat:@"%@ Camera Changes", (_shouldLimitCameraChanges ? @"Unlimit" : @"Limit")],
+ [NSString stringWithFormat:@"Turn %@ Content Insets", (_contentInsetsEnabled ? @"Off" : @"On")],
@"View Route Simulation",
@"Ornaments Placement",
]];
@@ -739,6 +744,61 @@ CLLocationCoordinate2D randomWorldCoordinate() {
}
break;
}
+ case MBXSettingsMiscellaneousSetContentInsets:
+ {
+ if (!_contentInsetsEnabled) {
+ _originalContentInsets = [self.mapView contentInset];
+ }
+ _contentInsetsEnabled = !_contentInsetsEnabled;
+ self.automaticallyAdjustsScrollViewInsets = !_contentInsetsEnabled;
+ UIEdgeInsets contentInsets = self.mapView.bounds.size.width > self.mapView.bounds.size.height
+ ? UIEdgeInsetsMake(_originalContentInsets.top, 0.5 * self.mapView.bounds.size.width, _originalContentInsets.bottom, 0.0)
+ : UIEdgeInsetsMake(0.25 * self.mapView.bounds.size.height, 0.0, _originalContentInsets.bottom, 0.25 * self.mapView.bounds.size.width);
+ if (_contentInsetsEnabled) {
+ if (!self.contentInsetsOverlays)
+ self.contentInsetsOverlays = [NSMutableArray array];
+ if (![self.contentInsetsOverlays count]) {
+ UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.mapView.bounds.size.width, contentInsets.top)];
+ view.backgroundColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.3 alpha:0.5];
+ [self.contentInsetsOverlays addObject:view];
+ [self.view addSubview:view];
+ view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, contentInsets.left, self.mapView.bounds.size.height)];
+ view.backgroundColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.3 alpha:0.5];
+ [self.contentInsetsOverlays addObject:view];
+ [self.view addSubview:view];
+ view = [[UIView alloc]initWithFrame:CGRectMake(self.mapView.bounds.size.width - contentInsets.right, 0, contentInsets.right, self.mapView.bounds.size.height)];
+ view.backgroundColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.3 alpha:0.5];
+ [self.contentInsetsOverlays addObject:view];
+ [self.view addSubview:view];
+ view = [[UIView alloc]initWithFrame:CGRectMake(0, self.mapView.bounds.size.height - contentInsets.bottom, self.mapView.bounds.size.width, self.mapView.bounds.size.height)];
+ view.backgroundColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.3 alpha:0.5];
+ [self.contentInsetsOverlays addObject:view];
+ [self.view addSubview:view];
+ }
+ [self.view bringSubviewToFront:self.contentInsetsOverlays[0]];
+ [self.view bringSubviewToFront:self.contentInsetsOverlays[1]];
+ [self.view bringSubviewToFront:self.contentInsetsOverlays[2]];
+ [self.view bringSubviewToFront:self.contentInsetsOverlays[3]];
+
+ // Denver streets parallel to cardinal directions help illustrate
+ // viewport center offset when edge insets are set.
+ MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(39.72707, -104.9986)
+ acrossDistance:100
+ pitch:60
+ heading:0];
+ __weak typeof(self) weakSelf = self;
+ [self.mapView setCamera:camera withDuration:0.3 animationTimingFunction:nil completionHandler:^{
+ [weakSelf.mapView setContentInset:contentInsets animated:TRUE];
+ }];
+ } else {
+ [self.view sendSubviewToBack:self.contentInsetsOverlays[0]];
+ [self.view sendSubviewToBack:self.contentInsetsOverlays[1]];
+ [self.view sendSubviewToBack:self.contentInsetsOverlays[2]];
+ [self.view sendSubviewToBack:self.contentInsetsOverlays[3]];
+ [self.mapView setContentInset:_originalContentInsets animated:TRUE];
+ }
+ break;
+ }
case MBXSettingsMiscellaneousOrnamentsPlacement:
{
MBXOrnamentsViewController *ornamentsViewController = [[MBXOrnamentsViewController alloc] init];
@@ -2005,6 +2065,23 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[sender setAccessibilityValue:nextAccessibilityValue];
}
+#pragma mark - UIViewDelegate
+
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
+{
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+ if (_contentInsetsEnabled)
+ {
+ _contentInsetsEnabled = NO;
+ self.automaticallyAdjustsScrollViewInsets = YES;
+ [self.mapView setContentInset:UIEdgeInsetsZero];
+ }
+ while (self.contentInsetsOverlays && [self.contentInsetsOverlays count]) {
+ [[self.contentInsetsOverlays lastObject] removeFromSuperview];
+ [self.contentInsetsOverlays removeLastObject];
+ }
+}
+
#pragma mark - MGLMapViewDelegate
- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation