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

[iOS] Using contentInset for setCenterCoordinate: and flyToCamera met… - #4067

Closed
RomainQuidet wants to merge 3 commits into
mapbox:masterfrom
Mappy:3778_incorrect_insets
Closed

RomainQuidet wants to merge 3 commits into
mapbox:masterfrom
Mappy:3778_incorrect_insets

Conversation

@RomainQuidet

Copy link
Copy Markdown
Contributor

Using contentInset for setCenterCoordinate: and flyToCamera methods everywhere.

@1ec5

1ec5 commented Feb 22, 2016

Copy link
Copy Markdown
Contributor

If edgePaddingForFollowing doesn't include the content inset, it should.

@RomainQuidet

Copy link
Copy Markdown
Contributor Author

@1ec5 What do you mean it should? I thought the logic behind edgePaddingForFollowing was for a former usage, I simply replaced it by the contentInset as everywhere else in the mapView class. It's working according to my basic tests.
If I must use this method, what is the logic behind it? Thanks.

@1ec5

1ec5 commented Feb 23, 2016

Copy link
Copy Markdown
Contributor

-edgePaddingForFollowing should be used here, but its implementation is incorrect. The method is meant to account for the fact that the user dot may be somewhere other than the center of the map (even after accounting for content insets). For example, if you set userLocationVerticalAlignment to MGLAnnotationVerticalAlignmentTop or MGLAnnotationVerticalAlignmentBottom, this method should return quite a large top inset. However, this line is incorrect: we should start out with contentFrame, not bounds. bounds should only be used to calculate the final return value, since edge padding is always based on the view’s non-inset bounds.

@1ec5 1ec5 added bug iOS Mapbox Maps SDK for iOS labels Feb 23, 2016
@1ec5 1ec5 added this to the ios-v3.2.0 milestone Feb 23, 2016
@RomainQuidet

Copy link
Copy Markdown
Contributor Author

I agree that - (UIEdgeInsets)edgePaddingForFollowing implementation is wrong and a little bit strange for me.
I'll try to adapt it to return the correct insets.
Everywhere else the method _setCenterCoordinate is used, it simply pass the self.contentInset to the edgePadding parameter. (see

[self _setCenterCoordinate:centerCoordinate edgePadding:self.contentInset zoomLevel:zoomLevel direction:direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil completionHandler:completion];
)

…mera methods everywhere."

This reverts commit ccbdeaa.
@RomainQuidet

Copy link
Copy Markdown
Contributor Author

correct edgePaddingForFollowing, using contentInset and vertical alignment.

@boundsj boundsj modified the milestones: ios-v3.4.0, ios-v3.3.0 Jun 29, 2016
@boundsj boundsj self-assigned this Aug 15, 2016
@boundsj

boundsj commented Aug 30, 2016

Copy link
Copy Markdown
Contributor

Everywhere else the method _setCenterCoordinate is used, it simply pass the self.contentInset to the edgePadding parameter.

I agree. It seems to me like the fix should actually be ccbdeaa, the original commit in this PR.

This rect created in userLocationAnnotationViewCenter is based off of contentFrame and already accounts for user location vertical alignment which is the concern @1ec5 brought up above. The paths [MGLMapView glkView:drawInRect:] -> [MGLMapView updateUserLocationAnnotationView] -> [MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:] and also [MGLMapView locationManager:didUpdateLocations:] -> [MGLMapView locationManager:didUpdateLocations:animated:] -> [MGLMapView updateUserLocationAnnotationViewAnimatedWithDuration:] all end up using userLocationAnnotationViewCenter to get the userPoint used to position the user dot view via its center property.

Therefore, I think that [MGLMapView _setCenterCoordinate:edgePadding:zoomLevel:direction:duration:animationTimingFunction:completionHandler:] should expect the edgePadding to be the contentInset for the case of updating for contentInset changes like it does for all other cases.

Note: I'm using an orange, semi-transparent UIView to visualize the contentFrame that is created here. I update the contentInset on a timer every 5 seconds. With only ccbdeaa applied, adjusting the map's contentInset works like I would expect for the following cases:

MGLAnnotationVerticalAlignmentCenter, contentInset oscillated between left=200 and left=0 on a loop:

contentinsetfix

MGLAnnotationVerticalAlignmentBottom, contentInset oscillated between left=200 and left=0 on a loop:

contentinsetfixbottom

MGLAnnotationVerticalAlignmentTop, contentInset oscillated between left=200 and left=0 on a loop:

contentinsetfixtop

If I use the implementation of edgePaddingForFollowing we have in the current release version or update the implementation of edgePaddingForFollowing as suggested in #4067 (comment) the result is incorrect because the implementation of edgePaddingForFollowing results in UIEdgeInsetsZero. This causes the map to not move based on the contentInset input by the developer even though the user dot does move. This matches the original issue report:

Then set the user tracking to follow. The map then "moves back" to its original position and only the user location is inset.

contetinsetincorrect

In any case, there is no reason that I can see to use edgePaddingForFollowing since the user dot is moved as noted above and the map just needs the raw contentInset value. The final commit in this PR causes incorrect behavior when something other than MGLAnnotationVerticalAlignmentCenter is used.

I propose that we reduce this PR to just ccbdeaa (the first commit) and merge it.

@1ec5

1ec5 commented Aug 30, 2016

Copy link
Copy Markdown
Contributor

OK, I’m convinced. 😄 Thanks for the visual verification.

@boundsj

boundsj commented Aug 30, 2016

Copy link
Copy Markdown
Contributor

Subsumed by #6216

@1ec5

1ec5 commented Sep 6, 2016

Copy link
Copy Markdown
Contributor

This caused a regression that reproduces when the user dot is top- or bottom-aligned: #6257.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants