This code make the map's div width max but height to 0 (the % value doesn't matter, it's always 0)
<div id="map" style="width: 100%; height: 100%;"></div>
This works, as it sets the map's div to a fixed size, but is obviously not what I want.
<div id="map" style="width: 100%; height: 500px;"></div>
Has someone experienced this? Anyone a suggestion on how to fix this?
I'm also using jquery(-mobile)
Thanks
This is my fix:
function fixContentHeight(){
var viewHeight = $(window).height();
var header = $("div[data-role='header']:visible:visible");
var navbar = $("div[data-role='navbar']:visible:visible");
var content = $("div[data-role='content']:visible:visible");
var contentHeight = viewHeight - header.outerHeight() - navbar.outerHeight();
content.height(contentHeight);
map.updateSize();
}
You need to give 100% height to HTML and Body:
html, body {
height: 100%;
}
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('<div>Handler for .resize() called.</div>');
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With