User input type of polygon to geoprocessing via JS API 4.11

680
1
Jump to solution
06-30-2019 12:59 AM
SimonWebster
Occasional Contributor

I'm having some issues getting a geoprocessing task to run with a polygon entered by the user. 

The GP task works in ArcMap, and also from WebApp Builder - but in order for this to fit my wider workflow I would much rather do this with JS API 4.x. 

Currently, I'm receiving an Error 500: Error performing execution operation. It's an error in my code, though I'm not sure where I'm getting tripped up. 

The GP task expects a few input parameters, listed below. I'm only feeding it the first as I believe the last couple can be null (I hope). 

As a side note it would be lovely to see ESRI put up at least one example of accepting polygon input into a simple GP task. Almost every single example is done with an input of type point, and that makes it hard for those of us trying to learn since there's no mention of featuresets, etc. Only recently have I found an example with a polyline, but it was something different again. When there's 3 possible geometry types, and they each need to be treated differently, it would be nice to see an example of each, because at the moment there's only 1/3 of the examples. 

//Define the GP service location
var gpService = L.esri.GP.service({
url: "http://machine:6080/arcgis/rest/services/GPServices/TestPolygonGPService/GPServer/Test%20Polygon%20GP%20Service",
useCors:true
});


//Trigger when the create event is complete
map.on(L.Draw.Event.CREATED, function (event) {
    var layer = event.layer;

    var gpTask = gpService.createTask();
    gpTask.setParam("InputPolygonSymbology_lyr", layer.toGeoJSON());
    console.log(layer.toGeoJSON());
    console.log("setParameter of event.layer successful");
    gpTask.run(polyQueryCallback);
    console.log("successfully called and returned the callback");
    drawnItems.addLayer(layer);
});

function polyQueryCallback(error, response, raw){
    //map.addLayer(L.geoJSON(layer));
    //console.log(Polyarea);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Geoprocessing Task Looks Like:

Task: Test Polygon GP Service
Display Name: Test Polygon GP Service 

Description: This service is designed to test returning a single unique identifying parameter, together with comitting a polygon to an SDE database table whilst using in_memory workspaces. 

Category: 

Help URL: http://mi018461:6080/arcgis/rest/directories/arcgisoutput/GPServices/TestPolygonGPService_GPServer/GPServices_TestPolygonGPService/Model.htm 

Execution Type: esriExecutionTypeAsynchronous 

Parameters: 
Parameter: InputPolygonSymbology_lyr 
Data Type: GPFeatureRecordSetLayer 
Display Name InputPolygonSymbology.lyr 
Description: 50 percent opacity, and purple. 
Direction: esriGPParameterDirectionInput 
Default Value:
Geometry Type: esriGeometryPolygon 
HasZ: false 
HasM: false 
Spatial Reference: 102100  (3857) 

Fields:
objectid ( type: esriFieldTypeOID , alias: OBJECTID )
rand ( type: esriFieldTypeString , alias: rand , length: 50 )
shape_Length ( type: esriFieldTypeDouble , alias: shape_Length )
shape_Area ( type: esriFieldTypeDouble , alias: shape_Area )
Features: # records: 1

objectid: 1
rand: null
shape_Length: 8686075.788202167
shape_Area: 4.50582047673178E12
Polygon:
[-9999054.1244, 2095332.1645000018] , [-8234515.1612, 2524514.3561999984] , [-8203558.337300001, 139316.78449999914] more... 



Parameter Type: esriGPParameterTypeRequired 
Category: 

Parameter: RandVal 
Data Type: GPString 
Display Name RandVal 
Description: 
Direction: esriGPParameterDirectionOutput 
Default Value: 
Parameter Type: esriGPParameterTypeDerived 
Category: ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The console returns:

More console/network stuff, showing what parameters are currently being sent. 

0 Kudos
1 Solution

Accepted Solutions
SimonWebster
Occasional Contributor

This is an error because the JS code is expecting a synchronous service. Make sure the service is synchronous and the issue goes away. There is a note on one of the leaflet examples on how to work with Async. 

View solution in original post

0 Kudos
1 Reply
SimonWebster
Occasional Contributor

This is an error because the JS code is expecting a synchronous service. Make sure the service is synchronous and the issue goes away. There is a note on one of the leaflet examples on how to work with Async. 

0 Kudos