将mapView缩放到osmdroid上的某个边界框 [英] zoom mapView to a certain bounding box on osmdroid

查看:244
本文介绍了将mapView缩放到osmdroid上的某个边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用zoomToBoundingBox方法将地图缩放到特定的边界框.
该方法仅在缩放级别0上显示地图.什么都不做.

I want to use the zoomToBoundingBox method to zoom a map to a specific bounding box.
The method does nothing but display the map on zoom level 0.

在mapView.java源代码中,我发现了这一点:

In the mapView.java source code I found this:

/** *尽可能缩放地图以包围指定的边界框. *必须在显示布局完成或屏幕尺寸未知后调用,并且 *将始终缩放到缩放级别0的中心. *建议:检查getScreenRect(null).getHeight()> 0 */

/** * Zoom the map to enclose the specified bounding box, as closely as possible. * Must be called after display layout is complete, or screen dimensions are not known, and * will always zoom to center of zoom level 0. * Suggestion: Check getScreenRect(null).getHeight() > 0 */

我检查了getScreenRect(null).getHeight() > 0,它给了我错误的答案.

I checked getScreenRect(null).getHeight() > 0 and it gives me false.

如何以编程方式完成显示布局?
我该怎么做才能使上述谓词使我成真?

How do you complete display layout programmatically?
What can I do so that the above predicate gives me true?

推荐答案

我遇到了同样的问题.我通过在onLayout()方法末尾调用zoomToBoundingBox()来解决此问题.

I had the same problem. I addressed it by calling the zoomToBoundingBox() call at the end of the onLayout() method.

我有自己的MapView子类,用于将我与地图库选择隔离.此类具有clearPoints/addPoint/layoutPoints样式的接口.在layoutPoints()方法中,我从点集合中创建逐项叠加层,并创建存储在该类的实例方法中的边界框.

I have my own subclass of MapView that I use to insulate me from the map library choice. This class has a clearPoints / addPoint / layoutPoints style of interface. Within the layoutPoints() method I create the itemized overlay lay from the collection of points and create the bounding box that is stored in an instance method of the class.

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;

我的onLayout()重写具有:

My onLayout() override has:

/* (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);
    }
}

我不确定这是否是最好的方法,但是它似乎对我有用(只是变焦似乎有点太远了,但这又是另一个问题了.)

I'm not sure if this is the best way of doing it, but it seems to work for me (except that the zoom appears to be a little too far out, but that's another problem for another time).

这篇关于将mapView缩放到osmdroid上的某个边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆