Survey123 JavaScript Spatial Overlap with Complex Polygon Geometry

222
1
12-15-2020 09:31 AM
IzzyMcLees
New Contributor II

Hi,

I am trying to integrate some JavaScript functionality into my Survey123 form whereby, a user will be nofified whether the polygon they've drawn, overlaps with an existing polyon.

I have managed to achieve this for polygons with straight edges, however when I draw polygons as circles or by freehand, it returns the error "404 page not found".

I believe this is because polygons with curved edges can have an incredibly lengthy geometry string which is too long for the query URL and is constrained by the GET request that I am currently using. I know a way to solve this is to change the GET request to a POST request, as this is not constraint by querystring length but I am unsure of how to do this?

My question is, how can I write a POST request to perform the same spatial query as below that will work for more complex geometry?

I have inserted my code below:

// Convert javaScipt object to a JSON string
var geoString = JSON.stringify(geoObject);
// return geoString;

// Change the parameters in the query URL to work with different geometryType, spatialRel, etc.
// Ref: https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm
var url = featurelayer_url+"/query?where=1%3D1&geometry="+geoString+"&geometryType=esriGeometryPolygon&spatialRel=esriSpatialRelOverlaps&units=esriSRUnit_Meter&returnCountOnly=true&f=json";

if (token) {
url = url+"&token="+token;
}

// return url;

// create a new XMLHttpRequest object to request data from the server. Then define the type of request
// method (GET or POST), the file location (url) and async (true (asynchronous) or false (synchronous))
// send() sends a request to the server (used for GET).
var xhttp = new XMLHttpRequest();
xhttp.open("GET", url, false);
xhttp.send();

 

1 Reply
IsmaelChivite
Esri Frequent Contributor

 

var xhttp = new XMLHttpRequest();
xhttp.open('POST', 'yourURL', false);
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send('token=<yourtoken>&param1=XYZ');
0 Kudos