Web AppBuilder 2.21 Developer Edition
I'm trying to refresh the labels for a specific layer in the layer list widget. The new labels are dependent of the map view and are recreated at every update-end event for the respective layer.
I can refresh the labels in the layer list widget using the _refresh() method but it collapses the legend for the layer. How can I expand the legend after the _refresh()?
Or, if anyone has a better solution, I'm all ears. Thanks.
Solved! Go to Solution.
Through some trialing I was able to come up with a solution. Not sure if this is best practice but it does seem to work.
function updateLayerListLegend(featureLayer){
//Using the Widget Manager get an instance of the Layer List widget
let wm = WidgetManager.getInstance(),
layerListWidget = wm.getWidgetsByName('LayerList')[0];
if(layerListWidget){
//Get the layer info for the layer who's legend is to be updated
let layerInfo = layerListWidget.operLayerInfos.getLayerInfoById(featureLayer.id)
//Use the redrawLegends method to update the legend. Parameter must be a layer info, not the feature layer.
layerListWidget.layerListView.redrawLegends(layerInfo)
}
}
I couldn't find any documentation on this, so be forewarned. It may not work in other versions.
Through some trialing I was able to come up with a solution. Not sure if this is best practice but it does seem to work.
function updateLayerListLegend(featureLayer){
//Using the Widget Manager get an instance of the Layer List widget
let wm = WidgetManager.getInstance(),
layerListWidget = wm.getWidgetsByName('LayerList')[0];
if(layerListWidget){
//Get the layer info for the layer who's legend is to be updated
let layerInfo = layerListWidget.operLayerInfos.getLayerInfoById(featureLayer.id)
//Use the redrawLegends method to update the legend. Parameter must be a layer info, not the feature layer.
layerListWidget.layerListView.redrawLegends(layerInfo)
}
}
I couldn't find any documentation on this, so be forewarned. It may not work in other versions.