I am working with the ArcGIS JavaScript API in Experience Builder. I am having an issue with my Feature Layer not "refreshing" or more appropriately described as "Redrawing" on the map.
I have a custom widget that makes changes to data on the backend through a custom API. The data edits eventually end up (through multiple backend databases) in the DB view that feeds the Feature Layer. To see the changes on the map, I have the refresh rate on the layer in the map set to 6 seconds, and this works ok. The data refreshes as well as the data being redrawn (symbols are dependent on changing attributes). I wish I could redraw the layer programmatically so it's not constantly refreshing, but I could never make it work.
I am now trying to change the label colors based on the selected basemap and have run into the same issue. The LabelClass is changing but the Layer Labels are not redrawing on the map.
I must be missing something. Destroying the layer and re-adding it to the map is not an option.
const layerDataSource = DataSourceManager.getInstance().getDataSource(props.config.useWorkOrderDataSources[0].dataSourceId) as FeatureLayerDataSource)
const labelInfo = layerDataSource.layer.labelingInfo[0];
labelInfo.symbol.color = new Color([0, 255, 0]);
layerDataSource.layer.labelingInfo = [labelInfo];
The above code is in the callback of the map basemap property watcher.
Although I don't think labelingInfo is one of them, I've run into various situations using the API where an "outer" object (in this case, the layer) doesn't notice a change to an "inner" object's properties when reusing the same object. I suppose it's a little difficult to explain. If that's the kind of thing going on though, you may be able to get around it by using clone:
layerDataSource.layer.labelingInfo = [labelInfo.clone()];