Wicket GMap2 off centre
Simple trick how to get map centred when is coming of centre
We started having problems Google maps, from Wicket GMap2 project, after we placed flash loading animation before application data retrieval logic. What was happening is that map with single destination marker been of centre with left and sometimes bottom section of map being grey colour. In case of multiple destinations map become zoomed out to zoom 0.0.
|
|
Map of centre | Expected view |
We seen that map will eventually centre out if we apply any of filter options available on the page to refresh data, while map coordinates wouldn't change. So what we need it was a way to create AjaxRequestTarget event where we can then add our map trough AjaxRequestTarget.addComponent(Component) and trigger refresh on component.This can be achieved as follows
map.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(50)) {
@Override
protected void onTimer(AjaxRequestTarget target) {
map.removeAll();
map.setMap(map.getMap());
map.setOutputMarkupId(true);
target.addComponent(map);
stop();
}
});
where map.setMap() is simple as
public void setMap(GMap2 newMap) {
removeAll();
map = newMap;
add(map);
}













