Parameters
- mapFrame
- MapFrame
Exception | Description |
---|---|
ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
//Added references using ArcGIS.Desktop.Core; //Project using ArcGIS.Desktop.Layouts; //Layout class using ArcGIS.Desktop.Framework.Threading.Tasks; //QueuedTask public class MapSurroundExample { public static Task<bool> UpdateMapSurroundAsync(string LayoutName, string SBName, string MFName) { //Reference a layoutitem in a project by name LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName)); if (layoutItem == null) return Task.FromResult(false); return QueuedTask.Run<bool>(() => { //Reference and load the layout associated with the layout item Layout lyt = layoutItem.GetLayout(); //Reference a scale bar element by name MapSurround scaleBar = lyt.FindElement(SBName) as MapSurround; if (scaleBar == null) return false; //Reference a map frame element by name MapFrame mf = lyt.FindElement(MFName) as MapFrame; if (mf == null) return false; //Set the scale bar to the newly referenced map frame scaleBar.SetMapFrame(mf); return true; }); } }
//Create a new table frame on the active layout. Layout layout = LayoutView.Active.Layout; //Perform on the worker thread await QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D rec_ll = new Coordinate2D(1.0, 3.5); Coordinate2D rec_ur = new Coordinate2D(7.5, 4.5); //At 2.x - Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur); Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur); //Reference map frame MapFrame mf = layout.FindElement("Map Frame") as MapFrame; //Reference layer Map m = mf.Map; FeatureLayer lyr = m.FindLayers("GreatLakes").First() as FeatureLayer; //Build fields list var fields = new[] { "NAME", "Shape_Area", "Shape_Length" }; //Construct the table frame //At 2.x - TableFrame tabFrame = LayoutElementFactory.Instance.CreateTableFrame(layout, rec_env, mf, lyr, fields); var surroundInfo = new TableFrameInfo() { FieldNames = fields, MapFrameName = mf.Name, MapMemberUri = lyr.URI }; var tabFrame = ElementFactory.Instance.CreateMapSurroundElement(layout, rec_env, surroundInfo) as TableFrame; });
await QueuedTask.Run(() => { LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>() .FirstOrDefault(item => item.Name.Equals("Layout Name")); Layout lyt = layoutItem.GetLayout(); MapFrame mf = lyt.FindElement("Map1 Map Frame") as MapFrame; MapSurround ms = lyt.FindElement("Scale Bar") as MapSurround; ms.SetMapFrame(mf); });
//Update a map surround. //Perform on the worker thread QueuedTask.Run(() => { // Reference and load the layout associated with the layout item Layout layout = layoutItem.GetLayout(); if (layout != null) { // Reference a scale bar element by name MapSurround scaleBar = layout.FindElement("MyScaleBar") as MapSurround; // Reference a map frame element by name MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame; if ((scaleBar != null) && (mf != null)) //Set the scale bar to the newly referenced map frame scaleBar.SetMapFrame(mf); } });
Target Platforms: Windows 11, Windows 10, Windows 8.1