I was looking around for a legend widget that only shows layers in the legend when the layer is visible and has data in the current extent. I also need to be able to reorder the legend without changing the drawing order in the web map. I was looking at the Legend Widget code and at LayerInfos. I don't know what the performance will be like, but I am getting ready to try using a query task to query the layers in the current extent to see which ones should be in the legend. As far as the layers go, I will try to change the order of the LayerInfos and see if that does it.
I just want to know if anyone has already done this or if they have recommendations on how to proceed. Otherwise, I will just start modifying and see how it goes.