我知道您找到了隐藏叠加层的方法,但是有更优雅的方法可以做到这一点。为您的叠加层创建一个自定义类:
public class MapOverlay extends Overlay{
private Boolean visible;
public MapOverlay(){
this.visible = true;
}
public void draw(Canvas canvas, MapView mapv, boolean shadow){
super.draw(canvas, mapv, shadow);
if (visible) {
// draw what you want
}
}
public Boolean isVisible() {
return visible;
}
public void isVisible(Boolean visible) {
this.visible = visible;
}
public void toggleVisible() {
this.visible = !visible;
}
}
然后在您的活动中,像往常一样添加叠加层:
mapView.getOverlays().addOverlay(new MapOverlay());
Later, if you want to show/hide your overlay, simply call:
mapView.getOverlays().get(0).toggleVisible();
or:
mapView.getOverlays().get(0).isVisible(false);
Hope it helps.