Set minimum zoom level for MapView
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 blo开发者_开发百科ck that zoom level. Ideally, it would work whether the user is zooming through gestures or zoom controls.
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);
精彩评论