Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Content insets #3583

Merged
merged 8 commits into from
Jan 19, 2016
Merged

Content insets #3583

merged 8 commits into from
Jan 19, 2016

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Jan 15, 2016

This PR implements content insets on iOS and OS X. By default, the content insets automatically adjust to account for translucent chrome (on iOS, the top and bottom bars when there’s extended layout; on OS X, the translucent toolbar of a window that has the map view as a full-window content view). However, it can be configured for any purpose, such as excluding a Google-style floating search bar from the logical viewport.

I attempted to mimic UIScrollView and NSScrollView on iOS and OS X, respectively. Therefore, there are a few minor differences in the implementations between the two platforms. Whereas the map view itself has an automaticallyAdjustsContentInsets property on OS X, it’s the containing view controller that feeds the map view its insets on iOS.

The underlying implementation in mbgl is designed to be usable by Android as well, and eventually course tracking mode will shift the center downward so that the user dot appears towards the bottom of the view.

Following this work, the rule is that Map and Transform assume a view origin at the top-left corner of the view (consistent with iOS, Android, and GLFW), while TransformState assumes a view origin at the bottom-left corner of the view (more convenient for converting to geographic coordinates). (OS X natively assumes an origin at the bottom-left.)

/ref #2600, #3574
/cc @friedbunny

@1ec5 1ec5 added feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS Android Mapbox Maps SDK for Android GLFW ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Jan 15, 2016
@1ec5 1ec5 self-assigned this Jan 15, 2016
@1ec5 1ec5 added this to the ios-v3.2.0 milestone Jan 15, 2016
@zugaldia
Copy link
Member

/sub

@1ec5 1ec5 modified the milestones: ios-v3.1.0, ios-v3.2.0 Jan 16, 2016
@1ec5 1ec5 removed Android Mapbox Maps SDK for Android GLFW labels Jan 17, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Jan 17, 2016

To keep the diffs in this PR coherent, I split out #3589 to push the user puck downward in course tracking mode.

@1ec5 1ec5 mentioned this pull request Jan 17, 2016
@1ec5 1ec5 added ✓ ready for review and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold in progress labels Jan 18, 2016

void EdgeInsets::flip() {
std::swap(top, bottom);
std::swap(left, right);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved EdgeInsets to geo.hpp so CameraOptions and Transform can refer to it. Added a padding option to CameraOptions that alters the frame of reference for the center option. Added optional padding parameters to LatLng getters and setters.

Working towards #2600.
Added a contentInsets property to MGLMapView that behaves similarly to NSScrollView.contentInsets. Adjust it according to the window’s content layout rectangle using KVO. Automatically apply the content insets whenever creating a CameraOptions or getting the center coordinates.
Methods that offer a convenient way to jump or ease now accept an optional padding parameter. MGLMapView specifies the padding to ensure that keyboard-based zooming and rotation respects the toolbar.
…(), Map::pixelForLatLng()

Map and Transform methods assume an origin at the top-left corner of the view, like iOS, Android, and GLFW but unlike OS X. Transform is responsible for flipping coordinates between the top-left origin of Map and the bottom-left origin of TransformState.

Fixes #3574.
The zoom level is already clamped by Transform. -currentMinimumZoom appears to be useful only as an unrotation threshold; it doesn’t correspond to the minimum allowed zoom level.
This version of setLatLng() can be expressed by constraining the viewport to a 0×0 viewport around the passed-in point.
@1ec5 1ec5 merged commit 8dfba0e into master Jan 19, 2016
@1ec5 1ec5 removed the ready label Jan 19, 2016
@1ec5 1ec5 deleted the 1ec5-padding-2600 branch January 19, 2016 01:15
@@ -770,6 +773,49 @@ - (void)layoutSubviews
}
}

/// Updates `contentInset` to reflect the current window geometry.
- (void)adjustContentInset
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle the case where MGLMapView is nested more than 2 level deep in the UIViewController view hierarchy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t, for consistency with UIScrollView and UIViewController.automaticallyAdjustsScrollViewInsets. (This is already more robust than the UIScrollView behavior; a UIScrollView has to be the first subview.) Regardless, a developer can manually set the contentInset of a deeply nested MGLMapView.

@lgeromegnace
Copy link

Hi @1ec5,
First of all: great work! Insets work fine :).

I have a question: are you (or someone else) planning to implement this on the android side ?
If not we can take care of it. Just let me know if you have specific needs for this platform.

@1ec5
Copy link
Contributor Author

1ec5 commented Jan 21, 2016

Android support is tracked by #3627. I'd be happy to let someone more familiar with Android take this on. @tobrun, are there any special considerations for Android support?

@tobrun
Copy link
Member

tobrun commented Jan 21, 2016

@lgeromegnace feel free to take that up, it's on my list but currently not ranked in the top tier.

@lgeromegnace
Copy link

Ok @1ec5, @tobrun.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core] Map::latLngForPixel and Map::pixelForLatLng are using bottom/left coordinates
5 participants