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

Added cameraThatFitsShape: direction: pitch: edgePadding: method #13007

Closed
wants to merge 3 commits into from

Conversation

d-prukop
Copy link
Contributor

@d-prukop d-prukop commented Oct 2, 2018

Fixes #13005

The current implementation uses the current pitch of the map to calculate the altitude. This addition allows for getting the proper altitude of the camera for an upcoming pitch change which allows for a smooth animation to the new pitch and altitude.

/cc @1ec5 @fabian-guerra @friedbunny @julianrex

Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

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

I made a minor comment. Just make sure everything works correctly in:
cameraThatFitsShape:direction:edgePadding:

@@ -3457,10 +3457,14 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape e
}

- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets {
return [self cameraThatFitsShape:shape direction:direction pitch:0 edgePadding:insets];
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be wrong but if you pass 0 in this method it will ignore the current transformation state and calculate a 0 based pitch. Could you please test and confirm that this is not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be true. I'll fix that

padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets);

mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction);
return [self cameraThatFitsShape:shape direction:direction pitch:0 edgePadding:insets];
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above:

I may be wrong but if you pass 0 in this method it will ignore the current transformation state and calculate a 0 based pitch. Could you please test and confirm that this is not the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

@d-prukop
Copy link
Contributor Author

d-prukop commented Oct 3, 2018

@fabian-guerra Thanks for catching those issues. I've updated the files.

Copy link
Contributor

@julianrex julianrex left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Before this PR can be merged, I think there would need to be a test or at least screenshots demonstrating that the returned camera actually fits the given shape snugly. I don’t see how this method accomplishes that task given that #2259 is still outstanding.

@d-prukop
Copy link
Contributor Author

d-prukop commented Oct 3, 2018

@1ec5 This will behave the same way as the current cameraThatFitsShape: direction: edgePadding: method but with the ability to send a predefined pitch to include in the calculations. The most important components in the MGLMapCamera that is returned from this are the center coordinate and the altitude. These are the unknown values and are what determines how the shape fits into the map view. If the intention is to animate to these new settings, calculating the unknown center and altitude with respect to the known final pitch and final heading is important.
The shape will not fit snugly until #2259 lands but this method will automatically benefit from that improvement when it does.

@d-prukop
Copy link
Contributor Author

d-prukop commented Oct 3, 2018

So... there's already a method called camera: fittingShape: edgePadding: that allows for passing in the heading and pitch through an MGLMapCamera object. Is it worth keeping this new method?

@1ec5
Copy link
Contributor

1ec5 commented Oct 3, 2018

Aha! I thought I remembered @bsudekum implemented that but couldn’t find #12213 for some reason. Thanks for digging it up. If I recall correctly, we gave it that awkward name in part because it doesn’t necessarily fit all the parameters that are passed in – it just tries to fit as many as possible. We felt that #2259 wouldn’t be a blocker because it makes no guarantees about actually fitting anything precisely.

It sounds like this PR is unnecessary given #12213.

@kkaefer kkaefer added the iOS Mapbox Maps SDK for iOS label Oct 8, 2018
@d-prukop d-prukop closed this Nov 5, 2018
@d-prukop
Copy link
Contributor Author

d-prukop commented Nov 5, 2018

Closed in favor of using the existing camera: fittingShape: edgePadding: method

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

Successfully merging this pull request may close these issues.

5 participants