在传单中显示.json文件 [英] displaying .json files in leaflet
问题描述
我有5个.shp文件来自 http://websoilsurvey.sc.egov .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.
推荐答案
传单具有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屋!