FeatureLayer.applyEdits not affecting map

134
2
11-19-2019 01:31 PM
JordanWright
New Contributor

I am attempting to display a visualization of data in a FeatureLayer.  I am pulling in data from a Feature Service and, based on user input, I am attempting to edit the colors of the features.  When this feature stopped working, I tried to narrow it down as much as I could.  What I am left with is the following:

I have a Feature Layer that has a SimpleRenderer.  That renderer has a VisualVariable that includes the following ColorVariable:

var rendColorInfo = {
   type: "color",
   valueExpression: "$feature.COLOR_FIELD",
   minDataValue: -3.0,
   maxDataValue: 3.0,
      stops: getStops(-3.0, 3.0)
   };

renderer.visualVariables = [rendColorInfo];

This correctly displays a color for the default value of the feature.  After instantiating the MapView, Map, and FeatureLayer, I call the following code:

lyr.queryFeatures().then((featureSet) => {
   let q = featureSet.features;
    console.log(q[0]);
   q[0].attributes.COLOR_FIELD = -3;
   console.log(q[0]);
   lyr.applyEdits({ updateFeatures : [q[0]] }).then((result) => { console.log(result); });
});

Where lyr is the FeatureLayer.

As a proof of concept, I am only trying to update the value of the color field on one of the ~250 features in the map.  Logging out q[0] before I set the COLOR_FIELD attribute, the value in the log is 2, which is correct.  Logging after setting the attribute shows the value at -3.  The OBJECTID field is set and consistent before and after setting the attribute.  After passing these values to the applyEdits method, no change is observed in any of the features, and the logged result is 

{addFeatureResults: Array(0), updateFeatureResults: Array(0), deleteFeatureResults: Array(0)}

I cannot figure out what the problem is, as the edits are not being applied even after following all of the documentation to get to this point.  The source for the featureLayer is set via the URL attribute.  If anyone has encountered this issue and solved it, please let me know.

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

My guess would be that your changes are not being applied to the feature on the server. You should check if the server is returning an error for your applyEdits operation. Check if the FeatureEditResult contains any errors. You can also check your network request for applyEdits and see if the server is returning any messages. 

0 Kudos
JordanWright
New Contributor

Gotcha - I think you're right.  There are no errors in the response, so that further confirms your thought.  Is there any way to apply only a local change to the feature service without making an edit to the data set on the server?  i.e. I want to add a field to the features returned from the Feature Server, let's call it COLOR_VARIABLE, and manage it from my Javascript controller without committing those values to the server.

0 Kudos