【发布时间】:2015-03-27 13:55:48
【问题描述】:
我想做的是让用户通过在 Leaflet 中选择一些 GeoJson 功能来创建 GPX 文件。我这样做的方式是创建一个新的 GeoJson 层来存储选定的特征,然后使用名为 togpx (https://github.com/tyrasd/togpx) 的插件将其转换为 gpx。现在我有一个gpx文件,但我不知道如何让用户下载它。有什么建议?这是我的代码:
var GPXfile;
var trails = new L.GeoJSON.AJAX('data/trasee.geojson', {
onEachFeature: function(feature, layer) {
layer.on({
click: function () {
var selectedGeojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Rocka Rolla"
},
"geometry": {
"type": "LineString",
"coordinates": feature.geometry.coordinates
}
}]
}
GPXfile = togpx(selectedGeojson);
}
})
}
}).addTo(map);
JsFiddle 可能会有所帮助:http://jsfiddle.net/pufanalexandru/20ara4qe/1/
【问题讨论】:
标签: export leaflet geojson gpx