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.

Limit Viewport #3602

Closed
Closed

Description

@tobrun

I have been hearing about the feature that developers want to limit the viewport for the end-user.

Sample use-case:

Create a tourist application for NYC, users are restricted to:

  • move the map in NYC area
  • only allowed to zoom between 8 - 14 level
  • tilt is limited to only 20 degrees.
API:

This will result in exposing a similar API as the old raster API:

  • setScrollableAreaLimit() // definition ready
  • setMinZoom() // implemented
  • setMaxZoom() // implemented
  • setMinTilt()
  • setMaxTilt()

iOS is currently thinking about implementing #2457, which will work similar to the rotation snap-back animation we currently have at very low zoom levels.

Activity

  1. added
    iOS
    Android
    on Jan 19, 2016
  2. 1ec5 commented on Jan 19, 2016

    @1ec5
    Contributor

    With the map tilted, does it matter that the user will be able to see beyond the scrollable area limit?

  3. 1ec5 commented on Jan 21, 2016

    @1ec5
    Contributor

    In other words, should these properties constrain the center point or the viewable bounds? If the latter, there could potentially be a complex interaction between the scrollable area limit, zoom, and tilt constraints.

  4. friedbunny commented on Jan 21, 2016

    @friedbunny
    Contributor

    #2341 is one suggested approach, on iOS.

  5. Zakay commented on Feb 10, 2016

    @Zakay

    +1 on setScrollableAreaLimit
    At least something like #2341

  6. daklock commented on Feb 11, 2016

    @daklock

    +1 on limiting scrollview

  7. s-a-y commented on Feb 15, 2016

    @s-a-y

    +1 limiting scrollview

  8. bleege commented on Feb 17, 2016

    @bleege
    Contributor

    @tobrun Let's get this into 4.0.0. Cool?

  9. added this to the android-v4.0.0 milestone on Feb 17, 2016
  10. tobrun commented on Feb 18, 2016

    @tobrun
    MemberAuthor

    @bleege 👍

    @zugaldia
    any preference on how we are going to implement this?
    This seems to be an overlapping requirement with offline?

  11. zugaldia commented on Feb 18, 2016

    @zugaldia
    Member

    @zugaldia any preference on how we are going to implement this? This seems to be an overlapping requirement with offline?

    I'm not sure there's an overlap. Offline tiles would be handled by app users, while a limited viewport would be set by the app developer, isn't it?

  12. tobrun commented on Feb 18, 2016

    @tobrun
    MemberAuthor

    That is true, but how are you restricting bounds there? eg, user downloads region of NYC and than tries to pan to New Jersey?

  13. 15 remaining items

  14. 1ec5 commented on Sep 6, 2016

    @1ec5
    Contributor

    The GL JS implementation allows the developer to constrain the viewable area to a rectangular bounding box, without accounting for rotation or pitch. (If I’m reading the code correctly, the user can still peek beyond the viewable area by rotating or tilting the map.) This approach implements a hard limit, so it won’t accommodate any “rubber band” effect we might want to introduce later (along the lines of #2191).

    If the GL JS approach is sufficient for the Android SDK despite these caveats, it might be easier to write the logic from scratch than to port the GL JS logic. You’ll want to plumb the options down into TransformState::constrain() and use logic similar to what we already do for ConstrainMode. While you’re at it, you might want to generalize ConstrainMode to be just a special case of setting the maximum bounds.

    For the iOS and macOS SDKs, I’m still committed to a different approach outlined in #5584, which allows for a non-rectangular viewable area and would allow for a “rubber band” effect in the future. So those SDKs wouldn’t be using a bbox-style constraint option.

  15. added this to the milestone on Oct 12, 2016
  16. jlormee commented on Nov 15, 2016

    @jlormee

    I did a quick method by utilising the mapboxMap OnScrollListener and OnFlingListener together with the camera method demonstrated here:

    https://www.mapbox.com/android-sdk/examples/fit-bound-camera

    Not perfect but kind of did the job, waiting for a more stable and official method from the SDK
    I paste my code snippet here in case anyone is interested

    public static void easeCameraBackToBoundingBox() {
            LatLngBounds latLngBounds = new LatLngBounds.Builder()
                    .include(NE_LIMIT) // Northeast
                    .include(SW_LIMIT) // Southwest
                    .build();
    
            mapboxMap.easeCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 0), 100);
        }
    

    Below is the method i place in my OnScrollListener and OnFlingListener:

    public static void restrictMapToBoundingBox() {
            VisibleRegion visibleRegion = mapboxMap.getProjection().getVisibleRegion();
    
            Double maxLat = NE_LIMIT.getLatitude();
            Double maxLng = NE_LIMIT.getLongitude();
            Double minLat = SW_LIMIT.getLatitude();
            Double minLng = SW_LIMIT.getLongitude();
    
            if( !(visibleRegion.farLeft.getLatitude() >= minLat && visibleRegion.farLeft.getLatitude() <= maxLat
                    && visibleRegion.farLeft.getLongitude() >= minLng && visibleRegion.farLeft.getLongitude() <= maxLng) ) {
               easeCameraBackToBoundingBox();
            }
            if( !(visibleRegion.farRight.getLatitude() >= minLat && visibleRegion.farRight.getLatitude() <= maxLat
                    && visibleRegion.farRight.getLongitude() >= minLng && visibleRegion.farRight.getLongitude() <= maxLng) ) {
               easeCameraBackToBoundingBox();
            }
            if( !(visibleRegion.nearLeft.getLatitude() >= minLat && visibleRegion.nearLeft.getLatitude() <= maxLat
                    && visibleRegion.nearLeft.getLongitude() >= minLng && visibleRegion.nearLeft.getLongitude() <= maxLng) ) {
               easeCameraBackToBoundingBox();
            }
            if( !(visibleRegion.nearRight.getLatitude() >= minLat && visibleRegion.nearRight.getLatitude() <= maxLat
                    && visibleRegion.nearRight.getLongitude() >= minLng && visibleRegion.nearRight.getLongitude() <= maxLng) ) {
               easeCameraBackToBoundingBox();
            }
        }
    
    
  17. zugaldia commented on Nov 15, 2016

    @zugaldia
    Member

    Thanks @jlormee for sharing!

  18. removed their assignment
    on Dec 9, 2016
  19. removed this from the android-v5.0.0 milestone on Mar 6, 2017
  20. 1ec5 commented on Mar 6, 2017

    @1ec5
    Contributor

    #5584 landed for iOS SDK v3.5.0 and macOS SDK v0.4.0. Removing the iOS label.

  21. added
    GL JS parity
    Google Maps parity
    and removed
    iOS
    Google Maps parity
    on Mar 6, 2017
  22. brunoabinader commented on Mar 30, 2017

    @brunoabinader
    Contributor

    Implementing core functionality in #8583.

  23. 1ec5 commented on Mar 30, 2017

    @1ec5
    Contributor

    #8583 is the most straightforward approach to allowing the developer to limit the viewport, but I don’t expect that the iOS and macOS SDKs will need to adopt it. Instead, those SDKs persued a very different solution for the use case of limiting the viewport, as proposed in #2457: instead of fixed bounds and zoom levels, there’s a delegate method (callback) that allows the developer to decide on demand, in advance, whether to allow a change to the viewport.

    The delegate approach is more consistent with standard scroll view APIs on the iOS and macOS platforms. It allows the developer to constrain the map to a non-polygonal region of the world and a non-rectangular-prism camera space, and it’ll eventually allow the iOS and macOS SDKs to implement rubber banding (#2191), varying the maximum pitch by zoom level (#6908), and snapping the rotation without special cases all over the gesture handling code. At a high level, this approach is consistent with a general push to complement declarative APIs with imperative APIs (other examples being runtime styling, computed GeoJSON sources, etc.).

    With the delegate method already in place in #5584 and further conveniences coming in #8499, I don’t think it’ll be necessary to introduce another public API for limiting the viewport on iOS or macOS. However, if the Android SDK or other frontends need the more straightforward approach in #8583, it seems perfectly reasonable to provide this support at the core level.

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

Metadata

Metadata

Assignees

Labels

AndroidGL JS parityfeature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions