开发者

Error in GWT MapWidget

I am trying to add MapWidget to VerticalPanel but the map added on the left corner:

Error in GWT MapWidget

And I added marker and the marker should be centered on the image I can't see the marker when I load the map. I should navigate to this location to show map.

The code for this

private FormPanel form = new FormPanel();

private VerticalPanel main = new VerticalPanel();



public Map(){

  ScrollPanel container = new ScrollPanel();

  initWidget(container);

  container.setStyleName("FuoEgForm");

  form.setWidget(main);

  main.setSpacing(6);

  container.add(main);
}

public MapWidget addMapWidget(){

  MapWidget map = new MapWidget();

  //map.setSize("100%", "100%");
开发者_开发知识库  map.setStyleName("gwt-map");
  map.removeMapType(MapType.getNormalMap());
  map.removeMapType(MapType.getSatelliteMap());
  map.addMapType(MapType.getPhysicalMap());
  map.addMapType(MapType.getHybridMap());
  map.setCurrentMapType(MapType.getHybridMap());

  //map.setSize("100%", "100%");
  map.setWidth("500px");
  map.setHeight("500px");
  main.add(map);

}

How can I solve this issue? The map should fill the gray boundary?


As of gwt-maps-1.1, the MapWidget implements the RequiresResize interface. When added to a panel that supports this interface (such as DockLayoutPanel), the widget automatically calls map.checkResizeAndCenter() whenever the panel containing the widget is resized. This new feature makes it possible to set your map size to 100% in both directions and fill up the available space on the screen. To use LayoutPanel subclasses properly, make sure your html page is set to use standards mode by adding as the first line in the document.

In gwt-maps 1.0, it may be necessary to force the map to resize its layout after the map is initially added. you can use the MapWidget.checkResizeAndCenter() method to clean this up. You may need to delay calling this function using a DeferredCommand or other mechanism to wait until after the DOM layout pass that resizes the map is called.

or you can find unexpected another unexpected reason that happened with me

i made the map invisible @constructor and then set it visible if clicked on a button

the solution make the map always visible :)


I insert these line below the add(map) :

LatLng c = mapWidget.getCenter();
resizeMap(mapWidget.getMVCObject());
mapWidget.setCenter(c);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜