AnsweredAssumed Answered

JS Variable Text Output As Input Parameter For Geoprocessing Tool

Question asked by lloydbronn on Jan 12, 2017
Latest reply on Jan 17, 2017 by lloydbronn

I have a blank map document. When any point on the map is clicked, the xy coordinates are converted to lat/lon and displayed in a popup. This popup also has a link to a geoprocessing tool. Currently, this is just a ESRI sample GP tool that calculates the population within a 10km buffer around the point. I have created a script tool in ArcMap that runs a Python script that creates a chart in Excel from extracted raster values. I've successfully run this script in ArcMap and returned a chart.This will eventually be published on our server as a GP tool. The inputs for the Python script are latitude, longitude and location. At the moment I have these as user-entered parameters in the script tool. These parameters are used to write a text file that is passed in to the Python script. This may not be the most efficient way to go about this, but this is the way my companies scripts are written.  I want the input text file to be generated from the xy coordinates from the click event in the map. I've found a pretty helpful code snippet that does just that. The problem is, this text file is automatically downloads to the downloads folder on my local computer. Everything I've read suggests that it's impossible to specify a download directory because that opens our server to security risks. Is there any way around this with JS or HTML?

 

map.on("click",function saveTextAsFile(evt){
     
       var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
          var x = mp.x.toFixed(3);
          var y = mp.y.toFixed(3);
          var textToSave = x.toString() + "," + y.toString() + "," + "Location";
           var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
          var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
          var fileNameToSaveAs = "location.txt";

           var downloadLink = document.createElement("a");
            downloadLink.download = fileNameToSaveAs;
            downloadLink.innerHTML = "Download File";
            downloadLink.href = textToSaveAsURL;
            downloadLink.onclick = destroyClickedElement;
            downloadLink.style.display = "none";
            document.body.appendChild(downloadLink);

            downloadLink.click();
           
            });

Outcomes