简体   繁体   English

OpenLayers Google地图调整大小问题

[英]OpenLayers Google Map Resize Issue

I am using OpenLayers in my project , but i have a problem with resizing. 我在我的项目中使用OpenLayers,但是我在调​​整大小时遇到​​问题。 When i open my bigger -which is bigger div- map , map does not cause a problem, however when i open my map in small div, map does not resize itself. 当我打开更大的-div更大的map时,map不会出现问题,但是当我在小div中打开地图时,map不会自动调整大小。

I have tried couple things to solve this problem: 我已经尝试了几件事来解决这个问题:


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

I have also tried to update library file. 我也尝试更新库文件。

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

Try using this algorithm: 尝试使用以下算法:

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

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

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