Select to view content in your preferred language

Updating feature attributes

399
1
Jump to solution
03-04-2023 04:38 PM
Aeseir
by
Frequent Contributor

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.

1 Solution

Accepted Solutions
Aeseir
by
Frequent Contributor

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
});
});
}
});

 

View solution in original post

0 Kudos
1 Reply
Aeseir
by
Frequent Contributor

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
});
});
}
});

 

0 Kudos