ProSnippets TextSymbols - Esri/arcgis-pro-sdk GitHub Wiki

All ProSnippets listed here are also used by the following sample code: TextSymbols sample code

Language:              C#  
Subject:               Map-Authoring  
Contributor:           ArcGIS Pro SDK Team <[email protected]>  
Organization:          esri, http://www.esri.com  
Date:                  10/22/2024  
ArcGIS Pro:            3.4  
Visual Studio:         2022  
.NET Target Framework: .Net 8  

TextSymbols

Creates a simple text symbol

Creates a simple black text symbol with a size of 8.5, Font Family "Corbel" and Font Style of "Regular". lineCallOut

private static Task<CIMTextSymbol> CreateSimpleTextAsync()
{
    return QueuedTask.Run <CIMTextSymbol>(() => 
    {
        //Create a simple text symbol
        return SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
    });
    
}

Creates a text symbol with a halo

Creates a text symbol with a red halo halo

private static Task<CIMTextSymbol> CreateTextSymbolWithHaloAsync()
{
    return QueuedTask.Run<CIMTextSymbol>(() =>
   {
       //create a polygon symbol for the halo
       var haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid);
       //create text symbol using the halo polygon
       return SymbolFactory.Instance.ConstructTextSymbol(haloPoly, 10, "Arial", "Bold");
   });        
}

Creates a simple line callout text symbol

Creates a simple line callout text symbol. The CIMSimpleLineCallout created is a dash-dot-dash line symbol with an offset of 10 from the geometry being labeled. lineCallOut

private static Task<CIMTextSymbol> CreateSimpleLineCalloutAsync()
{
    return QueuedTask.Run<CIMTextSymbol>(() => {
        //create a text symbol
        var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Verdana", "Regular");
        //Create a line call out
        var lineCalloutSymbol = new CIMSimpleLineCallout();
        //Get a line symbol
        var lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot);                
        //assign the line symbol to the callout
        lineCalloutSymbol.LineSymbol = lineSymbol;
        //Offset for the text
        textSymbol.OffsetX = 10;
        textSymbol.OffsetY = 10;
        //Assign the callout to the text symbol
        textSymbol.Callout = lineCalloutSymbol;
        return textSymbol;
    });           
}

Creates a balloon callout text symbol

Creates a black banner balloon callout text symbol. The CIMBalloonCallout created is a rectangular polygon with rounded corners. lineCallOut

private static Task<CIMTextSymbol> CreateBalloonCalloutAsync()
{
    return QueuedTask.Run<CIMTextSymbol>(() =>
    {
        //create a text symbol
        var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular");
        //A balloon callout
        var balloonCallout = new CIMBalloonCallout();
        //set the callout's style
        balloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
        //Create a solid fill polygon symbol for the callout.
        var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
        //Set the callout's background to be the black polygon symbol
        balloonCallout.BackgroundSymbol = polySymbol;
        //margin inside the callout to place the text
        balloonCallout.Margin = new CIMTextMargin
        {
                    Left = 5,
                    Right = 5,
                    Bottom = 5,
                    Top = 5
        };
        //assign the callout to the text symbol's callout property
        textSymbol.Callout = balloonCallout;
        return textSymbol;
    });
}

Creates a point callout text symbol

Creates a highway shield callout text symbol. The CIMPointSymbolCallout created is a highway shield point symbol from the ArcGIS 2D style. lineCallOut

private static Task<CIMTextSymbol> CreatePointCallOutAsync()           
{
    return QueuedTask.Run<CIMTextSymbol>(() =>
    {
        //create a text symbol
        var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 6, "Tahoma", "Bold");
        //Create a call out
        var shieldCalloutSymbol = new CIMPointSymbolCallout();
        //Get a Shield symbolStyleItem from ArcGIS 2D StyleProjectitem
        var symbolStyleItem = GetPointSymbol("ArcGIS 2D", "Shield 1");             
        //assign the point symbol (Highway shield) to the callout
        shieldCalloutSymbol.PointSymbol = symbolStyleItem.Symbol as CIMPointSymbol;
        shieldCalloutSymbol.PointSymbol.SetSize(18.0); //set symbol size
        //Assign the callout to the text symbol
        textSymbol.Callout = shieldCalloutSymbol;
        return textSymbol;
    });
}

Creates a background callout text symbol

Creates a solid fill background text symbol with an Accent bar and leader line. The CIMBackgroundCallout created has a solid fill aqua polygon, with a black dash-dot-dash leader line and a solid accent bar. lineCallOut

private static Task<CIMTextSymbol> CreateBackgroundCalloutAsync()
{
    return QueuedTask.Run<CIMTextSymbol>(() =>
    {
        var textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Tahoma", "Bold");
        //Create a call out
        var backgroundCalloutSymbol = new CIMBackgroundCallout();
        //Leader line
        //Get a line symbol
        var lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot);
        //Create a solid fill polygon symbol for the callout.
        var aquaBackground = ColorFactory.Instance.CreateRGBColor(190, 255, 232, 100);
        var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(aquaBackground, SimpleFillStyle.Solid);
        //assign the line to the callout
        backgroundCalloutSymbol.LeaderLineSymbol = lineSymbol;
        //Offset for the text
        textSymbol.OffsetX = 10;
        textSymbol.OffsetY = 10;
        //Assign the polygon to the background callout
        backgroundCalloutSymbol.BackgroundSymbol = polySymbol;
        //Accent bar
        var accentSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid);
        backgroundCalloutSymbol.AccentBarSymbol = accentSymbol;
        //Set margins for the callout
        backgroundCalloutSymbol.Margin = new CIMTextMargin
        {
            Left = 5,
            Right = 5,
            Top = 5,
            Bottom = 5
        };
        
        //assign the callout to the textSymbol
        textSymbol.Callout = backgroundCalloutSymbol;
        return textSymbol;
    });
}
⚠️ **GitHub.com Fallback** ⚠️