We have a service deployed at: http://www.agr.gc.ca/atlas/rest/services/mapservices/aafc_canada_land_parcels/MapServer. Using ESRI JSAPI 3.13 (but also seen in 3.9 so it's been like this for a while if not always), the Legend widget doesn`t appear to be handling this service properly.
The first image below shows how the service is defined. Note that the "Manitoba Township Fabric" is toggled ON and is within visible range given the map at right, but because its "Manitoba" parent group is toggled OFF, that feature class doesn't appear in the map…which is as expected. The second image shows what the map looks like when the "Manitoba" group is toggled ON and the "Manitoba Township Fabric" feature class is displayed in the map.
When the page is loaded in a browser it appears as you see below. The "Manitoba Township Fabric" (among others) appears in the Legend even though it is, correctly, not shown in the map. The Legend digit doesn't appear to be taking into consideration the fact that a group containing a "visibleLayer" may be toggled OFF and, therefore, not actually in the map and probably shouldn't be in the Legend either.
Can anyone tell me if this is by design? And, if so, what the logic behind showing these items in the Legend dijit is when, given the default visibility flag of their parent, there's no way they could actually appear in the map above?
I have worked around this problem in my own web mapping application by changing the visibleLayers array when the service is added to its map and removing those layers that have a parent that is toggled OFF somewhere up the chain but I thought I'd bring this up in case it is not "by design" and, instead, an oversight in the Legend dijit functionality.