How do you change the label style?

4485
7
Jump to solution
10-24-2017 10:49 AM
MichaelStranovsky
Occasional Contributor

I am looking for a way to change the font size, style(Bold) and add a mask(Halo) through the sdk.

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Hi Michael,

You should be able to adjust the settings of a MapFrame in a Layout using the SetCamera method.  Check out the code snippets on this page of the API Reference guide: topic11124.html

Thanks!

Uma

View solution in original post

7 Replies
UmaHarano
Esri Regular Contributor

Hi

You can access the Feature Layer's LabelClasses and the TextSymbol through the CIM to accomplish this.  Here is a snippet:

        private void ChangeLabel(FeatureLayer lyr)
        {
            var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer;
            var listLabelClasses =  lyrDefn.LabelClasses.ToList();

            var textSymbol = listLabelClasses.FirstOrDefault().TextSymbol.Symbol as CIMTextSymbol; //Gets the text symbol of the label class
            textSymbol.FontStyleName = "Bold"; //set font as bold
            textSymbol.SetSize(10); //set font size
            //Text symbol might not have a halo. 
            //So need to create a halo symbol (polygon with a solid fill layer)
            var haloFill = new CIMSolidFill
            {
                Enable = true,
                Color = ColorFactory.Instance.RedRGB,
                ColorLocked = false
            };
            //Define the array of Symbol layers (holds the halo solid fill only)
            var symbolLyrs = new CIMSymbolLayer[]
            {
                haloFill
            };

            //Creates the Polygon symbol with the halo solid fill layer
            var haloSymbol = new CIMPolygonSymbol
            {
                SymbolLayers = symbolLyrs
            };
            //Assign this halo symbol and its size to the text symbol
            textSymbol.HaloSymbol = haloSymbol;
            textSymbol.HaloSize = 1;

            lyrDefn.LabelClasses = listLabelClasses.ToArray(); //Set the labelClasses back
            lyr.SetDefinition(lyrDefn); //set the layer's definition

        }

Thanks

Uma

MichaelStranovsky
Occasional Contributor

Thank you for your help.  It worked like a charm.   One more question though,  how would you change the expression for the label?(the field used to label)

0 Kudos
MichaelStranovsky
Occasional Contributor

Thank you, how would you change the label expression(field use for labeling)?

Michael Stranovsky

Spatial Database Administrator

EIT – Enterprise GIS

1660 Ringling Blvd, Sarasota, FL 34236

Office: 941-914-8373

Cell: 941-914-8373

Email: mstranov@scgov.net<mailto:mstranov@scgov.net>

Web: www.scgov.net<http://www.scgov.net/>

All email sent to and from Sarasota County Government

is subject to the public record laws of the State of Florida.

To learn more about Florida’s Sunshine Law click here<https://employeenet.scgov.net/Communications/SitePages/Public%20Records.aspx>.

<https://www.facebook.com/SarasotaCountyGovernment/> <https://twitter.com/SRQCountyGov/> <https://www.instagram.com/srqemergencyservices/> <https://www.youtube.com/user/sarasotacounty1> <http://www.linkedin.com/company/27399?goback=.fcs_GLHD_sarasotacountygovernment_false_2_2_2_2_2_2_2_2_2_2_2_2&trk=ncsrch_hits>

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Michael

The LabelClass' Expression property can be used.  Like this:

theLabelClass.Expression = "$feature.POP2000";

Another thing you might find helpful while working with the CIM is to use the arcgis-pro-sdk-cim-viewer.  This will give a view of all the CIM objects, properties that you can manipulate for what you need.

Thanks

Uma

MichaelStranovsky
Occasional Contributor

Okay thank you again

Michael Stranovsky

Spatial Database Administrator

EIT – Enterprise GIS

1660 Ringling Blvd, Sarasota, FL 34236

Office: 941-914-8373

Cell: 941-914-8373

Email: mstranov@scgov.net<mailto:mstranov@scgov.net>

Web: www.scgov.net<http://www.scgov.net/>

All email sent to and from Sarasota County Government

is subject to the public record laws of the State of Florida.

To learn more about Florida’s Sunshine Law click here<https://employeenet.scgov.net/Communications/SitePages/Public%20Records.aspx>.

<https://www.facebook.com/SarasotaCountyGovernment/> <https://twitter.com/SRQCountyGov/> <https://www.instagram.com/srqemergencyservices/> <https://www.youtube.com/user/sarasotacounty1> <http://www.linkedin.com/company/27399?goback=.fcs_GLHD_sarasotacountygovernment_false_2_2_2_2_2_2_2_2_2_2_2_2&trk=ncsrch_hits>

0 Kudos
MichaelStranovsky
Occasional Contributor

Hi Uma,

Is there a way to get at the location settings of the mapframe in the layout through the sdk. I want to adjust the scale and the center x and y.

Michael Stranovsky

Spatial Database Administrator

EIT – Enterprise GIS

1660 Ringling Blvd, Sarasota, FL 34236

Office: 941-914-8373

Cell: 941-914-8373

Email: mstranov@scgov.net<mailto:mstranov@scgov.net>

Web: www.scgov.net<http://www.scgov.net/>

All email sent to and from Sarasota County Government

is subject to the public record laws of the State of Florida.

To learn more about Florida’s Sunshine Law click here<https://employeenet.scgov.net/Communications/SitePages/Public%20Records.aspx>.

<https://www.facebook.com/SarasotaCountyGovernment/> <https://twitter.com/SRQCountyGov/> <https://www.instagram.com/srqemergencyservices/> <https://www.youtube.com/user/sarasotacounty1> <http://www.linkedin.com/company/27399?goback=.fcs_GLHD_sarasotacountygovernment_false_2_2_2_2_2_2_2_2_2_2_2_2&trk=ncsrch_hits>

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Michael,

You should be able to adjust the settings of a MapFrame in a Layout using the SetCamera method.  Check out the code snippets on this page of the API Reference guide: topic11124.html

Thanks!

Uma