GWT-EXT+Maps Rendering/Resizing Solution

On my previous post about Google Maps I mention about my own map having some issues during the rendering process. Those of you who have tried working on Maps using GWT-EXT I bet you know exactly what I mean. Something like this:


After months of waiting for solution I almost gave up on this problem and almost quit on this like most developers. Unlike them I did not gave up, no not yet.

Here's the solution...

The most obvious clue to solve this problem is the resizing since every time you re-size your browser everything works well. Unfortunately, Panelmaps on GWT-EXT doesn't have a command like this (or I'm just too dumb not to figure it out).

May alternative was to use the Google Maps Api. You can download it here: http://code.google.com/p/gwt-google-apis/

The next step will be to use the latest Google Webtoolkit 1.5.3 just to make sure everything works. You can download it here: http://code.google.com/webtoolkit/download.html (Note: I tried the first version before GWT 1.5.0 and generated errors)

Overwrite your old GWT version with the new one.

Extract your Google Maps Api and in my case include it to your library. Something like this...


The next step is to add Google maps to your xml project and inhert it. On my project it is located at EIS.gwt.xml. Then add this inherit code to your xml file:

"inherits name="com.google.gwt.maps.GoogleMaps" (Don't forget to add the open and close bracket. "< .../>")

Now here is the actual code to execute...

MapWidget mapWiget= new MapWidget(LatLng.newInstance(21, 106), 5);

mapWiget.setSize("100%", Window.getClientHeight() + "px");

mapWiget.addControl(new LargeMapControl());
mapWiget.addControl(new MapTypeControl());

//auto resize the map
Window.addWindowResizeListener(new WindowResizeListener(){

public void onWindowResized(int width, int height) {
mapWiget.setHeight(height + "px");

}

});

mapWiget.checkResize();

panelMap.add(mapWiget);

The key to render the map correctly is the code "checkResize();"

Now, I can move on working more on my Ajax.

Comments

Anonymous said…
nice men! do u have live account?

Popular posts from this blog

John Gokongwei Speech before Ateneo 2004 Graduates

SM Mall of Asia

GWT+MySQL Best Practice