Select to view content in your preferred language

Display Legend details for added layers using API

590
1
11-07-2011 10:16 PM
ankitabhatia1
Emerging Contributor
Is there a feature in API for displaying the legend details of the layers added to the map?I already tried the legend class, the problem I am facing is that the layer name is being displayed as GUID and not Layer name.
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
By default the legend control displays the layer ID as name.

So if you add layers to the map by code, the easiest way is to give a significant ID.

Else, if you have no way to change the ID, you can hook up an handler to the Legend.Refreshed event and change the label in this handler.
Something like:
private void MyLegend_Refreshed(object sender, Client.Toolkit.Legend.RefreshedEventArgs e)
{
var layerItem = e.LayerItem;
 
if (layerItem.Layer is ArcGISDynamicMapServiceLayer)
  layerItem.Label = ((ArcGISDynamicMapServiceLayer)layerItem.Layer).MapName;
else if (layerItem.Layer is .......
}
0 Kudos