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

Method to convert arbitrary CameraOptions to LatLngBounds #8499

Closed
1ec5 opened this issue Mar 22, 2017 · 6 comments
Closed

Method to convert arbitrary CameraOptions to LatLngBounds #8499

1ec5 opened this issue Mar 22, 2017 · 6 comments
Labels
archived Archived because of inactivity feature gl-ios good first issue Good for newcomers iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS

Comments

@1ec5
Copy link
Contributor

1ec5 commented Mar 22, 2017

mbgl::Map should expose a latLngBoundsForCamera() method that takes an mbgl::CameraOptions and returns the mbgl::LatLngBounds that would be visible if the camera options were applied to the map. This method wouldn’t jump to a new location; it would only calculate what the extents would be.

The iOS and macOS SDKs have an -[MGLMapViewDelegate mapView:shouldChangeFromCamera:toCamera:] method that makes it easy to constrain the map’s center to a particular area, but it isn’t easy to constrain the map so that no disallowed area is ever visible. mapbox/ios-sdk-examples#65 illustrates the problem: we’d have to perform a set-and-revert dance just to determine whether the viewable area lies beyond the designated area. With latLngBoundsForCamera() and the corresponding SDK method, the delegate would be able to essentially do a “dry run” of the camera change associated with each gesture and use the resulting bounds to make this determination.

latLngBoundsForCamera() would essentially be the reverse operation of cameraForLatLngBounds(), so it may be desirable to ensure round-trippability. On the other hand, given #2259, I’m not sure we can ensure that at the moment.

/cc @jfirebaugh @brunoabinader @fabian-guerra @tobrun

@1ec5 1ec5 added Core The cross-platform C++ core, aka mbgl feature labels Mar 22, 2017
@jfirebaugh
Copy link
Contributor

LatLngBounds represents an axis-aligned rectangle, which can't accurately represent the visible map region in the cases where the camera has a non-zero bearing or pitch (as mentioned in #2259). Is that an acceptable limitation in the cases where cameraOptionsForLatLngBounds is intended for use? If so, what particular behavior should the method have in those cases (e.g. should the axis aligned bound inscribe the visible region, or circumscribe it)? If not, how can we more accurately represent the visible region?

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 22, 2017

(Side note: I made a major typo above. I meant to suggest latLngBoundsForCamera() as the name of the method, but I got the name backwards.)

Is that an acceptable limitation in the cases where cameraOptionsForLatLngBounds is intended for use?

I think it’d be acceptable, as long as latLngBoundsForCamera() and cameraForLatLngBounds() round-trip values consistently. It may not be perfect for the region-constraining feature, but it’s an improvement over what we have now and would accommodate future improvements without changing the API.

If not, how can we more accurately represent the visible region?

We have cameraForLatLngs() as a polygonal alternative to cameraForLatLngBounds(), although the former currently still suffers from #2259. We could implement a latLngsForCamera(), shifting the responsibility of deciding between inscribing and circumscribing to the SDK.

@brunoabinader
Copy link
Member

@1ec5 @jfirebaugh I've implemented a naïve approach in #8510 - notice though that even this solution does not guarantee precise conversions between cameraForLatLngBounds and latLngBoundsForCamera.

@1ec5 1ec5 added Android Mapbox Maps SDK for Android iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS and removed Core The cross-platform C++ core, aka mbgl labels Mar 24, 2017
@1ec5
Copy link
Contributor Author

1ec5 commented Mar 24, 2017

#8510 landed, so now it’s up to the platforms to use it. For iOS and macOS, I think we’d want to expose this functionality as -[MGLMapView coordinateBoundsVisibleFromCamera:] (or MGLMapView.coordinateBounds(visibleFrom:) in Swift).

@1ec5 1ec5 mentioned this issue Mar 30, 2017
@1ec5 1ec5 added the good first issue Good for newcomers label Mar 30, 2017
@tobrun tobrun removed the Android Mapbox Maps SDK for Android label Aug 15, 2017
@friedbunny friedbunny removed their assignment Oct 23, 2018
@stale stale bot added the archived Archived because of inactivity label Apr 21, 2019
@stale
Copy link

stale bot commented Apr 22, 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 Apr 22, 2019
@julianrex julianrex reopened this Apr 22, 2019
@stale stale bot removed the archived Archived because of inactivity label Apr 22, 2019
@jmkiley jmkiley added the gl-ios label Nov 21, 2019
@stale stale bot added the archived Archived because of inactivity label May 20, 2020
@stale
Copy link

stale bot commented May 23, 2020

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 May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity feature gl-ios good first issue Good for newcomers iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

No branches or pull requests

7 participants