Cannot set map's div height for openlayers map

前端 未结 5 1429
予麋鹿
予麋鹿 2021-01-05 23:25

This code make the map\'s div width max but height to 0 (the % value doesn\'t matter, it\'s always 0)

5条回答
  •  梦谈多话
    2021-01-06 00:09

    in case you use jquery, this works perfectly to 'stretch' your map to the container div holding it, notmatter what your css has set for the map :

       $(window).resize(function () {
          //$('#log').append('
    Handler for .resize() called.
    '); var canvasheight=$('#map').parent().css('height'); var canvaswidth=$('#map').parent().css('width'); $('#map').css("height", canvasheight); $('#map').css("width", canvaswidth); });

    You would call this early btw, ideally in a $(document).ready(function(){ /* here */ } block.

提交回复
热议问题