Is there any way to edit attributes on the client side of a hosted feature layer in the JS API 4.15

1042
4
05-28-2020 12:31 AM
GuusPutten
New Contributor

I have made an app where a certain score is given to an area based on parameters. And to give the score to that area a calculation is made and the score has to written into the attribute table of the layer. That way i can edit the symbology of the area based on that score in the attribute table. But all of the ways to edit in the layer seem to update the layer itself. I want to do the edits in the client itself. Therefore no changes are made in the layer and when the page is reloaded the layer is reset. Is there a way to accomplish this?

Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Guus,

   Is it a vary large dataset? If it is not to large then you can create a client side feature layer using a a graphics source. Just use a queryTask to get the layers graphics.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#client-s... 

This way it is an isolated client side copy of your layer.

0 Kudos
GuusPutten
New Contributor

Hi Robert,

Thank you for your response, it is not a big dataset. It's only all the neighborhoods of a municipality. Around 100 features. I'm going to try your idea, thank you. 

0 Kudos
GuusPutten
New Contributor

Hi Robert, it worked perfectly thank you very much. I am now struggling to edit the attribute table of the new layer. When I try to use the applyEdit() method I keep getting the error that the objectID identifier field is missing. But I transferred it to the new layer.

Here is some code, if you can take a look at it that would be amazing:

"p" is  an integer that represents a objectid

"Score" is the field of "p" which i'm trying to edit

Thanks in advance

sectorenLayer.applyEdits({
                    updateFeatures: [{
                        attributes: {ObjectID: p, Score: endScore}
                    }]
                }).then(function(response){
                    console.log(response)
                })
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Guus,

   Normally you would get the feature (graphic) and update the attribute of Score and add that whole graphic to an array to pass to the updateFeatures method. They way you are attempting will not work (passing a simple object that has an attribute property).

0 Kudos