geoprocessing service no response with Leaflet

2464
12
12-01-2018 09:32 AM
GrantHaynes
Occasional Contributor

Hi all,

 

I'm using leaflet to create a time series web map where a user can place a point on a map and the values at that lat and long will be graphed on the web page. I have a geoprocessing service that runs fine, I've tested it in arcmap and it works great it accepts lats and longs and spits out the extracted data values. I also have a web page that allows a user to create points and produces lats and longs to be passed back to the geoprocessing service. However I cannot get the two to talk to each other, can anyone here tell me what is wrong?

 
<!-- Map processes here -->
<div id = "map">
<script type='text/javascript'>
var map = L.map('map').setView([0, 0], 2);

L.esri.basemapLayer('Gray').addTo(map);

map.on('click', addMarker);

var MarkerLayer = new L.FeatureGroup();
map.addLayer(MarkerLayer);

var Coordinates = [];
function addMarker(e){
Marker = new L.marker(e.latlng).addTo(MarkerLayer);
Coordinates.push(e.latlng);
}

function ClearMarker(){
MarkerLayer.clearLayers();
Coordinates = [];
}

 
function Geoprocessing(){
// Go through coordinates generated from leaflet and split them
// up to be passed to the geoprocessing service
Coordinates.forEach(function(item){
var Results = [];
var StrItem = String(item);
var StrParts = StrItem.split(",");
var Lat = StrParts[0].slice(7);
var Long = StrParts[1].substring(0, StrParts[1].length - 1);

//execute geoprocessing service each time a lat and long are generated
var gpService = L.esri.GP.service({
useCors:false
});
var gpTask = gpService.createTask();
gpTask.setParam("InputX", Long);
gpTask.setParam("InputY", Lat);
gpTask.run(DataCallBack);
})

// Handle server response
function DataCallBack(error, raw, response)
{
window.alert(error.message);
}
}
</script>
0 Kudos
12 Replies
GrantHaynes
Occasional Contributor

Thanks, I fixed the URL and I'm getting a response from the service. Do you know how synchronous geoprocessing services return non layer results? Is it dictated by the output data type of the published geoprocessing task? 

0 Kudos
JohnGravois
Frequent Contributor

yup. you can configure GP services to output all sorts of different results.

0 Kudos
GrantHaynes
Occasional Contributor

That's what I thought, this service as it stands returns a text file, I want the values in the text file for graphing in the web browser. I'm pretty sure I need to change the script and republish the service with a result data type that is more suitable, but is there a way to achieve that with the existing service? 

0 Kudos