Adding a div element inside a panel?
- by Bar Mako
I'm working with GWT and I'm trying to add google-maps to my website.
Since I want to use google-maps V3 I'm using JSNI.
In order to display the map in my website I need to create a div element with id="map" and get it in the initialization function of the map. I did so, and it worked out fine but its location on the webpage is funny and I want it to be attached to a panel I'm creating in my code.
So my question is how can I do it?
Can I create a div somehow with GWT inside a panel ?
I've tried to do create a new HTMLPanel like this:
runsPanel.add(new HTMLPanel("<div id=\"map\"></div>"));
Where runsPanel is a the panel I want to to be attached to.
Yet, it fails to retrive the div when I use the following initialization function:
private native JavaScriptObject initializeMap() /*-{
var latLng = new $wnd.google.maps.LatLng(31.974, 34.813); //around Rishon-LeTsiyon
var mapOptions = {
zoom : 14,
center : latLng,
mapTypeId : $wnd.google.maps.MapTypeId.ROADMAP
};
var mapDiv = $doc.getElementById('map');
if (mapDiv == null) {
alert("MapDiv is null!");
}
var map = new $wnd.google.maps.Map(mapDiv, mapOptions);
return map;
}-*/;
(It pops the alert - "MapDiv is null!")
Any ideas?
Thanks