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

Method to convert arbitrary CameraOptions to LatLngBounds #8499

Closed

Description

@1ec5

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

Activity

  1. added
    Core
    on Mar 22, 2017
  2. jfirebaugh commented on Mar 22, 2017

    @jfirebaugh
    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?

  3. 1ec5 commented on Mar 22, 2017

    @1ec5
    ContributorAuthor

    (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.

  4. brunoabinader commented on Mar 23, 2017

    @brunoabinader
    Contributor

    @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.

  5. added
    Android
    iOS
    macOS
    and removed
    Core
    on Mar 24, 2017
  6. 1ec5 commented on Mar 24, 2017

    @1ec5
    ContributorAuthor

    #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).

  7. added
    good first issue
    on Mar 30, 2017
  8. removed
    Android
    on Aug 15, 2017
  9. removed their assignment
    on Oct 23, 2018
  10. added
    archived
    on Apr 21, 2019
  11. stale commented on Apr 22, 2019

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  12. removed
    archived
    on Apr 22, 2019
  13. added
    archived
    on May 20, 2020
  14. stale commented on May 23, 2020

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    archivedfeaturegl-iosgood first issueiOSmacOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions