I am working on a leaflet map which will allow a user to click on an area on the map and download respective river data based on the area of the click, however am struggling on the download functionality. I have included my current code and an image of the output of the code. How can I have the script download a file depending on which tile (see below image) the user clicks on? Ideally i'd like to use the download tag or have an on click JavaScript event so that each click of a tile downloads it's respective data.
<!DOCTYPE html>
<html>
<head>
<title>GRWL test</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<style>
#mapid {
height: 1920px;
width: 1080px;
}
</style>
<script src="leaflet-src.js"></script>
<script type="text/javascript" src="../dist/leaflet.ajax.js"></script>
<script src="spin.js"></script>
<script src="leaflet.spin.js"></script>
</head>
<body>
<div id="mapid"></div>
<script>
var map = L.map('mapid').setView([0.478320099108, -79.381377894799996], 14);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoiamltbXlzd2lzaGVyIiwiYSI6ImNqc29vYW02ejAxYjI0YW94NnBlcDhpYWEifQ.6DiOztwTzMJu3eBEyHHfrw'
}).addTo(map);
function popUp(f,l){
var out = [];
if (f.properties){
for(key in f.properties){
out.push(key+": "+f.properties[key]);
}
l.bindPopup(out.join("<br />"));
var anchor = document.createElement('a');
anchor.href = "C:\leaflet\leaflet-ajax-gh-pages\example\NA17.geojson";
anchor.target = '_blank';
anchor.download = "NA17.geojson";
anchor.click();
}
}
var jsonTest = new L.GeoJSON.AJAX(["tiles.geojson"],{onEachFeature:popUp}).addTo(map);
</script>
</body>
</html>
Output of the code, creates a grid system over the map: