Select to view content in your preferred language

How to change NumberFormat at ScaleBar

966
2
Jump to solution
12-11-2019 07:31 PM
by Anonymous User
Not applicable

Hi Guys,

Below is my current code snippet.

I want to change my custom scale bar number format to be whole number without decimal place.

And would like to change the Kilometer wording Label as well.

Have any idea to do it?



StyleProjectItem arcgis_2dStyle = Project.Current.GetItems<StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
                    //Construct on the worker thread
                    QueuedTask.Run(() =>
                    {
                        //Reference the specific scale bar by name 
                        ScaleBarStyleItem scaleBarItem = arcgis_2dStyle.SearchScaleBars("Alternating Scale Bar 1 Metric").FirstOrDefault();
                       
                        double GuessX = 0.5;
                        double GuessY = 1;
                        //Reference the map frame and define the location                       
                        Coordinate2D coord2D = new Coordinate2D(GuessX, GuessY);
                        
                        //Construct the scale bar
                        ScaleBar settedBar = LayoutElementFactory.Instance.CreateScaleBar(activeLayoutView.Layout, coord2D, activedMapFrame, scaleBarItem);
                        settedBar.SetName("Custom Scale bar");
                        CIMDoubleFillScaleBar scaleBarElement = settedBar.GetDefinition() as CIMDoubleFillScaleBar;
                        scaleBarElement.UnitLabelPosition = ScaleBarLabelPosition.Below;
                        scaleBarElement.Division = 5;
                        scaleBarElement.Subdivisions = 0;
                        scaleBarElement.DivisionsBeforeZero = 0;
                        scaleBarElement.DivisionsBeforeZero = 0;
                        scaleBarElement.LabelFrequency = ScaleBarFrequency.Divisions;

                        //Division resize behavior -> adjust width
                        //Division Value -> how to dynamically appropriately add the value(to be 50) or dynamic width, 
                        //interval will be whole number(Need to figure out)
                        //scaleBarElement.NumberFormat = 
                        //Need to change label text to Kilometres
                        scaleBarElement.BarHeight = 3;
                        settedBar.SetDefinition(scaleBarElement);
                    }, ps.Progressor);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thank in advance

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Thank Uma,

It work.

That mean CIMNumericFormat is extended from CIMNumberFormat.

I keep on finding that CIMNumberFormat

For Number format, it is not what I want but that give me to get right solution.

With esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits properties, I sometime gets one decimal place.

 scaleBarElement.UnitLabel = "Kilometers";
var numberFormat = scaleBarElement.NumberFormat as CIMNumericFormat;
  numberFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
  numberFormat.RoundingValue = 0;

View solution in original post

0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

Hi Than

This worked for me -

                scaleBarElement.UnitLabel = "Not Kilometers";
                var numberFormat = scaleBarElement.NumberFormat as CIMNumericFormat;
                numberFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;
by Anonymous User
Not applicable

Thank Uma,

It work.

That mean CIMNumericFormat is extended from CIMNumberFormat.

I keep on finding that CIMNumberFormat

For Number format, it is not what I want but that give me to get right solution.

With esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits properties, I sometime gets one decimal place.

 scaleBarElement.UnitLabel = "Kilometers";
var numberFormat = scaleBarElement.NumberFormat as CIMNumericFormat;
  numberFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
  numberFormat.RoundingValue = 0;
0 Kudos