FlowPanel controls = new FlowPanel();
controls.setStyleName("controls");
mainDock.addNorth(controls, 2);
final MapWidget map = new MapWidget(opts);
mainDock.add(map);
LatLngBounds bounds = LatLngBounds.newInstance();
bounds.extend(LatLng.newInstance(37.660773,-122.534448));
bounds.extend(LatLng.newInstance(37.860773,-122.334448));
map.fitBounds(bounds);
// Add the controls
latLonBox = new TextBox();
latLonBox.setText("37,-122");
controls.add(latLonBox);
controls.add(new Button("Switching InfoWindow", new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
initInfoWindow();
FlowPanel panel = new FlowPanel();
panel.add(new Button("Click Me", handler1));
infoWindow.setContent(panel);
infoWindow.open(map.getMapJSO());
}
}));
controls.add(new Button("Expanding InfoWindow", new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
initInfoWindow();
final FlowPanel panel = new FlowPanel();
panel.add(new Button("Click Me", new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
// Doesn't work
panel.clear();
panel.add(new Label("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."));
infoWindow.setContent(panel);
infoWindow.setContent(panel);
// Works
// FlowPanel nextPanel = new FlowPanel();
// nextPanel.add(new Label("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."));
// infoWindow.setContent(nextPanel);
}
}));
infoWindow.setContent(panel);
infoWindow.open(map.getMapJSO());
}
}));
controls.add(new Button("Reverse Geocode", new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
String latLonStr = latLonBox.getText();
String[] split = latLonStr.split(",");
float lat = Float.parseFloat(split[0]);
float lon = Float.parseFloat(split[1]);
final LatLng point = LatLng.newInstance(lat, lon);
map.getMapJSO().panTo(point);
GeocoderRequest request = GeocoderRequest.newInstance();
request.setLatLng(point);
GWT.log("Geocoding " + point, null);
Geocoder geocoder = Geocoder.newInstance();
geocoder.geocode(request, new GeocoderCallback() {
@Override
public void callback(JsArray<GeocoderResponse> responses, GeocoderStatus status)
{
GWT.log("Got callback with status " + status, null);
if (status.equals(GeocoderStatus.OK))
{
InfoWindowJSO info = InfoWindowJSO.newInstance();
info.setPosition(point);
if (responses.length() > 0)
{
info.setContent(responses.get(0).toString());
}
else
{
info.setContent("No results from geocoder");
}
info.open(map.getMapJSO());
}
else
{
Window.alert("Geocoder failed: " + status);
}