I am trying to add simple legend to the map.
I wrote some simple test code below to see what happens but it did not work.
var map = activeView.FocusMap;
IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;
IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame;
UID uid = new UID();
uid.Value = "esriCarto.Legend";
IMapSurround mapSurround = map.CreateMapSurround(uid, null);
mapFrame.CreateSurroundFrame(uid, null);
var legend = (ILegend)mapSurround;
var legendItem = new VerticalLegendItemClass();
legendItem.HeadingSymbol.Text = "served";
legend.AddItem(legendItem);
var legendItema = new VerticalLegendItemClass();
legendItema.HeadingSymbol.Text = "unserved";
legend.AddItem(legendItema);
IElement element = legend as IElement;
element.Geometry = envelope as IGeometry;
graphicsContainer.AddElement(element, 0);
activeView.Refresh();
The legend I am after, must be similar to this:
Can anyone assist?
No comments:
Post a Comment