简体   繁体   English

Leaflet.js映射移动高度问题

[英]Leaflet.js map on mobile height issues

I have a map I am trying to incorporate into a mobile web app. 我有一张地图正在尝试整合到移动网络应用中。 I am having issues with the height sizing of the map. 我在地图的高度调整方面遇到问题。 I am using this code at the moment and you can see it looks ugly since it doesn't come all the way down in the picture below: 我现在正在使用此代码,您可以看到它看起来很丑,因为它并没有完全出现在下图中:

<div id="map" style="height: 400px;"></div>

在此处输入图片说明

I also tried using the code: 我也尝试使用代码:

<div id="map" style="height: 100%;"></div>

But the map doe snot show up at all with that code, and there are no errors reported in chromes inspect element. 但是,使用该代码根本不会出现地图问题,并且chromes inspect元素中未报告任何错误。

You need to set up the height of map according to height of window after you initialize your map 初始化地图后,需要根据窗口高度设置地图的高度

$('#map').height($(window).height()+'px');

If you have header included in your window height like in the image you've attached, you need to exclude the height of that header while setting the height of map div. 如果您的窗口高度中包含标题,就像您所附加的图像一样,则在设置map div的高度时,需要排除该标题的高度。

For example, your header have 50px height, so set the height of map this way 例如,您的标题的高度为50px,因此可以这样设置地图的高度

$('#map').height($(window).height()-50+'px');

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

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