【发布时间】:2015-05-06 05:57:20
【问题描述】:
我提出了一个关于引导传单地图未在移动设备上显示的问题How can I fix bootstrap leaflet map mobile display?
从那以后,我使用了一个简单的 mapbox 模板作为地图,并使用了此处所述的 invalidateSize() https://www.mapbox.com/help/why-map-cropped-hidden-shown/
但仍然无法将地图显示在手机上。
谁能帮助我正确实施 invalidateSize()?
谢谢 巴里
只有一个 div 元素:
<div id='map' class='blue'></div>
这是脚本:
<script>
L.mapbox.accessToken = 'mytoken';
var map = L.map('map').setView([10.5063,-61.4079], 10);
map.attributionControl.setPrefix('© <a href="http://www.url.com">Copyright 2015. hellO!</a>');
L.control.locate().addTo(map);
L.control.layers(
{'Streets': L.mapbox.tileLayer('url').addTo(map)},
{
'Drive Times': L.mapbox.tileLayer('url'),
'Outlets': L.mapbox.tileLayer('url')
}
).addTo(map);
//attempt to force resize on mobile devices
$('map').show();
map.invalidateSize();
这就是所有的css:
<style>
.menu-ui {background:#fff; position:absolute; bottom:10px;right:10px; left:10px; z-index:1; border-radius:3px; width:auto; height:inherit; border:1px solid rgba(0,0,0,0.4);}
.menu-ui a { font-size:11px; color:#404040; display: inline-block; margin:0;padding:0; padding:10px; text-decoration:none; border-right: 2pt inset; border-right-color:0.5px solid rgba(0,0,0,0.25); text-align: left;}
.menu-ui a:first-child { border-radius:3px 3px 0 0; }
.menu-ui a:last-child { border:none; border-radius:0 0 3px 3px; }
.menu-ui a:hover { background:#f8f8f8; color:#404040; }
.menu-ui a.active { background:#3887BE; color:#FFF; }
.menu-ui a.active:hover { background:#3074a4; }
.menu-ui a.inactive { background:#FFF; color:#3887BE; }
.leaflet-control-locate {border: 1px solid rgba(0,0,0,0.4);}
.leaflet-control-locate a {background-color: #fff;background-position: -3px, -2px;}
.leaflet-control-locate.active a {background-position: -33px -2px;}
.leaflet-popup-content { margin-top: 2px; margin-bottom: 2px; margin-left: 2px; margin-right: 2px;}
.leaflet-popup-content-wrapper {border-radius: 2px;}
.legend label, .legend span { display:block; float:left; height:15px; width:20%; text-align:center; font-size:9px; color:#808080;}
.leaflet-control-layers label { font-weight: normal; margin-bottom: 0px;}
.legend label, .legend span { display:block; float:left; height:15px; width:20%; text-align:center; font-size:9px; color:#808080;}
</style>
【问题讨论】:
标签: mobile maps leaflet mapbox window-resize