在传单中显示 .json 文件 [英] displaying .json files in leaflet
问题描述
我有 5 个来自 http://websoilsurvey.sc.egov 的 .shp 文件.usda.gov/App/WebSoilSurvey.aspx我想将这些 .shp 文件叠加到传单中我现有的平铺照片上.
I have 5 .shp files from http://websoilsurvey.sc.egov.usda.gov/App/WebSoilSurvey.aspx I would like to overlay these .shp files onto my existing tile photos in leaflet.
我已经使用 ogr2ogr 将 5 个 .shp 文件转换为 .json,但我不知道如何将所有这些 .json 文件作为覆盖添加到我现有的平铺中.任何帮助将不胜感激,谢谢.
I have converted the 5 .shp files to .json using ogr2ogr, but I do not know how add all of these .json files as overlay to my existing tilings. Any help would be appreciated, thanks.
推荐答案
Leaflet 有一个 L.GeoJSON
层,您可以使用它在地图上覆盖 GeoJSON 集合.您需要使用您选择的最喜欢的 XHR/AJAX 库加载 JSON 文件,并使用检索到的对象实例化 GeoJSON 层:
Leaflet has a L.GeoJSON
layer which you can use to overlay GeoJSON collections on the map. You would need to load your JSON files using your favorite XHR/AJAX library of choice and instanciate the GeoJSON layer with the retrieved object:
// 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
It's as simple as that. Here's a working example on Plunker: http://plnkr.co/edit/0eP6zm?p=info
Leaflet 网站本身有一个关于 L.GeoJSON
的非常好的教程:http://leafletjs.com/examples/geojson.html 这里是 API 参考:http://leafletjs.com/reference.html#geojson
There is a very nice tutorial on L.GeoJSON
on the Leaflet site itself: http://leafletjs.com/examples/geojson.html and here is the API reference: http://leafletjs.com/reference.html#geojson
这篇关于在传单中显示 .json 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!