Hi Gordon,
You can add the legend items based on your "layercode" when the map initializes in your controller side. Some codes is like the below:
AddLegend(map,values);
return View(map);
}
private void AddLegend(Map map,List<string> values)
{
// Add Legend adorment overlay
LegendAdornmentLayer legendAdornmentLayer = new LegendAdornmentLayer();
legendAdornmentLayer.Location = AdornmentLocation.LowerLeft;
legendAdornmentLayer.XOffsetInPixel = 10;
legendAdornmentLayer.Title = new LegendItem();
legendAdornmentLayer.Title.ImageJustificationMode = LegendImageJustificationMode.JustifyImageRight;
legendAdornmentLayer.Title.TopPadding = 10;
legendAdornmentLayer.Title.BottomPadding = 10;
legendAdornmentLayer.Title.TextStyle = new TextStyle("Population", new GeoFont("Segoe UI", 12), new GeoSolidBrush(GeoColor.SimpleColors.Black));
map.AdornmentOverlay.Layers.Add(legendAdornmentLayer);
foreach (var item in values)
{
LegendItem legendItem = new LegendItem();
legendItem.ImageWidth = 20;
legendItem.TextRightPadding = 5;
legendItem.RightPadding = 5;
if (item == "1")
{
legendItem.ImageStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Red));
}
// … other values
legendItem.TextStyle = new TextStyle(item, new GeoFont("Segoe UI", 10), new GeoSolidBrush(GeoColor.SimpleColors.Black));
legendAdornmentLayer.LegendItems.Add(legendItem);
}
}
Hope it helps.
Btw, we fixed a bug related with legend, would you please get the latest dll packages (8.0.149.0) to have a try?
Any questions, please feel free to let us know.
Troy