PDA

View Full Version : Rendering Google MAPS in GXT



eburgerwa
27 Dec 2010, 6:07 PM
Hi,

I am quite sure I am missing something rather elementary here, and hope someone can help me.

When I use GWT's dockpanel as the enclosing container, the Google Map renders just fine. When, however, i use GXT's LayoutContainer, it does not render. What am I doing wrong?

I am using GXT 2.2.1, GWT 2.1.0 and ver 1.1.0 of the GWT Maps API.

Thank you in advance for any help.

Here is the code snippet in question.

The onModuleLoad method:
public void onModuleLoad() {

// final DockLayoutPanel dock = new DockLayoutPanel(Unit.PX);
LayoutContainer container = new LayoutContainer();
container.setSize(500, 500);

Maps.loadMapsApi("my_key", "2", false, new MapRunnable(container));

RootPanel.get().add(container);
container.layout();
}


public class MapRunnable implements Runnable
{
DockLayoutPanel dock = null;
LayoutContainer container = null;

/**
* @param map
*/
public MapRunnable(DockLayoutPanel dock)
{
this.dock = dock;
}

public MapRunnable(LayoutContainer container)
{
this.container = container;
}

MapWidget map;

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run()
{
buildMap();

}



private void buildMap()
{
Window.alert("Google Maps loaded!");

LatLng seattle = LatLng.newInstance(47.45, -122.30);

map = new MapWidget(seattle, 2);
map.setPixelSize(500, 500);
map.addControl(new LargeMapControl());

map.addOverlay(new Marker(seattle));

// Add an info window to highlight a point of interest
map.getInfoWindow().open(map.getCenter(), new InfoWindowContent("Seattle"));

// dock.addNorth(map, 500);
container.add(map);
}

}

sven
28 Dec 2010, 2:27 AM
After
container.add(map); try to call
container.layout();

eburgerwa
28 Dec 2010, 9:52 AM
Hello Sven,

Thank you very much - that solved the problem. Any pointers to GXT documentation on where we need to call layout and where not?

Cheers
Eugene

sven
28 Dec 2010, 9:59 AM
Everytime you modify a container (add or remove) you need to call it.