Hello all,
I've implemented the following code using a before-apply-edits on a layer, however I get an error when I try to apply those changes I made using a geometry service. The server does send an error 17000 on the Method "GraphicFeatureServer.HandleREST_ApplyEditsOperation". Any help is much appreciated. This is a head scratcher for me.
forage.on("before-apply-edits", function (evt) {
if (evt.adds != null){
console.log("QueryRunning");
var query = new Query();
query.outSpatialReference = map.spatialReference;
query.geometry = evt.adds[0].geometry;
query.spatialRelationship = Query.SPATIAL_INTERSECTS;
var feat = evt.adds[0];
property.queryFeatures(query, function(featureSet) {
if (featureSet.features.length == 0) {
}
else {
console.log("pboundary detected");
console.log(evt.adds[0]);
var intersectGeometry = feat.geometry;
var queryGeometry = featureSet.features[0].geometry;
var newGeom = geometryEngine.intersect(intersectGeometry, queryGeometry);
feat.setGeometry(newGeom);
console.log(feat.geometry);
forage.applyEdits(null, [feat], null);
}
});
}
});
Solved! Go to Solution.
Mikael,
I am not sure what you are trying to achieve, but from the code I understand, you are get the add graphics and then based on query, you are changing the geometry of the graphic and trying to update it. Is that correct?
If it is, the main issue, using the "before-apply-edit" is that, the graphic which was passed to adds would not contain the unique ObjectID when it was inserted into the database. so the required value to identify the feature to update is missing.
You may want to do the above action once the updates are completed. i.e. use, "edits-complete" event instead where you will get the features with unique object id assigned to the feature.
Hope this was helpful.
Mikael,
I am not sure what you are trying to achieve, but from the code I understand, you are get the add graphics and then based on query, you are changing the geometry of the graphic and trying to update it. Is that correct?
If it is, the main issue, using the "before-apply-edit" is that, the graphic which was passed to adds would not contain the unique ObjectID when it was inserted into the database. so the required value to identify the feature to update is missing.
You may want to do the above action once the updates are completed. i.e. use, "edits-complete" event instead where you will get the features with unique object id assigned to the feature.
Hope this was helpful.
Thanks thejus. I'm working to try this now. I'll respond as soon as I have more.
Enjoy the day,
Mike
Thanks Thejus,
What we did here was make an editing tool that honors topology between two layers using the geometry engine. Attached is a snip from the code that is fired using the on "edits-complete" method.
Thanks for the help.
Enjoy the day,
Mike
function forageGo(evt) {
console.log(evt);
var union;
var query = new Query();
query.outSpatialReference = map.spatialReference;
//query.num = 1;
if (evt.adds.length == 0) {
return;
}
var objID = evt.adds[0].objectId;
query.objectIds = [objID];
//query.spatialRelationship = Query.SPATIAL_INTERSECTS;
var polyGreen;
var polyGreenAttr;
var geoms = [];
//var polyunion;
ForageDelineationInput.queryFeatures(query, function(featureSet2) {
if (featureSet2.features.length == 0) {
return;
}
polyGreen = featureSet2.features[0].geometry;
polyGreenAttr = featureSet2.features[0].attributes;
});
var query1 = new Query();
query1.outSpatialReference = map.spatialReference;
query1.num = 1;
query1.geometry = polyGreen;
query1.spatialRelationship = Query.SPATIAL_INTERSECTS;
// query PropertyBoundaryInput to get the geometry
PropertyBoundaryInput.queryFeatures(query1, function(featureSet) {
if (featureSet.features.length == 0) {
//alert("No Results found");
}
else {
for (var i = 0; i < featureSet.features.length; i++) {
var graphic = new Graphic();
var features = [];
console.log(polyGreen);
console.log(ForageDelineationInput.getSelectedFeatures);
var graphic = ForageDelineationInput.getSelectedFeatures()[0].setGeometry(geometryEngine.difference(polyGreen, featureSet.features[0].geometry));
graphic = ForageDelineationInput.getSelectedFeatures()[0].setGeometry(geometryEngine.intersect(query1.geometry, featureSet.features[0].geometry));
//property.applyEdits([evt.adds[0]], null, [evt.adds[0]]);
ForageDelineationInput.applyEdits(null, [graphic], null);
var query2 = new Query();
query2.outSpatialReference = map.spatialReference;
//query2.num = 1;
query2.geometry = graphic.geometry;
query2.spatialRelationship = Query.SPATIAL_INTERSECTS;
query2.where = "OBJECTID_1 <>" + objID;
ForageDelineationInput.queryFeatures(query2, function(featureSet2) {
if (featureSet2.features.length == 0) {
//alert("No Results found");
}
else {
for (var i = 0; i < featureSet2.features.length; i++) {
/*console.log(featureSet2.features.length);
//var features = [];
graphic1 = ForageDelineationInput.getSelectedFeatures()[0].setGeometry(geometryEngine.difference(ForageDelineationInput.getSelectedFeatures()[0].geometry, featureSet2.features[0].geometry));*/
var fFeature = featureSet2.features;
geoms.push(fFeature.geometry);
console.log(geoms);
}
union = geometryEngine.union(geoms);
console.log(union.toJson());
var graphic1 = new Graphic();
graphic1 = ForageDelineationInput.getSelectedFeatures()[0].setGeometry(geometryEngine.difference(ForageDelineationInput.getSelectedFeatures()[0].geometry, union));
console.log(graphic1);
ForageDelineationInput.applyEdits(null, [graphic1], null);
}
});
}
}
});
}