private MoveEndListener moveEndBehavior;
public HomePage()
{
final GMap2 map = new GMap2("map", GMapExampleApplication.get().getGoogleMapsAPIkey());
map.addControl(GControl.GLargeMapControl);
add(map);
map.add(new LoadListener()
{
private static final long serialVersionUID = 1L;
@Override
protected void onLoad(AjaxRequestTarget target)
{
target.addComponent(boundsLabel);
}
});
moveEndBehavior = new MyMoveEndListener();
map.add(moveEndBehavior);
zoomLabel = new Label("zoom", new PropertyModel<Integer>(map, "zoom"));
zoomLabel.setOutputMarkupId(true);
add(zoomLabel);
boundsLabel = new MultiLineLabel("bounds", new PropertyModel<GLatLngBounds>(map, "bounds"))
{
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
public IConverter getConverter(Class type)
{
if (GLatLngBounds.class.isAssignableFrom(type))
{
return new IConverter()
{
private static final long serialVersionUID = 1L;
public GLatLngBounds convertToObject(String value, Locale locale)
{
throw new UnsupportedOperationException();
}
public String convertToString(Object value, Locale locale)
{
GLatLngBounds bounds = (GLatLngBounds)value;
StringBuffer buffer = new StringBuffer();
buffer.append("NE (");
buffer.append(bounds.getNE().getLat());
buffer.append(",");
buffer.append(bounds.getNE().getLng());
buffer.append(")\nSW (");
buffer.append(bounds.getSW().getLat());
buffer.append(",");
buffer.append(bounds.getSW().getLng());
buffer.append(")");
return buffer.toString();
}
};
}
else
{
return super.getConverter(type);
}
}
};
boundsLabel.setOutputMarkupId(true);
add(boundsLabel);
final Label enabledLabel = new Label("enabled", new Model<Boolean>()
{
private static final long serialVersionUID = 1L;
@Override
public Boolean getObject()
{
return map.getBehaviors().contains(moveEndBehavior);
}
});
enabledLabel.add(new AjaxEventBehavior("onclick")
{
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target)
{
if (map.getBehaviors().contains(moveEndBehavior))
{
map.remove(moveEndBehavior);
}
else
{
// TODO AbstractAjaxBehaviors are not reusable, so
// we have
// to recreate:
// https://issues.apache.org/jira/browse/WICKET-713
moveEndBehavior = new MyMoveEndListener();
map.add(moveEndBehavior);
}
target.addComponent(map);
target.addComponent(enabledLabel);
}
});