You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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.
Reacted by Natalia O, Ollie Snowden, Matt Votsikas McLean, Hashem, Stephen D'Amico, altafrm3d, rm3dbeckers and Eduard Popov
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.
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.
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
#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.
Activity
1ec5 commentedon Jan 19, 2016
With the map tilted, does it matter that the user will be able to see beyond the scrollable area limit?
1ec5 commentedon Jan 21, 2016
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.
friedbunny commentedon Jan 21, 2016
#2341 is one suggested approach, on iOS.
Zakay commentedon Feb 10, 2016
+1 on setScrollableAreaLimit
At least something like #2341
daklock commentedon Feb 11, 2016
+1 on limiting scrollview
s-a-y commentedon Feb 15, 2016
+1 limiting scrollview
bleege commentedon Feb 17, 2016
@tobrun Let's get this into
4.0.0. Cool?tobrun commentedon Feb 18, 2016
@bleege 👍
@zugaldia
any preference on how we are going to implement this?
This seems to be an overlapping requirement with offline?
zugaldia commentedon Feb 18, 2016
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?
tobrun commentedon Feb 18, 2016
That is true, but how are you restricting bounds there? eg, user downloads region of NYC and than tries to pan to New Jersey?
15 remaining items
1ec5 commentedon Sep 6, 2016
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 forConstrainMode. While you’re at it, you might want to generalizeConstrainModeto 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.
jlormee commentedon Nov 15, 2016
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
Below is the method i place in my OnScrollListener and OnFlingListener:
zugaldia commentedon Nov 15, 2016
Thanks @jlormee for sharing!
1ec5 commentedon Mar 6, 2017
#5584 landed for iOS SDK v3.5.0 and macOS SDK v0.4.0. Removing the iOS label.
brunoabinader commentedon Mar 30, 2017
Implementing core functionality in #8583.
1ec5 commentedon Mar 30, 2017
#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.