Tuesday, 20 March 2018

arcmap - Creating new legend using ArcObjects?


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:


legend


Can anyone assist?





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...