How do you change the label style?

243
7
Jump to solution
10-24-2017 10:49 AM
Highlighted
Occasional Contributor

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

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
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
Highlighted
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

Highlighted
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)

Reply
0 Kudos
Highlighted
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>

Reply
0 Kudos
Highlighted
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

Highlighted
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>

Reply
0 Kudos
Highlighted
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>

Reply
0 Kudos
Highlighted
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