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?
Zhang,
Are you only wanting to update the attribute for these feature on the client and not commit this change back to the server?
Yes, I just update the attribute on the client side. Do you have any ideas about 'refresh' the feature layer on the client?
Have you tried to call the refresh() method on the FeatureLayer?
https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#refresh
Yes, when call the `refresh` method of feature layer, it will reload data from server and repaint, and what I want is just repaint the layer at client side.
I would create a FeatureLayer from a graphics collection using a QueryTask to the MapService, that way you have the map service graphics but they are no longer attached to the map service and you can refresh without it getting the data again from the map service.
Hi there,
Robert Scheitlin, GISP is correct. You cannot do what you are trying to achieve with FeatureLayer. Instead please create FeatureCollection from the FeatureLayer. You can then update the attributes on the client.
I created a very simple test app to show one way how it can be done. In this case, I am creating a feature collection from a featurelayer. Then changing the attribute of the clicked feature using FeatureLayer.applyEdits() method.
OK, Thanks for your reply。 I will try to find another way to work out it。