public void onMapInitialized(MapInitializationEvent event) {
// When the map initializes: add a CheckBox for every layer, so the use can toggle visibility:
for (int i = 0; i < mapPresenter.getLayersModel().getLayerCount(); i++) {
final Layer<?> layer = mapPresenter.getLayersModel().getLayer(i);
CheckBox layerCheck = new CheckBox(layer.getTitle());
layerCheck.setValue(layer.isMarkedAsVisible());
// When CheckBox value changes, change the layer's visibility as well:
layerCheck.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue() != null) {
layer.setMarkedAsVisible(event.getValue());
}