![](/img/trans.png)
[英]Display Marker Using Latitude And Longitude From SQL Database With Leaflet Map In ASP.NET CORE MVC
[英]Read Latitude and Longitude from a GeoJSON file, and then display each lat-long as a marker with Leaflet
我是Java的新手,因此我有點迷路了。 我可以從GeoJSON文件讀取; 但是,我不明白如何遍歷文件以獲取點的緯度,然后在傳單中將這些點顯示為標記。 我希望也使用插件Awesome Markers(基於Leafa的font-awesome)
這是我的GeoJSON文件的示例:
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "Street Nam": "Aljunied Avenue 2", " Block": "118 Aljunied Avenue 2", " Postal Co": "380118", " Latitude": 1.320440, "Longitude": 103.887575 },
"geometry": { "type": "Point", "coordinates": [ 103.887575, 1.320440 ] } }
,
{ "type": "Feature", "properties": { "Street Nam": "Aljunied Crescent", " Block": "97A Aljunied Crescent", " Postal Co": "381097", " Latitude": 1.321107, "Longitude": 103.886127 },
"geometry": { "type": "Point", "coordinates": [ 103.886127, 1.321107 ] } }
]
}
謝謝您的關注和時間=)
按照傳單文檔中的描述處理geojson。 指定一個pointToLayer函數,該函數將創建帶有超贊圖標的標記:
L.geoJson(geoJson, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng,
{icon: L.AwesomeMarkers.icon(
<< options based on feature.properties >>
)});
}
}).addTo(map);
讀取文件后,您應該有一個javascript對象,該對象代表文件中的所有數據:
var geoData = JSON.parse(fileContents);
var features = geoData.features;
等等。 解析的數據將轉換為對象或數組,具體取決於它們是鍵/值字典還是列表。 所以從上面
var feature = geoData.features[0];
將為您提供對列表中第一個要素對象的引用。 如果你寫
console.log(geoData);
並在任何最新的瀏覽器上運行,您都應該能夠看到數據的擴展說明,以幫助理解所有內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.