2015-04-03 35 views
0

我在我的項目中使用OpenLayers,但我有調整大小的問題。當我打開我的更大 - 這是更大的div-地圖,地圖不會導致問題,但是當我打開我的小地圖時,地圖不會自行調整大小。OpenLayers谷歌地圖調整大小問題

我已經試過幾件事情來解決這個問題:


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(); 
    } 

我甲肝e也試圖更新庫文件。

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

回答

0

嘗試使用這種算法:

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);