tha*_*io2 6 maps android bounding-box openstreetmap
我想使用zoomToBoundingBox方法将地图缩放到特定的边界框.
该方法除了在缩放级别0上显示地图外什么都不做.
在mapView.java源代码中我发现了这个:
/***缩放地图以尽可能地包围指定的边界框.*必须在显示布局完成后调用,或者屏幕尺寸未知,并且*将始终缩放到缩放级别0的中心.*建议:检查getScreenRect(null).getHeight()> 0*/
我查了一下getScreenRect(null).getHeight() > 0,它给了我假.
如何以编程方式完成显示布局?
我能做什么才能使上述谓词真实?
我有同样的问题。我通过在 onLayout() 方法末尾调用 ZoomToBoundingBox() 来解决这个问题。
我有自己的 MapView 子类,用它来使我免受地图库选择的影响。这个类有一个clearPoints/addPoint/layoutPoints风格的接口。在layoutPoints() 方法中,我从点集合中创建逐项覆盖层,并创建存储在类的实例方法中的边界框。
public class MyMapView extends MapView {
// The bounding box around all map points
// Used to determine the correct zoom level to show everything
private int minLat = Integer.MAX_VALUE;
private int minLon = Integer.MAX_VALUE;
private int maxLat = Integer.MIN_VALUE;
private int maxLon = Integer.MIN_VALUE;
private BoundingBoxE6 boundingBox;
Run Code Online (Sandbox Code Playgroud)
我的 onLayout() 重写有:
/* (non-Javadoc)
* @see org.osmdroid.views.MapView#onLayout(boolean, int, int, int, int)
*/
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
super.onLayout(arg0, arg1, arg2, arg3, arg4);
// Now that we have laid out the map view,
// zoom to any bounding box
if (this.boundingBox != null) {
this.zoomToBoundingBox(this.boundingBox);
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是最好的方法,但它似乎对我有用(除了变焦似乎有点太远,但这是另一个问题)。