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
Solved! Go to Solution.
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
I don't know how to fix that.