设置 MapView 的最小缩放级别

发布于 2024-10-01 10:15:35 字数 122 浏览 2 评论 0原文

有没有办法为我的 MapView 设置最小缩放级别?当缩放级别设置为 1 时,地图看起来非常丑陋,因为整个世界地图都被复制了。

我想阻止该缩放级别。理想情况下,无论用户是通过手势还是缩放控件进行缩放,它都可以工作。

Is there a way I can set a minimum zooM level for my MapView?. The map looks really ugly when zoom level is set to one because the whole world map replicated.

I would like to block that zoom level. Ideally, it would work whether the user is zooming through gestures or zoom controls.

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

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

发布评论

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

评论(3

无远思近则忧 2024-10-08 10:15:36

只需在 onCreate 中编写以下代码:

MapController myMC myMapView.getController();
myMC.setZoom(int value);

just write onCreate following code:

MapController myMC myMapView.getController();
myMC.setZoom(int value);
池木 2024-10-08 10:15:35

幸运的是,我的 MapView 中有一个叠加层。否则,我想你将不得不创建一个,只是为了这个微小的功能:-/。我想知道为什么没有其他方法可以更轻松地做到这一点。

无论如何,你只需要像这样重写你的绘制方法:

@Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        if (mapView.getZoomLevel() < 2)
            mapView.getController().setZoom(2);
    }

Ger

Fortunately, i was having an overlay in my MapView. Otherwise, i guess you will have to create one, just for this tiny feature :-/. I wonder why there isn't any other way of doing this easier.

Anyways, you just need to override your draw method like this:

@Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        if (mapView.getZoomLevel() < 2)
            mapView.getController().setZoom(2);
    }

Ger

遇到 2024-10-08 10:15:35

ggomeze 的答案类似,通过重写 *draw() 方法,但最好在 MapView 中重写 dispatchDraw()代码>.通过这种方式,您可以阻止对图块为空的缩放级别进行绘制。

另请注意,此时最好将地图居中,就好像您使用触摸手势进行缩放一样,手动设置缩小一级可能会导致地图每次偏离中心(这使得 MapView代码> 看起来有点狡猾!)。

@Override
public void dispatchDraw(Canvas canvas) {

    //limit zoom level 
    if(getZoomLevel() == 1){
        getController().setZoom(2);
        getController().setCenter(new GeoPoint(0, 0));
        //dont draw as it will just be blank and then jump
        return;
    }

    super.dispatchDraw(canvas);
}

这可以通过在手势发生时跟踪缩放级别来改进,这样用户在手势时就看不到部分缩放到被阻止的最低缩放级别 (1),但我想上面的情况最适合并且很多更轻松!

Similar to ggomeze's answer by overriding a *draw() method but it may be better to override dispatchDraw() in MapView. This way you can block the draw for the zoom level where the tiles are empty.

Also note that its good to center the map at this point as if you are zooming with touch gestures manually setting the zoom out by one level can cause the map to shift away from the center each time (which makes the MapView look a bit more dodgy!).

@Override
public void dispatchDraw(Canvas canvas) {

    //limit zoom level 
    if(getZoomLevel() == 1){
        getController().setZoom(2);
        getController().setCenter(new GeoPoint(0, 0));
        //dont draw as it will just be blank and then jump
        return;
    }

    super.dispatchDraw(canvas);
}

This could be improved upon by tracking the zoom level while the gesture is taking place also so the user can not see the partial zoom to the blocked lowest zoom level (1) while gesturing but i imagine the case above will suit most and is a lot easier!

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