限制用户在 Mapview 上可以到达的区域
我正在使用地图视图的定制版本(OSMDroid 版本)。 我在其中使用自定义图块,我只希望用户能够查看我拥有自定义图块的区域。 有没有办法设置边界纬度,以便当他们平移地图时不会超出这些边界?
I am using a customised version of the mapview (OSMDroid version).
I am using custom tiles within it and I only want the user to be able to view the area where I have my custom tiles.
Is there a way to set the boundary lat longs so when they pan the map it doesn't go past these boundaries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更新:我知道这是一个老问题,但 osmdroid 现在有一个 setScrollableAreaLimit() 方法,可以实现您正在寻找的内容。还有 setMinZoomLevel() 和 setMaxZoomLevel() 方法可以轻松限制缩放级别。
原始答案:
请关注:
http ://code.google.com/p/osmdroid/issues/detail?id=209
补丁已经创建,可能很快就会集成。
Update: I know this is an old question, but osmdroid now has a setScrollableAreaLimit() method that will achieve what you are looking for. There is also a setMinZoomLevel() and setMaxZoomLevel() method to easily restrict zoom levels.
Original answer:
Please keep an eye on:
http://code.google.com/p/osmdroid/issues/detail?id=209
A patch has already been created, and will likely be integrated shortly.
此内容是从 osmdroid 主题交叉发布的。现在列出了一个 BoundedMapView 类,它实现了前面提到的补丁。
This is cross-posted from the osmdroid thread. There's now lists a
BoundedMapView
class, which implements the afortementioned patch.万一它对任何人有帮助......
我有一种正在使用的解决方案,它工作正常,但肯定会更好,因为地图在跳回来之前可能会离屏幕太远!
它使用经纬度并计算出地图的位置,我设置了 4 个坐标,它们大约是地图的 4 个角,我发现如果将它们稍微设置到地图中而不是精确地设置角,效果会更好,然后我计算出是否纬度经度已完全离开屏幕..如果是这样,它会弹回一半:
我覆盖了地图视图和地图的 OnTouch 事件
如果您正在考虑使用此功能,我应该指出一些事情:
如果有人有更好的解决方案或可以改进我的代码,请随时!
Incase it helps anyone....
I have sort of a solution that I am using, it works ok, but could definitely be better as the map can go abit too far off the screen before it jumps back!
It uses the lat longs and works out where the map is, I set 4 coordinates which are roughly the 4 corners of the map I have found it works better if you set them slightly into the map rather exactly the corners, I then work out if the lat longs have left the screen completely.. if so it will bounce it halfway back:
I overrode the mapview and the OnTouch event of the map
A few things I should point out if you are considering using this:
If anyone has any better solutions or can improve my code please feel free!
我正在寻找完全相同的东西。
我最好的方法是添加一个覆盖层,它扩展了 boolean onScroll(...) 。如果返回 true,则滚动被取消。
这正是我想要的,除了一件事:猛击/轻弹。相同的方法可用于取消 fling 事件,尽管您只能在 fling 开始时听到它。
理想情况下,您能够监听computeScroll()方法,并基于mScroller.getCurX限制滚动的
(x, y)
() 和mScroller.getCurY()
。I'm looking for exactly the same thing.
My best lead is to add an Overlay, which extends
boolean onScroll(...)
. If this returns true, then the scroll is cancelled.This is exactly how I want it, except for one thing: flinging/flicking. The same approach can be used to cancel fling events, though you only get to hear about it at the start of the fling.
Ideally, you'd be able to listen to the
computeScroll()
method, and limit the(x, y)
of the scroll, based onmScroller.getCurX()
andmScroller.getCurY()
.