我在傳單中有一張地圖,使用下面的代碼,當頁面加載時,地圖沒有完全顯示,我不知道爲什麼,這怎麼解決?在傳單中加載地圖很慢
var Mmap = L.map('Modalmap').setView([8.7144, 125.7481],8);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright"></a>',
subdomains: ['a','b','c']
}).addTo(Mmap);
L.control.scale({imperial:false}).addTo(Mmap);
var north = L.control({position: "topleft"});
north.onAdd = function(map) {
var div = L.DomUtil.create("div", "info_legend leaflet-bar");
div.innerHTML = '<img src="../lib/css/images/north-arrow-2.png" width="100%" height="100%">';
return div;
}
north.addTo(Mmap);
var geocoder = L.Control.geocoder({
defaultMarkGeocode: false
})
.on('markgeocode', function(e) {
var box = e.geocode.center;
document.getElementById("Latitude").value = box.lat;
document.getElementById("Longitude").value = box.lng;
var MarkLayer=L.marker([box.lat,box.lng]).addTo(Mmap);
var group = new L.featureGroup([MarkLayer]);
Mmap.fitBounds(group.getBounds());
}).addTo(Mmap);
這張地圖是在我從一個導航欄
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav" style="margin-top: -3px;">
<li class="dropdown"><a href="#" data-toggle="modal" data-target="#modal-1">New Customer</a></li>
<li class="dropdown"><a href="#" data-toggle="modal" data-target="#modal-2">New Category</a></li>
</ul>
</div>
您是否在頁面中包含了傳單CSS? (它是一個常見的錯誤) – Sharky
@ Sharky..Yes我已經將它添加到主頁 –
請參閱https://stackoverflow.com/questions/36246815/data-toggle-tab-does-not-download-leaflet-map(類似於@ Sharky的下面的答案) – ghybs