我在Leaflet.js网络地图中创建了一个选项,可将单击的行导出为GPX,但仅导出最后单击的行。我需要将所有单击/突出显示/选定的行导出到一个GPX文件中。
这是我的代码:
$.getJSON('data/routes/Download/Nwn.geojson', function (collection) {
Nwn = L.geoJson(collection, {
'style': function () {
return {
'color': '#FFFF00',
'weight': 3,
'opacity': 0
}
}, onEachFeature: function(feature, layer) {
layer.on('click', function() {
document.getElementById('exportHiking').onclick = function() {
var toJson = layer.toGeoJSON();
var dGpx = togpx(toJson);
document.getElementById('exportHiking').setAttribute('href', 'data:text/json;charset=utf-8,' + dGpx);
document.getElementById('exportHiking').setAttribute('download','route.gpx');
};
})
var timesClicked = 0;
layer.on('click', function() {
Nwn.resetStyle(layer);
layer.setStyle({color: '#FFFF00', opacity: 1});
timesClicked++;
if(timesClicked>1) {
Nwn.resetStyle(layer);
timesClicked = 0;
}
});
// Nwn.resetStyle(layer);
},
distanceMarkers: { showAll: 11, offset: 1000000, cssClass: 'some-other-class', iconSize: [16, 16] }
}).addTo(NwnGroupe);
map.addLayer(NwnGroupe);
});
怎么办?