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

Method for getting map camera settings from polyline, bearing, bounds and insets #9809

Closed
d-prukop opened this issue Aug 18, 2017 · 7 comments
Assignees
Labels
Core The cross-platform C++ core, aka mbgl feature navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general

Comments

@d-prukop
Copy link
Contributor

This method should accept a polyline, a bearing, a bounding rectangle in pixels and an object defining padding in pixels on all sides. It should then return a center coordinate and a zoom level appropriate for showing the given polyline in the given bounds at the given bearing.

This is basically what's already happening in fitBounds. The only difference is that this returns the calculated values so that the developer can handle the fitting of the bounds using any transition they want.

getCamera(polyline: Array<LngLat>, bounds:Array<Point>, insets: Array<Float>, bearing: Float) {
  return {zoomLevel: Float, centerCoord: LngLat, bearing: Float}
}

cc @mapbox/gl @pveugen

@d-prukop d-prukop added Core The cross-platform C++ core, aka mbgl feature navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general labels Aug 18, 2017
@1ec5
Copy link
Contributor

1ec5 commented Aug 21, 2017

This sounds a lot like the existing -[MGLMapView cameraFittingCoordinateBounds:edgePadding:] method, except that it takes a polyline instead of a coordinate bounds and allows the rotation to be specified. There's an mbgl::Map::cameraForLatLngs() method that does something similar. It could be exposed as -cameraFittingShape:edgePadding: or -cameraForShowingAnnotation:, playing off existing method names.

Would it be desirable to automatically choose an optimal rotation (within some threshold, to avoid overrotation)? I recall that Bing's API even goes so far as to choose an optimal pitch when the map is tilted.

@d-prukop
Copy link
Contributor Author

except that it takes a polyline instead of a coordinate bounds

This, I believe, is the tricky part. The viewport of the device in heading-up navigation is at an arbitrary bearing. You can't simply take the northeast and southwest coordinates and make a bounding box that will work. There needs to be some translation going on in order to calculate the proper zoom level.

@d-prukop
Copy link
Contributor Author

Would it be desirable to automatically choose an optimal rotation (within some threshold, to avoid overrotation)? I recall that Bing's API even goes so far as to choose an optimal pitch when the map is tilted.

Could you explain the overrotation problem. As for the pitch, It would be really great to have that.

@1ec5
Copy link
Contributor

1ec5 commented Aug 22, 2017

The viewport of the device in heading-up navigation is at an arbitrary bearing. You can't simply take the northeast and southwest coordinates and make a bounding box that will work. There needs to be some translation going on in order to calculate the proper zoom level.

mbgl::Map::cameraForLatLngs() correctly fits the polygon given the map’s current camera heading.

@1ec5
Copy link
Contributor

1ec5 commented Aug 22, 2017

Could you explain the overrotation problem.

I just meant that we may want to avoid rotating nearly 180° from the current camera just for something slightly more optimal than the current camera.

@d-prukop
Copy link
Contributor Author

d-prukop commented Aug 22, 2017

mbgl::Map::cameraForLatLngs() correctly fits the polygon given the map’s current camera heading.

This is great news.

@zugaldia
Copy link
Member

cc: @cammace @danesfeder for visibility on the Android side.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl feature navigation For the Mapbox Navigation SDK for Android or iOS or navigation use cases in general
Projects
None yet
Development

No branches or pull requests

4 participants