//Create a legend for an associated map frame.
//Construct on the worker thread
await QueuedTask.Run(() =>
{
//Build 2D envelope geometry
Coordinate2D leg_ll = new Coordinate2D(6, 2.5);
Coordinate2D leg_ur = new Coordinate2D(8, 4.5);
//At 2.x - Envelope leg_env = EnvelopeBuilder.CreateEnvelope(leg_ll, leg_ur);
Envelope leg_env = EnvelopeBuilderEx.CreateEnvelope(leg_ll, leg_ur);
//Reference MF, create legend and add to layout
MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame;
if (mapFrame == null)
{
//TODO handle null map frame
return;
}
//At 2.x - Legend legendElm = LayoutElementFactory.Instance.CreateLegend(
// layout, leg_env, mapFrame);
// legendElm.SetName("New Legend");
var legendInfo = new LegendInfo()
{
MapFrameName = mapFrame.Name
};
Legend legendElm = ElementFactory.Instance.CreateMapSurroundElement(
layout, leg_env, legendInfo, "New Legend") as Legend;
});