Select to view content in your preferred language

Issue with callbacks while uploading multiple graphics to "apply edits" inside of For Loop in JS API 3.23

391
1
04-17-2018 11:06 PM
AmrutaBildikar
Occasional Contributor

Hi All,

I have 2 feature layers added in my map:1 point layer(coming from Mapservice) and 1 polygon feature layer(Which is coming from feature service). I would like to upload the polygon geometries build up from Json to associated point feature. so Point ID will be stored in associated polygon geometries and it will get passed to apply edits call. I am following below mentioned steps:

1. build featureset from input JSON

2.Loop featureset ,Inside of "for loop", taking one feature at a time, checking if it's geometry is associated with point geometry which is selected on map(checking if point geometry is inside of polygon geometry)

3. if step 2 is successful, pass that feature to "apple edit" BUT Apply edit is async call and taking it's own time and loop is not getting executed for all the feature geometries

4. If I put break point at Callback function from "apply edit calls" is not working.

Relevant code:--------------

if (featureSet && featureSet.features && selectedResource) {
//To-do:check if resource point is inside of outline geometry

for (var i = 0; i < featureSet.features.length; i++) {
featureSet.features.attributes["additionalinformation"] = selectedResourceID;
var attribs = featureSet.features.attributes;

featureSet.features.spatialReference = featureSet.spatialReference;
boolContains = IfContains(featureSet.features, selectedResource)
if (boolContains) {
var wgs84 = new esri.geometry.Polygon(featureSet.features.geometry);
var graphic = new esri.Graphic(wgs84, symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([112, 112, 112]), 1), new Color([136, 136, 136, 0.25])), attribs);

if (graphic.geometry == null) {
console.log("Graphic geometry is null");
}
else {
}

//Apply Edit call
OutlineLayer.applyEdits([graphic], null, null).then(function (addResults, updateResults, deleteResults)
{ alert('Addsuccess', addResults); }).then(function (error)
{ console.log('error: '+ error); });
OutlineLayer.on("edits-complete", onComplete);
featureSet.features.clear();
}
else {
alert("Browsed Outline is not associated with the selected resource geometry");
}
}

}

---------------------------

in above code, I have formatted(Bold and Italic) the callback function with addResults, update and.. How to ensure in this function that loop is getting honored and one by one feature will get uploaded via apply edits?

 

I am working with ArcGIS JS API 3.23.

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

The way I've worked with applyEdits, I've used the callback and errback as parameters in the call itself.

Try something like

OutlineLayer.applyEdits([graphic], null, null,
  function (addResults, updateResults, deleteResults) {
     alert('Addsuccess', addResults); 
  },
  function (error) {
     console.log('error: '+ error); 
  }
);