HLayout mapLayout = new HLayout();
mapLayout.setShowEdges(true);
mapLayout.setHeight("60%");
// Map with ID mapOsm is defined in the XML configuration. (mapOsm.xml)
final MapWidget map = new MapWidget("mapOsm", "gwt-samples");
map.setController(new PanController(map));
mapLayout.addMember(map);
HLayout buttonLayout = new HLayout();
buttonLayout.setMembersMargin(10);
// Create a button to toggle bounds between the whole world an Belgium
final IButton butToggleMaxBounds = new IButton(I18nProvider.getSampleMessages().toggleMaxBoundsBelgium());
butToggleMaxBounds.setWidth100();
buttonLayout.addMember(butToggleMaxBounds);
butToggleMaxBounds.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (isBelgiumBoundsEnabled) { // switch to whole world bounds
isBelgiumBoundsEnabled = false;
map.getMapModel().getMapView().setMaxBounds(maxBounds);
butToggleMaxBounds.setTitle(I18nProvider.getSampleMessages().toggleMaxBoundsBelgium());
} else { // switch to Belgium bounds
if (maxBounds == null) {
// First we save the World bounds:
maxBounds = map.getMapModel().getMapView().getMaxBounds();
}
map.getMapModel().getMapView().setMaxBounds(belgiumBounds);
// force a new scale level so we go inside the bounding box of Belgium
map.getMapModel().getMapView().applyBounds(belgiumBounds, ZoomOption.LEVEL_FIT);
isBelgiumBoundsEnabled = true;
butToggleMaxBounds.setTitle(I18nProvider.getSampleMessages().toggleMaxBoundsWorld());
}
}
});