I am trying to figure out how I can update a feature's attributes during edit event.
here is the code so far:
// layer is of type FeatureLayer
layer.on("edits", (e) => {
const emptyFeature = e.edits?.addFeatures?.filter((e: any) => e.attributes.weight === null);
if(emptyFeature?.length) {
// features without weight attribute
// default weight is 1000
emptyFeature.forEach((e) => {
//update feature's weight attribute to 1000
}
);
}
}
);
I am struggling to find the right combination to update these empty features any advice is appreciated.
Solved! Go to Solution.
Ahh figured it out, I had a silly typo in code, for those interested do this:
layer.on("edits", (e) => {
const emptyFeature = e.edits?.addFeatures?.filter((e: any) => e.attributes.weight === null);
if(emptyFeature?.length) {
// features without weight attribute
// default weight is 1000
emptyFeature.forEach((e) => {
//update feature's weight attribute to 1000
e.attributes.weight = 1000;
layer.applyEdits({updateFeatures: [e]}).then((e) =>{
// do something with success result
}).catch((err) => {
// do something with err result
});
});
}
});
Ahh figured it out, I had a silly typo in code, for those interested do this:
layer.on("edits", (e) => {
const emptyFeature = e.edits?.addFeatures?.filter((e: any) => e.attributes.weight === null);
if(emptyFeature?.length) {
// features without weight attribute
// default weight is 1000
emptyFeature.forEach((e) => {
//update feature's weight attribute to 1000
e.attributes.weight = 1000;
layer.applyEdits({updateFeatures: [e]}).then((e) =>{
// do something with success result
}).catch((err) => {
// do something with err result
});
});
}
});