AnsweredAssumed Answered

Update attribute value does not affect feature layer's graphic?

Question asked by beginor on Dec 27, 2018
Latest reply on Dec 28, 2018 by beginor

I have a FeatureLayer in a SceneView (with ArcGIS JS API 4.10), the layer is using a unique-value renderer, init code like this:

var map = new Map({
  layers: [
    new FeatureLayer({
      id: 'my_layer',
      url: 'url-to-map-server',
      renderer: {
        type: 'unique-value',
        field: 'level_name',
        defaultSymbol: { /* default symbol is point-ed */ },
        uniqueValueInfos: [
          { value: 'Ⅰ', symbol: { /* symbol for level Ⅰ */} },
          { value: 'Ⅱ', symbol: { /* symbol for level Ⅱ */ } },
          /* other unique infos. */
        ]
      }
    })
  ]
});

var view = new SceneView({
    map: map,
    container: 'my-map'
});

this code works. And I want to update the layer's visual by updating the attribute of the graphics in the layer, my code like this:

// first find the layer view
view.whenLayerView(view.map.findLayerById('my_layer'))
  .then(function (layerView) {
    // watch for updating
    layerView.watch('updating', function (val) {
      if (!val) {
        // find all graphics
        layerView.queryFeatures().then(function(fset) {
            // update all graphics features.
            for (var i =0; i < fset.features.length; i++) {
              var feature = fset.features[i];
              feature.setAttribute('level_name', 'Ⅰ');
            }
            // but the layer's viaual does not change, how to refersh
            // the layer manually?
          });
      }
    });
  });

my question is, how to refresh the layer with client side attribute changes?

Outcomes