Hello -
Someone recently had the issue that when editing a FeatureLayer in my web app it wouldn't save. We found that when drawing a polygon if the lines cross (for instance, drawing a narrow polygon and the sides accidentally cross/touch), the shape deleted itself. The same goes for editing vertices -- if the user accidentally pulled a vertex such that the polygon sides crossed, the shape deleted itself.
I followed this sample relatively closely but in the sample, there is no issue! I somehow broke it.
In ArcMap, looking at the source dataset, the features drawn with crossed lines were listed in the attribute table with the Shape.STArea() and Shape.STLength() attributes as '0'.
My issue is this: in my own code no error was thrown. The applyEdits function runs successfully and creates the objectid. I don't use the TemplatePicker dijit. However I do use the Draw toolbar and take that graphic to applyEdits - I can see the graphic in the console.log just fine.
Any thoughts on where to start debugging my work?
function finishDraw(event, layer) {
console.log('finishDraw', event);
var newAttributes = templateFields(layer);
console.log(newAttributes);
var newGraphic = new Graphic(event.geometry, null, newAttributes);
var finishDeferred = layer.applyEdits([newGraphic], null, null);
return finishDeferred.promise;
}
function templateFields (layer) {
var fieldObj = {};
arrayUtils.forEach(layer.fields, function(atts) {
if (atts.name.search('OBJECTID') == -1) {
if (atts.name.search('Shape') == -1) {
fieldObj[atts.name] = null;
};
};
});
return fieldObj;
},
Solved! Go to Solution.
Sarah,
You should check if the polygon is self-intersecting using the "isselfintersecting" method of polygon.
Polygon | API Reference | ArcGIS API for JavaScript | isselfintersecting
and if it is then use the GeometryService Simplify:
GeometryService | API Reference | ArcGIS API for JavaScript | Simplify
Sarah,
You should check if the polygon is self-intersecting using the "isselfintersecting" method of polygon.
Polygon | API Reference | ArcGIS API for JavaScript | isselfintersecting
and if it is then use the GeometryService Simplify:
GeometryService | API Reference | ArcGIS API for JavaScript | Simplify
Thanks so much - I'll add that code in today
Robert, do you have any samples/template that utilizes this 'selfintersecting' method? I am trying to implement while editing the feature layer. Thanks.
Kushendra,
No. But it is a simple method you would call after drawing a polygon to know if you need to simplify the geometry:
var isIntersecting = polygon.isSelfIntersecting(polygon);