Select to view content in your preferred language

How to Add Text Overley (Graphic Element) in Arcgis Pro SDK

3450
6
11-15-2018 07:31 AM
tanerkoka
Frequent Contributor

Hi ,

We are develope commands for arcgis pro sdk 2.2 version.We have text and polygon geometry inputs. How can we add these (text and polgon) graphically on map without annotation or feature class  ? Can do it as Annotation also I can do polygon overlay (using MapView.Active.AddOverlay function) but but I want to create a graph with both polygon and te text like below in picture?How can I solve this problem?

Thaks for Helping

graphic

Tags (1)
0 Kudos
6 Replies
UmaHarano
Esri Regular Contributor

Here is a code snippet to create an overlay with text. This code is from a sample Map Tool:

internal class AddOverlayWithText : MapTool
    {
        private IDisposable _graphic = null;
        private CIMPolygonSymbol _polygonSymbol = null;
        public AddOverlayWithText()
        {
            IsSketchTool = true;
            SketchType = SketchGeometryType.Polygon;
            SketchOutputMode = SketchOutputMode.Map;
        }

        protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            //Add an overlay graphic to the map view
            _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid));
            _graphic = await this.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference());

            //define the text symbol
            var textSymbol = new CIMTextSymbol();
            //define the text graphic
            var textGraphic = new CIMTextGraphic();

            await QueuedTask.Run(() =>
            {
                //Create a simple text symbol
                textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
                //Sets the geometry of the text graphic
                textGraphic.Shape = geometry;
                //Sets the text string to use in the text graphic
                textGraphic.Text = "This is my polygon";
                //Sets symbol to use to draw the text graphic
                textGraphic.Symbol = textSymbol.MakeSymbolReference();
                //Draw the overlay text graphic
                _graphic = this.ActiveMapView.AddOverlay(textGraphic);
            });

            return true;
        }
    }

This code creates an overlay like this:

tanerkoka
Frequent Contributor

Thanks for halping Uma,

I had a final question about graphic overlay. Are there any graphic Layer (Graphic Container) for adding overlay in Arcgis pro SDK?  Can we find graphic overlay after save and close/open  pro document (.aprx file) ? Can we use it  like graphic Element in  ArcObject (Finds element from GraphicContainer and use it) or are there any solution to save overlay as graphic?

Thaks for helping.

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Taner

No, the graphics are not persisted.

Thanks

Uma

tanerkoka
Frequent Contributor

Hi Umma,

I can display mentioned above graphics on layout but I can not share (export pdf, jpg.etc)  ?How can we solve this problem because our customers also want to see these graphics (export pdf., jpg. etc. files).

Here are above pictures.

Layout picture:

Layout

Export pdf file picture:

pdf

Thanks for helping. 

0 Kudos
JamalWest2
Regular Contributor

@UmaHarano Do you have to create a drawn polygon for this to work? Is there anyway to  just add it automatically without the sketch part?

0 Kudos
UmaHarano
Esri Regular Contributor

Hi,

ArcGIS Pro now supports GraphicsLayers. So graphics such as this can be drawn using GraphicsLayer and GraphicElements. GraphicElements can be created with or without sketch tools.

Here are some wiki pages that help shed light on this:

ProConcepts: Graphics Layers 

ProSnippets: GraphicsLayers 

Sample

Thanks

Uma