diff --git a/js/gpx.js b/js/gpx.js index 886008d..c1cc593 100644 --- a/js/gpx.js +++ b/js/gpx.js @@ -4,6 +4,15 @@ attribution: 'Map data © OpenStreetMap' }).addTo(map); +function download(url) { + const a = document.createElement('a') + a.href = url + a.download = url.split('/').pop() + document.body.appendChild(a) + a.click() + document.body.removeChild(a) +} + function addGPX(map, gpx, lineColor) { new L.GPX(gpx, { async: true, @@ -20,6 +29,18 @@ } }).on('loaded', function(e) { map.fitBounds(e.target.getBounds()); + }).on('mouseover', function(e) { + var paths = gpx.split("/") + this.bindTooltip( + "Click to download: " + paths[paths.length - 1], + { sticky: true } + ) + this.openPopup(e.latlng); + }).on('mouseout', function(e) { + setTimeout(this.closePopup(), 500); + }).on('click', function(e) { + setTimeout(this.closePopup(), 500); + download(gpx); }).addTo(map); }