简体   繁体   English

奇怪的Google地图大小调整行为

[英]Weird Google Map sizing behaviour

I've got a map in a GWT app up at http://corn.appspot.com - I want the map to cover 100% of the height and width of its container. 我在http://corn.appspot.com的GWT应用程序中有一张地图-我希望地图覆盖其容器的高度和宽度的100%。 I'm doing this by adding it into a layout panel and not assigning a size, like so: 我这样做是通过将其添加到布局面板中,而不是分配大小,如下所示:

public void loadMap() {
        LatLng cawkerCity = LatLng.newInstance(39.509, -98.434);
        MapOptions options = MapOptions.newInstance();
        MapWidget map = new MapWidget(cawkerCity, 2, options);
        map.setUIToDefault();
        map.addOverlay(new Marker(cawkerCity));
        mapHolder.add(map);
    }

The problem is that the map displays a small version in the area, then rights itself as soon as you try to change the size of the browser window in any way. 问题在于,地图在该区域中显示一个小版本,然后在您尝试以任何方式更改浏览器窗口的大小时立即对自身进行版权保护。 Take a look and see for yourselves. 看看 ,看看自己。

Does anyone have any idea why that would happen? 有谁知道为什么会这样?

It seems like your map is rendering if off center due to the size of the container changing. 由于容器大小的变化,如果地图偏离中心,似乎您的地图正在渲染。 Try a checkResize() 尝试一个checkResize()

http://code.google.com/apis/maps/documentation/reference.html#GMap2.checkResize http://code.google.com/apis/maps/documentation/reference.html#GMap2.checkResize

new Timer() {

@Override public void run() { @Override public void run(){
map.checkResizeAndCenter(); map.checkResizeAndCenter(); } }.schedule(100); }} .schedule(100);

this will help. 这会有所帮助。 regards 问候

Actually, its a lot easier to just do 其实,这样做更容易

DeferredCommand.addCommand(new Command(){
  @Override
  public void execute(){
    map.checkResizeAndCenter();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM