2017-03-16 142 views
0

與下面的教程沿着以下:http://leafletjs.com/examples/quick-start/單張地圖不顯示

我下載的CSS和JS的到本地目錄我是從工作,但我只顯示一個灰色背景。沒有地圖。我錯過了什麼?謝謝。

<!DOCTYPE html> 
<head> 
    <meta charset="utf-8" > 
    <title>Testing Leaflet</title> 
    <link rel="stylesheet" href="leaflet.css" /> 
    <style> 
     #mapid { height: 180px; } 
    </style> 
    <!--<script src="leaflet.js"></script> --> 
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> 
</head> 
<body> 
    <div id="mapid"></div> 
    <script> 
     var mymap = L.map('mapid').setView([51.505, -0.09], 13); 

     L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', { 
     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://mapbox.com">Mapbox</a>', 
     maxZoom: 18, 
     id: 'your.mapbox.project.id', 
     accessToken: 'your.mapbox.public.access.token' 
     }).addTo(mymap); 

     var marker = L.marker([51.5, -0.09]).addTo(mymap); 

     var circle = L.circle([51.508, -0.11], { 
     color: 'red', 
     fillColor: '#f03', 
     fillOpacity: 0.5, 
     radius: 500 
    }).addTo(mymap); 

     var polygon = L.polygon([ 
     [51.509, -0.08], 
     [51.503, -0.06], 
     [51.51, -0.047] 
     ]).addTo(mymap); 

    </script> 
</body> 
</html> 

這是所有顯示的內容。 enter image description here

回答

0

讓你成爲賬號Mapbox並設置your.mapbox.project.idyour.mapbox.public.access.token

+0

Mapbox是使用傳單的必要條件嗎? – martinbshp

+0

不,但你**有**有瓷磚供應商。看看這個:http://leaflet-extras.github.io/leaflet-providers/preview/。 – Shiva127

0
 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { 
         attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributor',  
         //other attributes. 
    }).addTo(mapname); 

我面臨同樣的問題,編輯/添加到您現有的代碼。您不需要設置任何帳戶。