AnsweredAssumed Answered

Get Area value and update before apply Edits in Edit Widget

Question asked by krishnavsav on Dec 4, 2017
Latest reply on Jan 5, 2018 by rscheitlin

Hello All,

 

I'm trying to update one attribute value using Polygon Area in Edit Widget. I'm using before-apply-edits event to do so. For calculating area of polygon I'm using geometry service. Please find the code below:

 

onBeforeApplyEdits: function (evt) {
          if (evt.adds != null) {
              var feat = evt.adds[0];
              var geometry = feat.geometry
              var geometryService = new GeometryService("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
              //geometryService.on("areas-and-lengths-complete", outputAreaAndLength);
              var areasAndLengthParams = new AreasAndLengthsParameters();
              areasAndLengthParams.areaUnit = GeometryService.UNIT_SQUARE_METERS;
              areasAndLengthParams.calculationType = "planar";

              geometryService.simplify([geometry], lang.hitch(this, function (simplifiedGeometries) {
                  areasAndLengthParams.polygons = simplifiedGeometries;
                  geometryService.areasAndLengths(areasAndLengthParams);
              }));

              geometryService.on("areas-and-lengths-complete", lang.hitch(this, function (evtObj) {
                  var result = evtObj.result;
                  console.log(result.areas[0]);
                 


                  var feat = evt.adds[0];
                  area = result.areas[0];
                
                  feat.attributes.no_of_areas = Math.round(area / 25);

                  setTimeout(lang.hitch(this, function () {
                      evt.target.applyEdits(null, [feat], null);
                  }), 100);

                  debugger;

              }));
          }
      },

 

Attributes are getting updated but unable to save. Please suggest how to proceed.

 

Regards,

Krish

Outcomes