moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 337 forks source link

Restrict scroll/zoom positions to an arbitrary rectangle #468

Closed strombringer closed 6 years ago

strombringer commented 6 years ago

Is there a built-in way to restrict the scroll positions to an arbitrary rectangle?

E.g. to implement a "view finder"-like functionality for cropping a part of the original image, I want the minimum X and Y positions for the top left corner of the fictional map example match the top left corner of the view finder and that the user can't pan further: viewfinder_example

In addition I would like to restrict the minimum scale as with MinimumScaleMode.FIT, just with this arbitrary recangle.

If there is no existing functionality to achieve that, could you point me in the right direction of where to start in the code? I tried already to modify ZoomPanLayout.getScrollLimitX(), getScrollLimitY(), getConstrainedScrollX() and getConstrainedScrollY() but didn't manage to get it right.

moagrius commented 6 years ago

there's nothing built in to do that. you can subclass and override the scroll limit functions with your own logic. you'd have to write your own framing logic, but that's fairly straightforward - i've done similar custom functionality previously without too much trouble

strombringer commented 6 years ago

Thank you for the reply. I thought as much, I just wasn't getting the output I expected. It turns out I forgot to take the Offset into account.

In case anyone else needs something like this, here are the changes I made to the ZoomPanLayout to support my use case: Custom ZoomPanLayout (The gist only contains the methods I changed or added. The rest of the class stays the same)