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

Content insets should be added when setting camera with custom edge padding #12818

Closed
1ec5 opened this issue Sep 5, 2018 · 8 comments · Fixed by #14813
Closed

Content insets should be added when setting camera with custom edge padding #12818

1ec5 opened this issue Sep 5, 2018 · 8 comments · Fixed by #14813
Assignees
Labels
bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general

Comments

@1ec5
Copy link
Contributor

1ec5 commented Sep 5, 2018

The -[MGLMapView setCamera:withDuration:animationTimingFunction:edgePadding:completionHandler:] method added in #9651 uses the edgePadding parameter verbatim. By contrast, -setVisibleCoordinates:count:edgePadding:direction:duration:animationTimingFunction:completionHandler:, -cameraThatFitsCoordinateBounds:edgePadding:, and other camera-related methods all add the MGLMapView.contentInset property to the passed-in edge padding:

padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);

This inconsistency forces callers of -setCamera:withDuration:animationTimingFunction:edgePadding:completionHandler: to manually add the content insets.

/cc @frederoni @JThramer

@1ec5 1ec5 added bug iOS Mapbox Maps SDK for iOS navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general labels Sep 5, 2018
@stale stale bot added the archived Archived because of inactivity label Mar 4, 2019
@stale
Copy link

stale bot commented Mar 4, 2019

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Mar 4, 2019
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 6, 2019

This is definitely still a bug. Nice try, stalebot.

@1ec5 1ec5 reopened this Mar 6, 2019
@stale stale bot removed the archived Archived because of inactivity label Mar 6, 2019
@friedbunny friedbunny added this to the release-l milestone Mar 11, 2019
@friedbunny friedbunny removed this from the release-liquid milestone Apr 29, 2019
@astojilj
Copy link
Contributor

There is discrepancy in code and documentation between the methods, when it comes to interpretation of edgePadding/insets. Documentation "could" be interpreted as inline with the implementation - setVisiblecoordinates and "fitting" methods documentation uses wording "additional padding" while setcamera doesn't:

    • (void)setCamera... edgePadding:(UIEdgeInsets)edgePadding

@param edgePadding The minimum padding (in screen points) that would be visible around the returned camera object if it were set as the receiver’s camera.

    • (void)setVisibleCoordinates ... edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;

Changes the receiver’s viewport to fit all of the given coordinates and optionally some additional padding on each side.

However, documentation doesn't specify additional to contentInset* value. Additional to contentInset`value, when automatically adjusted by deprecated automaticallyAdjustsScrollViewInsets (btw, we should port to usage of contentInsetAdjustmentBehavior since deprecating automaticallyAdjustsScrollViewInsets), is also overwritten by automatic adjustment.

I would suggest changing the implementation so that:
a) when automaticallyAdjustsScrollViewInsets is YES (default), all methods, including setContentInsets and setCamera, define additional content inset to the one read from viewController layout guides (deprecation topLayoutGuide in favour of topLayoutGuide.bottomAnchor there).
b) when automaticallyAdjustsScrollViewInsets is NO, all methods, so fitting, setCamera and setContentInsets, there is no automatic content inset (or it is (0, 0, 0, 0)) and all APIs define the same content inset value. Additional word can stay in documentation as it is adding to zero content inset.

@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label May 30, 2019
@1ec5
Copy link
Contributor Author

1ec5 commented May 30, 2019

Documentation "could" be interpreted as inline with the implementation - setVisiblecoordinates and "fitting" methods documentation uses wording "additional padding" while setcamera doesn't

To me, the -setCamera:… documentation remains mum about the edgePadding behavior when there is a content inset; it doesn’t say one way or another whether the content inset is added to the edge padding.

I would suggest changing the implementation so that:
a) when automaticallyAdjustsScrollViewInsets is YES (default), all methods, including setContentInsets and setCamera, define additional content inset to the one read from viewController layout guides (deprecation topLayoutGuide in favour of topLayoutGuide.bottomAnchor there).
b) when automaticallyAdjustsScrollViewInsets is NO, all methods, so fitting, setCamera and setContentInsets, there is no automatic content inset (or it is (0, 0, 0, 0)) and all APIs define the same content inset value. Additional word can stay in documentation as it is adding to zero content inset.

Agreed. -[MGLMapView setCamera:withDuration:animationTimingFunction:edgePadding:completionHandler:] should add contentInsets to edgePadding, and -[MGLMapView setCamera:withDuration:animationTimingFunction:completionHandler:] should pass in an edge padding of NSEdgeInsetsZero/UIEdgeInsetsZero, not contentInsets.

The current behavior is clearly a bug, but it has been present for a while, and some clients such as the iOS navigation SDK have been working around it. So can we make the change in place, or do we have to create new methods, deprecating the old ones, to get around semver requirements?

@fabian-guerra
Copy link
Contributor

fabian-guerra commented May 30, 2019

The current behavior is clearly a bug, but it has been present for a while, and some clients such as the iOS navigation SDK have been working around it. So can we make the change in place, or do we have to create new methods, deprecating the old ones, to get around semver requirements?

Technically this is a bug. What happens if we treat it as such? and specify the proper functionality in the docs? We shouldn't have to wait for a semver to fix this problem nor complicate the api further. From a bug perspective (and even tho it has been this way for a while, and devs work around this issue) I'm in favor to release it as part of a "minor" version.

cc @mapbox/maps-ios

@1ec5
Copy link
Contributor Author

1ec5 commented May 31, 2019

If we fix this bug, we need to fix it in time for v5.1.0 (release-oolong). That release will also include a significant change to vanishing point behavior (#14664), essentially a fix for an even older bug. The navigation SDK is currently working around both bugs. (mapbox/mapbox-navigation-ios#2134 tracks removing the vanishing point workaround.)

The navigation SDK is pinning to v5.x of the map SDK. If the map SDK team commits to fixing this bug in v5.1.0, then I’ll modify today’s release of the navigation SDK to pin to v5.0.x, and we can relax the dependency the next time around once v5.1.0 is out. Otherwise, developers on a current version of the navigation SDK will wind up with a broken application when they routinely run pod install or carthage bootstrap. This is the pitfall that semver is supposed to protect clients of the map SDK from, but if we’re going to bend the rules, then we’ll need to at least protect the navigation SDK.

@astojilj
Copy link
Contributor

astojilj commented Aug 14, 2019

Is this still an issue? If so, let's reopen to get it fixed.

From the #15232 and #15233 it is not clear to me if this is still an issue.

@astojilj
Copy link
Contributor

Is this still an issue? If so, let's reopen to get it fixed.

From the #15232 and #15233 it is not clear to me if this is still an issue.

Please ignore - it seems fine #15232 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general
Projects
None yet
5 participants