Set minimum zoom level for MapView

Deadly 提交于 2019-11-28 09:18:30

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

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!

just write onCreate following code:

MapController myMC myMapView.getController();
myMC.setZoom(int value);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!