-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ios] Fix camera paddings reset on map view gestures performing. #188
[ios] Fix camera paddings reset on map view gestures performing. #188
Conversation
Here one can find the project with the fix demonstration. It's in the separate AsymmetricalPaddingsDemo.mov
|
@@ -2591,8 +2586,7 @@ - (MGLMapCamera *)cameraByZoomingToZoomLevel:(double)zoom aroundAnchorPoint:(CGP | |||
|
|||
- (MGLMapCamera *)cameraByRotatingToDirection:(CLLocationDirection)degrees aroundAnchorPoint:(CGPoint)anchorPoint | |||
{ | |||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); | |||
mbgl::CameraOptions currentCameraOptions = self.mbglMap.getCameraOptions(padding); | |||
mbgl::CameraOptions currentCameraOptions = self.mbglMap.getCameraOptions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in similar places below the padding value passed in mbglMap.getCameraOptions()
just replaces the camera edge insets. Although CameraOptions
is a pure model class which doesn't have any computations and side effects, it doesn't make much sense to replace its padding value.
self.mapView.contentInset = contentInset; | ||
mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(self.mapView.contentInset); | ||
auto cameraPadding = self.mapView.mbglMap.getCameraOptions().padding; | ||
XCTAssertEqual(padding, cameraPadding, @"MGLMapView's contentInset property should match camera's padding."); | ||
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset)); | ||
|
||
contentInset = UIEdgeInsetsMake(20, 20, 20, 20); | ||
[self.mapView setCamera:self.mapView.camera withDuration:0.1 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; | ||
[self.mapView setCamera:self.mapView.camera withDuration:0.0 animationTimingFunction:nil edgePadding:contentInset completionHandler:nil]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change must be immediate to take an effect while the test is running.
This looks really good @OlexandrStepanov Thank you for the great work! |
This PR fixes the issue with inconsistent padding reset of the map view camera after performing any gesture on the map other than pan.
The logic to reset camera paddings with pinch/rotation gesture was introduced in this commit altogether with gesture unit tests. Although I'm not sure what was the original intent, it seems wrong nowadays taking into account the current logic of edge insets handling in
MGLMapView.set...
methods.Just to be clear, what I mean by "current logic":
contentInset
property ofMGLMapView
controls the global padding of the map view. This value persists between camera changes of the map and controls the map elements positioning, like compass, scale bar, logo view etc.edgePadding
value passed in the methods likesetCamera:
,setVisibleCoordinatesBounds:
,showAnnotations:
etc. is the transient value for this particular camera update.contentInset
and passededgePadding
. This value is passed to the internal_mbglMap
as a part ofCameraOptions
.contentInset
value.There is another PR which is reported to be fixing the same issue, but there are some new problems introduced there.
edgePadding
are interchangeable, so having both of them introduces some ambiguity.More discussions on the topic: