使用 Osmdroid 进行捏合缩放

发布于 2024-12-07 09:50:08 字数 582 浏览 5 评论 0原文

我编写了一个地图应用程序,它有两个活动,一个活动显示 Google 地图视图,另一个活动使用 osmdroid 3.0.5 jar 显示等效视图。

到目前为止,我仅在模拟器上进行测试,并且在显示区域和覆盖数据方面功能完全相同。现在我已经在真正的 Gingerbread 设备上运行该应用程序,我注意到 Google 地图活动似乎支持捏合缩放,而 Osmdroid 活动则不支持。

我还没有为 Google 端或 Osmdroid 编写任何特定于捏合缩放的代码。这两个活动都实现了 OnTouchListener。这两个活动都只有一个 OnTouch 存根,例如:

@Override
public boolean onTouch(View v, MotionEvent e) {
    // chain it for now
    return false;
}

Osmdroid 活动中的我的地图视图属于以下类别: org.osmdroid.views.MapView

有谁知道如何使用 osmdroid 进行捏合缩放或了解使用 osmdroid 的示例应用程序我可以研究并适应我的应用程序?

I've written a mapping application which has two activities, one activity displays a Google Maps view, the other displays the equivalent view using osmdroid 3.0.5 jar.

Until now I've been testing on emulators only and the functionality is completely identical in terms of area shown and overlay data. Now I have run the app on a real Gingerbread device, I notice that the Google Maps activity seems to support pinch to zoom, whilst the Osmdroid one doesn't.

I haven't written any code specific to pinch to zoom for the Google side or for Osmdroid. Both activities implement OnTouchListener. Both activities just have a stub for OnTouch like:

@Override
public boolean onTouch(View v, MotionEvent e) {
    // chain it for now
    return false;
}

My mapview in the Osmdroid activity is of the class: org.osmdroid.views.MapView

Does anybody know how to make pinch to zoom work with osmdroid or know of a sample application using osmdroid that I could study and adapt into my app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小女人ら 2024-12-14 09:50:08
MapView.setBuiltInZoomControls(true);
MapView.setMultiTouchControls(true);
MapView.setBuiltInZoomControls(true);
MapView.setMultiTouchControls(true);
身边 2024-12-14 09:50:08

Osmdroid 具有缩放功能。您需要设置一个手势监听器来检查捏合动作,此时您应该调用 osmdroid 中的缩放功能。我相信在 osmdroid 3.0.5 中它类似于

mOsm.getController.setZoomLevel(someNumber) (mOsm 是地图视图的实例)。

我的缩放功能适用于相反的捏合(手指开始并拢,然后展开)。我建议使用 MotionEvent (就像您当前正在做的那样)并执行以下操作:

boolean finished = false;

@Override
public boolean onTouch(View v, MotionEvent e) {

    switch (e.getAction()) {

        case MotionEvent.ACTION_DOWN:
            finished = false;
            break;

        case MotionEvent.ACTION_MOVE:
            finished = false;
            break;

        case MotionEvent.ACTION_UP:
            //action is finishing at this point, so now I can do my refreshActionOnMap();
            if (!finished) 
                refreshActionOnMap();
            break;
    }
    return true;
}

我添加的代码处理捏点 - 完成的布尔值是我在程序中实现的,用于确定何时刷新地图。这应该可以帮助你更多。

这里对此有进一步的解释。

如果您正在寻找不同的东西,请尝试阅读此处< /a>.显然,Android 自 2010 年 6 月以来一直支持捏合操作。

Osmdroid has the functionality to zoom. You will need to setup a gesturelistener to check for the pinch action, at which point you should call the zoom function in osmdroid. I believe in osmdroid 3.0.5 it is something like

mOsm.getController.setZoomLevel(someNumber) (mOsm is an instance of the map view).

I have the zoom function working for the opposite pinch (you fingers start close together and then expand). I suggest using a MotionEvent (like you are currently doing) and doing something like this:

boolean finished = false;

@Override
public boolean onTouch(View v, MotionEvent e) {

    switch (e.getAction()) {

        case MotionEvent.ACTION_DOWN:
            finished = false;
            break;

        case MotionEvent.ACTION_MOVE:
            finished = false;
            break;

        case MotionEvent.ACTION_UP:
            //action is finishing at this point, so now I can do my refreshActionOnMap();
            if (!finished) 
                refreshActionOnMap();
            break;
    }
    return true;
}

The code I have added deals with the pinch - the finished boolean is something I implemented in my program to figure out when to refresh the map. That should help you out more.

Here is a further explanation of this.

If you are looking for something different, then try reading here. Android has been supporting the pinch action since June 2010 apparently.

烟燃烟灭 2024-12-14 09:50:08

是否可以不缩放到地图中心,而是缩放到用户两根手指的中间。

Is it possible not to zoom to the map center but to the middle of users two finger.

热情消退 2024-12-14 09:50:08

正如 Shameus.burp 所说,代码线 -

mapView.setMultiTouchControls(true); 

正在为我工​​作,以便捏缩放(在 2021 年检查)。

请注意,显示缩放控制器的功能(基本上是 (-) 和 (+) 按钮) -

MapView.setBuiltInZoomControls(true);

已被 osmdroid 弃用。

因此,您可以使用代码行 -

mapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.ALWAYS);

默认情况下(不添加最后一个代码行)osmdroid 将缩放控制器设置为显示和淡入淡出。相当于

CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT 

选项。

As shameus.burp said, the codeline-

mapView.setMultiTouchControls(true); 

Is working for me in order to pinch for zoom (check at 2021).

Notice that the function that shows zoom-controller (basically it is buttons of (-) and (+)) -

MapView.setBuiltInZoomControls(true);

is deprecated by osmdroid.

So instead, you can use the code line -

mapView.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.ALWAYS);

By default (without adding the last code line) osmdroid is set the zoom-controller to show and fade. Equivalent to

CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT 

option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文