AnsweredAssumed Answered

Projecting multiple points inside for loop

Question asked by siva.lntgis on Oct 5, 2017
Latest reply on Oct 5, 2017 by rscheitlin

Hello,

 

Here i'm facing some issue in projecting points inside a for loop

please refer the code below,

 

var jsonFS = new Object();
jsonFS.geometryType = "esriGeometryPoint";
var features = [];
var taskQuery = [];
var pts = [];
gsvc = new esri.tasks.GeometryService("https://<your Domain>/webgis/rest/services/Utilities/Geometry/GeometryServer/");
for (i = 0; i < 100 i++)
{
var attributeObj = new Object();
attributeObj.objectid = i;
attributeObj.latitude = response.EntityData[i].lat;
attributeObj.longitude = response.EntityData[i].lon;
attributeObj.pop = response.EntityData[i].pop;

pt = new Point(response.EntityData[i].lon,response.EntityData[i].lat,new SpatialReference(4326));
var outSR = new SpatialReference(this.map.spatialReference);
var prjParams = new esri.tasks.ProjectParameters();
prjParams.geometries = [pt];
prjParams.outSR = outSR;
gsvc.project(prjParams,function(projectedPoints) {
ptnew = projectedPoints[0];
});

this.feature = new Object();
this.feature.attributes = attributeObj;
this.feature.geometry = ptnew;
this.features.push(feature);
}

 

here when the execution reaches "gsvc.project" , the execution was skipped and remaining codes are executed.

after completing the entire for loop the "gsvc.project" is executing asynchronously for the loop cont(100).

 

Can anyone help me to execute this projection inside a for loop in a sequential manner.

 

Thanks & Regards

Siva

Outcomes