我想要做的是讓用戶通過選擇Leaflet中的一些GeoJson功能來創建GPX文件 . 我這樣做的方法是創建一個新的GeoJson圖層來存儲所選的特征,然后用一個名為togpx(https://github.com/tyrasd/togpx)的插件將其轉換為gpx . 現在我有一個gpx文件,但我沒有't know how can I let the users download it. Any suggestions? Here'我的代碼:
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);