2015-02-17 51 views

回答

2

小葉具有一個L.GeoJSON層,你可以用它來在地圖上覆蓋GeoJSON的集合。您需要使用您所選擇的最喜歡的XHR/AJAX庫檢索對象加載您的JSON文件和實例化的GeoJSON的層:

// Fetch the geojson file 
$.getJSON('data.geo.json', function (data) { 
    // Define the geojson layer and add it to the map 
    L.geoJson(data).addTo(map); 
}); 

就這麼簡單。這裏有Plunker工作示例:http://plnkr.co/edit/0eP6zm?p=info

有上L.GeoJSON一個非常好的教程上的單張網站本身:http://leafletjs.com/examples/geojson.html和這裏的API參考:http://leafletjs.com/reference.html#geojson