我在使用 gwt GoogleMaps v3.8 时遇到问题
这段代码按预期工作得很好:
public class TestMaps implements EntryPoint {
public void onModuleLoad() {
final SimplePanel sp = new SimplePanel();
sp.setSize("460px", "320px");
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false&language=en");
Runnable callback = new Runnable() {
public void run() {
LatLng myLatLng = LatLng.create(51.5171, 0.1062);
MapOptions myOptions = MapOptions.create();
myOptions.setZoom(12.0);
myOptions.setCenter(myLatLng);
myOptions.setMapTypeId(MapTypeId.ROADMAP);
GoogleMap.create(sp.getElement(), myOptions);
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
RootPanel.get("GoogleMapsContainer").add(sp);
}
}
如果我将地图放在 TabPanel 中,我会得到灰色区域:
public class TestMaps implements EntryPoint {
private final native static void resizeMap(GoogleMap map) /*-{
$wnd.google.maps.event.trigger(map, 'resize');
}-*/;
public void onModuleLoad() {
final DecoratedTabPanel dtp = new DecoratedTabPanel();
final SimplePanel sp = new SimplePanel();
sp.setSize("460px", "320px");
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false&language=en");
Runnable callback = new Runnable() {
public void run() {
LatLng myLatLng = LatLng.create(51.5171, 0.1062);
MapOptions myOptions = MapOptions.create();
myOptions.setZoom(12.0);
myOptions.setCenter(myLatLng);
myOptions.setMapTypeId(MapTypeId.ROADMAP);
GoogleMap map = GoogleMap.create(sp.getElement(), myOptions);
dtp.add(sp, "Tab1", false);
resizeMap(map);
map.setZoom(map.getZoom());
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
RootPanel.get("GoogleMapsContainer").add(dtp);
}
}
我看到很少有关于类似问题的帖子,但没有一个建议对我有用。任何意见,建议表示赞赏。