Select to view content in your preferred language

Get Area value and update before apply Edits in Edit Widget

1286
11
Jump to solution
12-04-2017 09:03 PM
KrishV
by
Occasional Contributor III

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

Tags (1)
0 Kudos
11 Replies
KrishV
by
Occasional Contributor III

Hi Robert Scheitlin, GISP‌,

Thank you so much. This code works perfectly fine. Attributes are getting updated.

only problem is attributes are not getting updated immediately in attribute inspector. Is there anything which can be done to achieve this.

Regards,

Krish

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

I don't know how to fix that.

0 Kudos