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("");
              //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.on("areas-and-lengths-complete", lang.hitch(this, function (evtObj) {
                  var result = evtObj.result;

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

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




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