AddElement(GraphicsLayer,MapPoint,String,CIMTextSymbol,String,Boolean,ElementInfo) Method
Add a
ArcGIS.Desktop.Layouts.GraphicElement based on the input point, text, and textsymbol (optional). This method must be called on the MCT. Use QueuedTask.Run.
Text Graphic Element
var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
.OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
if (graphicsLayer == null)
return;
QueuedTask.Run(() =>
{
//Place symbol in the center of the map
var extent = MapView.Active.Extent;
var location = extent.Center;
//specify a text symbol
var text_symbol = SymbolFactory.Instance.ConstructTextSymbol
(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
graphicsLayer.AddElement(location, text_symbol, "Text Example");
});
Translates a point in page coordinates to a point in map coordinates.
//On the QueuedTask
var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
var mapFrame = layout.FindElement("New Map Frame") as MapFrame;
//Get a point in the center of the Map frame
var mapFrameCenterPoint = mapFrame.GetBounds().CenterCoordinate;
//Convert to MapPoint
//At 2.x - var pointInMapFrame = MapPointBuilder.CreateMapPoint(mapFrameCenterPoint);
var pointInMapFrame = MapPointBuilderEx.CreateMapPoint(mapFrameCenterPoint);
//Find the corresponding point in the MapView
var pointOnMap = mapFrame.PageToMap(pointInMapFrame);
//Create a point graphic on the MapView.
var cimGraphicElement = new CIMPointGraphic
{
Location = pointOnMap,
Symbol = pointSymbol.MakeSymbolReference()
};
graphicsLayer.AddElement(cimGraphicElement);
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.