我知道这个线程有点旧,但可以在http://code.google.com/p/osmdroid/issues/detail?id=209上找到这个问题的答案
要点是设置地图的最大范围并限制滚动到那个程度。以下是上述问题的摘要(将以下代码添加到 MapView.java)
protected Rect mScrollableAreaLimit = null;
public void setScrollableAreaLimit(BoundingBoxE6 boundingBox) {
final int worldSize_2 = TileSystem.MapSize(MapViewConstants.MAXIMUM_ZOOMLEVEL) / 2;
// Clear scrollable area limit if null passed.
if (boundingBox == null) {
mScrollableAreaLimit = null;
return;
}
// Get NW/upper-left
final Point upperLeft = TileSystem.LatLongToPixelXY(boundingBox.getLatNorthE6() / 1E6,
boundingBox.getLonWestE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
upperLeft.offset(-worldSize_2, -worldSize_2);
// Get SE/lower-right
final Point lowerRight = TileSystem.LatLongToPixelXY(boundingBox.getLatSouthE6() / 1E6,
boundingBox.getLonEastE6() / 1E6, MapViewConstants.MAXIMUM_ZOOMLEVEL, null);
lowerRight.offset(-worldSize_2, -worldSize_2);
mScrollableAreaLimit = new Rect(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);
}
现在您可以在创建地图视图时调用 setScrollableAreaLimit 方法,也可以使用 BoundingBoxE6 参数展开构造函数。
希望这可以帮助。
除此之外,还需要对双击错误进行更正http://code.google.com/p/osmdroid/issues/detail?id=209#c23
@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
if (mScroller.isFinished()) {
// This will facilitate snapping-to any Snappable points.
setZoomLevel(mZoomLevel);
} else {
/* correction for double tap */
int targetZoomLevel = getZoomLevel();
if (targetZoomLevel == mZoomLevel)
scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
}
postInvalidate(); // Keep on drawing until the animation has
// finished.
}
}