OpenLayers Google 地图调整大小问题

OpenLayers Google Map Resize Issue

我在我的项目中使用 OpenLayers,但我在调整大小方面遇到了问题。当我打开更大的地图 - 更大的 div- 地图时,地图不会造成问题,但是当我打开小地图 div 时,地图不会自行调整大小。

我已经尝试了一些方法来解决这个问题:


 window.onresize = function()
        {
          setTimeout( function() { map.updateSize();}, 200);
        }

$(window).trigger('resize');


  function resize() {
      var div = $('#map');
      div.height(
        Math.max( div.height() + ($(window).height() - $('body').height()), 300 )
      );
      map.updateSize();
    }

我也试过更新库文件。

http://trac.osgeo.org/openlayers/attachment/ticket/2828/openlayers-2828.patch

尝试使用这个算法:

function reduce() { 
var mapDiv = document.getElementById("map"); 
console.log("Current size: "+mapDiv.style.width+ " / "+mapDiv.style.height); 
mapDiv.style.width = mapDiv.clientWidth - 10 + "px"; 
mapDiv.style.height = mapDiv.clientHeight - 10 + "px"; 
console.log("New size: "+mapDiv.style.width+ " / "+mapDiv.style.height);