<< Wicket - AjaxLazyLoadPanel loading indicator with flash | Home | Create Android project without IDE >>

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);
    }

Categories : Java, Tips, Wicket

Export this post as PDF document  Export this post to PDF document

Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!
Technorati Tags : , , , , ,



Add a comment Send a TrackBack