Hello all, I am wondering if it's possible to update UniqueValueRenderer after it has been initialized with symbols and their corresponding fieldNames. My application creates a GeoJSONLayer, which is assigned a UniqueValueRenderer that contains all the symbol information for the displayed geoFeatures. However, I'd like to update some of the symbols for the rendered geoFeatures if a user hovers over it or selects it.
The only case where I have been able to update a symbol within the geojson layer is when the UniqueValueRenderer already contains the fieldName, symbol pair. Is it possible to add a new symbol to the UniqueValueRenderer and refresh it so that a specific geoFeature's symbol gets updated? I've tried reassigning the renderer property of GeoJSONLayer after modifying the UVR, but the symbol that's supposed to change style just disappears.
private updateFeatures(results, layer: GeoJSONLayer)
{
if (results.length > 0)
{
const updatedGraphics = {
updateFeatures: []
}
results.forEach((feature) => {
feature.attributes[UNIQUE_VALUE_RENDERER_FIELD] = "drawing"; // set new style
updatedGraphics.updateFeatures.push(feature); // update geojson feature
})
let symbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "square",
color: "blue",
size: "8px", // pixels
outline: { // autocasts as new SimpleLineSymbol()
color: [ 255, 255, 0 ],
width: 3 // points
}
};
const renderer = layer.renderer as UniqueValueRenderer;
renderer.addUniqueValueInfo("drawing", symbol); // assign new symbol to new style
if (updatedGraphics.updateFeatures.length > 0){
this.applyEditsToGeoJSON(updatedGraphics, layer); // apply changes to feature
}
}
}
private applyEditsToGeoJSON(params, layer: GeoJSONLayer)
{
layer.applyEdits(params)
.then((result) => {
result.updateFeatureResults.forEach((updatedFeature) => {
console.log('feature with id ' + updatedFeature.objectId + ' updated');
})
})
}