2012-12-12 46 views
6

我正在爲傳單做快速入門教程,我一直收到一張空白地圖。我正在使用JavaScript來初始化地圖,但即使我認爲所有的編寫代碼仍然沒有看到地圖。請幫助,我的代碼如下:傳單空白地圖

<!DOCTYPE HTML> 



<div id="map"> 
    <script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.4/leaflet.js"></script> 
    <script type="text/javascript"> 
    var map = L.map('map').setView([28.23211669921875, -26.050065042385917], 10); 
    L.tileLayer('http://b.tilecloudmade.com/e7b61e61295a44a5b319ca0bd3150890/997/256/18/149531/108306.png', { 
     attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>', 
     maxZoom: 18 
     }).addTo(map); 
    </script> 
    </div> 
    </div> 

回答

5

您對瓦片地圖的引用看起來不對,下面的代碼給出了瓦片。

<!DOCTYPE HTML> 


<div id="map"/> 
<script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.4/leaflet.js"></script> 
<script type="text/javascript"> 
var map = L.map('map').setView([28.23211669921875, -26.050065042385917], 10); 
//L.tileLayer('http://b.tilecloudmade.com/e7b61e61295a44a5b319ca0bd3150890/997/256/18/149531/108306.png', { 
L.tileLayer('http://{s}.tile.cloudmade.com/e7b61e61295a44a5b319ca0bd3150890/997/256/{z}/{x}/{y}.png', { 
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>', 
    maxZoom: 18 
}).addTo(map); 
</script> 
+1

感謝您的建議。它效果更好。 – Siya