我想要可视化下面的GeoJSON对象,它被发送到我的Leaflet/JavaScript应用程序。我如何可视化所有的线串,显示每个线串的properties.name参数(例如,通过ToolTip)。
{“功能”:[{“类型”:“功能”,“属性”:{“名称”:“0”},“几何”:{“类型”:“LineString”,"coordinates":[10.941445541381836,52.438697814941406,10.941454124450684,52.4387092590332,10.941451263427734,52.43870544433594,10.941445541381836,52.438697814941406,10.941254806518555,52.440738677978516]}},{“类型”:“功能”,“属性”:{“名称”:“0”},“几何”:{“类型”:“LineString”,"coordinates":[10.941445541381836,52.438697814941406,10.941454124450684,52.4387092590332,10.941451263427734,52.43870544433594,10.941445541381836,52.438697814941406,10.941254806518555,52.440738677978516]}}}
任何帮助都是最好的!
谢谢
发布于 2017-08-21 16:31:38
您没有正确使用GeoJSON。如果您有多个要素,则应使用要素集合:https://geojson.org/geojson-spec.html
然后使用此网站具有正确的格式:https://jsonformatter.curiousconcept.com/
然后,如果您想要添加工具提示,请参阅本教程:http://leafletjs.com/examples/geojson/
var geojsonFeature = {
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"geometry":{
"type":"LineString",
"coordinates":[
[
10.941445541381836,
52.438697814941406
],
[
10.941454124450684,
52.4387092590332
],
[
10.941451263427734,
52.43870544433594
],
[
10.941445541381836,
52.438697814941406
],
[
10.941254806518555,
52.440738677978516
]
]
},
"properties":{
"name":"0"
}
},
{
"type":"Feature",
"geometry":{
"type":"LineString",
"coordinates":[
[
10.941445541381836,
52.438697814941406
],
[
10.941454124450684,
52.4387092590332
],
[
10.941451263427734,
52.43870544433594
],
[
10.941445541381836,
52.438697814941406
],
[
10.941254806518555,
52.440738677978516
]
]
},
"properties":{
"name":"0"
}
}
]
};
function onEachFeature(feature, layer) {
// This is where it loop through your features
if (feature.properties) {
// If there is a properties document we bind a tooltip with your property : name
layer.bindTooltip(feature.properties.name);
}
}
L.geoJSON(geojsonFeature, {
onEachFeature: onEachFeature
}).addTo(map);https://stackoverflow.com/questions/45759314
复制相似问题