Select to view content in your preferred language

LayerDrawingOptions Font Size Set Same As Server Default But Renders Smaller

4544
14
Jump to solution
01-09-2014 09:31 AM
Labels (1)
RyanCoodey
Frequent Contributor
I am building a dialog to allow the users to change a layers labeling scale, all other LayerDrawingOptions should stay at the defaults. Unfortnatly from what I can tell, there is no way to just change the label's min/max scale without also defining most the other LayerDrawingOptions. Found I could skip resetting the renderer (leave it null) if I also dont reset "Opacity".

First question, is there any easy way to just change the label min/max without having to specify all the other properties?

Since there is not a nice method like CreateDynamicLayerInfosFromLayerInfos() for LayerDrawingOptions I am retrieving all the layer info manually from the servers (JSON).

Second question, is there a built in way to get this info I am not seeing?

I am taking this info to build out a complete LayerDrawingOptions with the defaults from the server, but the Font Size (even though set to the same font settings as the server) gets smaller.

Third question, and most important, is this a bug? Why is it not rendering the same size?

Thanks a lot for any help or info!
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor

First question, is there any easy way to just change the label min/max without having to specify all the other properties?


You have to set all the labels properties but not all the renderer properties.
For example the following code is working with the renderer defined at server side:

<esri:Map>     <esri:ArcGISDynamicMapServiceLayer Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer">         <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>             <esri:LayerDrawingOptionsCollection>                 <esri:LayerDrawingOptions LayerID="2" ShowLabels="True">                     <esri:LayerDrawingOptions.LabelClasses>                         <esri:LabelClassCollection>                             <esri:LabelClass LabelExpression="[state_abbr]" MaxScale="15000000">                                 <esri:LabelClass.LabelOptions>                                     <esri:LabelOptions FontSize="20" Color="Green" />                                 </esri:LabelClass.LabelOptions>                             </esri:LabelClass>                             <esri:LabelClass LabelExpression="[state_name] CONCAT NEWLINE CONCAT &quot;Pop2000:&quot; CONCAT [pop2000]" MinScale="15000000">                                 <esri:LabelClass.LabelOptions>                                     <esri:LabelOptions FontSize="15" Color="Green" />                                 </esri:LabelClass.LabelOptions>                             </esri:LabelClass>                         </esri:LabelClassCollection>                     </esri:LayerDrawingOptions.LabelClasses>                </esri:LayerDrawingOptions>             </esri:LayerDrawingOptionsCollection>         </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>         <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>             <esri:DynamicLayerInfoCollection>                 <esri:DynamicLayerInfo ID="2">                     <esri:DynamicLayerInfo.Source>                         <esri:LayerMapSource MapLayerID="2" />                     </esri:DynamicLayerInfo.Source>                 </esri:DynamicLayerInfo>             </esri:DynamicLayerInfoCollection>         </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>     </esri:ArcGISDynamicMapServiceLayer> </esri:Map>



Since there is not a nice method like CreateDynamicLayerInfosFromLayerInfos() for LayerDrawingOptions I am retrieving all the layer info manually from the servers (JSON).

Second question, is there a built in way to get this info I am not seeing?


You are right there is no builtin method to create a default layerDrawingOptions nevertheless you can use the GetAllDetails method to get renderers defined at server side and use them to build a LayerDrawingOptions object.

I am taking this info to build out a complete LayerDrawingOptions with the defaults from the server, but the Font Size (even though set to the same font settings as the server) gets smaller.

Third question, and most important, is this a bug? Why is it not rendering the same size?


I am not sure but might be a difference due to points vs pixels. try by multiplying by a ratio 96/72.

View solution in original post

0 Kudos
14 Replies
DominiqueBroux
Esri Frequent Contributor

First question, is there any easy way to just change the label min/max without having to specify all the other properties?


You have to set all the labels properties but not all the renderer properties.
For example the following code is working with the renderer defined at server side:

<esri:Map>     <esri:ArcGISDynamicMapServiceLayer Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer">         <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>             <esri:LayerDrawingOptionsCollection>                 <esri:LayerDrawingOptions LayerID="2" ShowLabels="True">                     <esri:LayerDrawingOptions.LabelClasses>                         <esri:LabelClassCollection>                             <esri:LabelClass LabelExpression="[state_abbr]" MaxScale="15000000">                                 <esri:LabelClass.LabelOptions>                                     <esri:LabelOptions FontSize="20" Color="Green" />                                 </esri:LabelClass.LabelOptions>                             </esri:LabelClass>                             <esri:LabelClass LabelExpression="[state_name] CONCAT NEWLINE CONCAT &quot;Pop2000:&quot; CONCAT [pop2000]" MinScale="15000000">                                 <esri:LabelClass.LabelOptions>                                     <esri:LabelOptions FontSize="15" Color="Green" />                                 </esri:LabelClass.LabelOptions>                             </esri:LabelClass>                         </esri:LabelClassCollection>                     </esri:LayerDrawingOptions.LabelClasses>                </esri:LayerDrawingOptions>             </esri:LayerDrawingOptionsCollection>         </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>         <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>             <esri:DynamicLayerInfoCollection>                 <esri:DynamicLayerInfo ID="2">                     <esri:DynamicLayerInfo.Source>                         <esri:LayerMapSource MapLayerID="2" />                     </esri:DynamicLayerInfo.Source>                 </esri:DynamicLayerInfo>             </esri:DynamicLayerInfoCollection>         </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>     </esri:ArcGISDynamicMapServiceLayer> </esri:Map>



Since there is not a nice method like CreateDynamicLayerInfosFromLayerInfos() for LayerDrawingOptions I am retrieving all the layer info manually from the servers (JSON).

Second question, is there a built in way to get this info I am not seeing?


You are right there is no builtin method to create a default layerDrawingOptions nevertheless you can use the GetAllDetails method to get renderers defined at server side and use them to build a LayerDrawingOptions object.

I am taking this info to build out a complete LayerDrawingOptions with the defaults from the server, but the Font Size (even though set to the same font settings as the server) gets smaller.

Third question, and most important, is this a bug? Why is it not rendering the same size?


I am not sure but might be a difference due to points vs pixels. try by multiplying by a ratio 96/72.
0 Kudos
RyanCoodey
Frequent Contributor
Dominique to the rescue again! Thanks a lot.


  1. Thanks for confirming. Would be a nice future enhancement request... maybe something along the lines of all the properties can be nullable and if null then server defaults are used. Not sure what is required on the server side though, so probably not be quite that simple. We�??ll survive without that feature though :).


  2. Thanks for confirming. Would be a nice future enhancement request to get default LayerDrawingOptions out of the box, but no hurries from me on a feature like that, pretty easy to implement for oneself.


  3. Thanks much, that was the problem... scaling by 96/72 worked! A few additional questions if I may:


    1. So 96 is the screen DPI (which I can have C# get the current users default in case this is not), but may I ask what the 72 is?

    2. Now the labels almost match the same as the defaults, the only other thing that seems to be happening is the labels (in this case for a line) shift away from the line more than the defaults do. Setting the LabelClass.LabelPlacement like so:

    3. labelClass.LabelPlacement = (LabelPlacement)Enum.Parse(typeof(LabelPlacement), currentJSONLabelingInfo.labelPlacement.Replace("esriServer", "")); //Convert esriServerLinePlacementAboveAlong to LinePlacementAboveAlong

      And there are no offsets or anything. Not a huge issue... but not sure why they are shifting a bit if you happen to know? Attached an image for clarification.

Thanks again for all the great help! If Dominique�??s boss is reading this, please give him a raise :).
0 Kudos
DominiqueBroux
Esri Frequent Contributor
So 96 is the screen DPI (which I can have C# get the current users default in case this is not), but may I ask what the 72 is?

By definition in typography a point is 1/72 of an inch. So we can set a constant with this value.

Now the labels almost match the same as the defaults, the only other thing that seems to be happening is the labels (in this case for a line) shift away from the line more than the defaults do. Setting the LabelClass.LabelPlacement like so:
labelClass.LabelPlacement = (LabelPlacement)Enum.Parse(typeof(LabelPlacement), currentJSONLabelingInfo.labelPlacement.Replace("esriServer", "")); //Convert esriServerLinePlacementAboveAlong to LinePlacementAboveAlong

And there are no offsets or anything. Not a huge issue... but not sure why they are shifting a bit if you happen to know? Attached an image for clarification.

Sorry no idea.


Thanks again for all the great help! If Dominique�??s boss is reading this, please give him a raise .


Thanks I'll definitively remind him when the time comes 😮
0 Kudos
RyanCoodey
Frequent Contributor
Great, thanks once again Dominique for the information!
0 Kudos
SaranPon
Emerging Contributor
Hi,

I have a similar requirement to update Labels using a local dynamic layer (only one layer in the package).

I tried the following as suggested

 <esri:Map>
            <esri:ArcGISLocalDynamicMapServiceLayer Path="States.mpk">
                <esri:ArcGISLocalDynamicMapServiceLayer.LayerDrawingOptions>
                    <esri:LayerDrawingOptionsCollection>
                        <esri:LayerDrawingOptions LayerID="0" ShowLabels="True">
                            <esri:LayerDrawingOptions.LabelClasses>
                                <esri:LabelClassCollection>
                                    <esri:LabelClass LabelExpression="[NAME1]" MaxScale="15000000">
                                        <esri:LabelClass.LabelOptions>
                                            <esri:LabelOptions FontSize="20" Color="Green" />
                                        </esri:LabelClass.LabelOptions>
                                    </esri:LabelClass>
                                    <esri:LabelClass LabelExpression="[NAME1]" MinScale="15000000">
                                        <esri:LabelClass.LabelOptions>
                                            <esri:LabelOptions FontSize="15" Color="Green" />
                                        </esri:LabelClass.LabelOptions>
                                    </esri:LabelClass>
                                </esri:LabelClassCollection>
                            </esri:LayerDrawingOptions.LabelClasses>
                        </esri:LayerDrawingOptions>
                    </esri:LayerDrawingOptionsCollection>
                </esri:ArcGISLocalDynamicMapServiceLayer.LayerDrawingOptions>
                <esri:ArcGISLocalDynamicMapServiceLayer.DynamicLayerInfos>
                    <esri:DynamicLayerInfoCollection>
                        <esri:DynamicLayerInfo ID="0">
                            <esri:DynamicLayerInfo.Source>
                                <esri:LayerMapSource MapLayerID="0" />
                            </esri:DynamicLayerInfo.Source>
                        </esri:DynamicLayerInfo>
                    </esri:DynamicLayerInfoCollection>
                </esri:ArcGISLocalDynamicMapServiceLayer.DynamicLayerInfos>
            </esri:ArcGISLocalDynamicMapServiceLayer>
        </esri:Map>


Am I doing anything wrong here? Can someone help?

Thanks,
Saran
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You have to set EnableDynamicLayers to true in order to be able to change the renderer or the labelling of local dynamic layers.

<esri:ArcGISLocalDynamicMapServiceLayer Path="States.mpk" EnableDynamicLayers="True">
.....


Then make sure that the field NAME1 does exist:
<esri:LabelClass LabelExpression="[NAME1]" >

else the labelling won't work.
For testing purpose, you can set an hardcoded expression not depending on field names such as:
<esri:LabelClass LabelExpression="&quot;TEST&quot;" >
0 Kudos
SaranPon
Emerging Contributor
Dominique,

Thanks. However after setting the EnableDynamicLayers="True" option, there is no map produced.... output is blank...


 <esri:Map>
            <esri:ArcGISLocalDynamicMapServiceLayer Path="W:\Inforum Platform_Dev\Mapviewer\ESRIShapeFiles\Boundary\States.mpk"  EnableDynamicLayers="True">
                <esri:ArcGISLocalDynamicMapServiceLayer.LayerDrawingOptions>
                    <esri:LayerDrawingOptionsCollection>
                        <esri:LayerDrawingOptions LayerID="1" ShowLabels="True">
                            <esri:LayerDrawingOptions.LabelClasses>
                                <esri:LabelClassCollection>
                                    <esri:LabelClass LabelExpression="[NAME1]" MaxScale="15000000">
                                        <esri:LabelClass.LabelOptions>
                                            <esri:LabelOptions FontSize="20" Color="Green" />
                                        </esri:LabelClass.LabelOptions>
                                    </esri:LabelClass>
                                    <esri:LabelClass LabelExpression="[NAME1]" MinScale="15000000">
                                        <esri:LabelClass.LabelOptions>
                                            <esri:LabelOptions FontSize="15" Color="Green" />
                                        </esri:LabelClass.LabelOptions>
                                    </esri:LabelClass>
                                </esri:LabelClassCollection>
                            </esri:LayerDrawingOptions.LabelClasses>
                        </esri:LayerDrawingOptions>
                    </esri:LayerDrawingOptionsCollection>
                </esri:ArcGISLocalDynamicMapServiceLayer.LayerDrawingOptions>
                <esri:ArcGISLocalDynamicMapServiceLayer.DynamicLayerInfos>
                    <esri:DynamicLayerInfoCollection>
                        <esri:DynamicLayerInfo ID="1">
                            <esri:DynamicLayerInfo.Source>
                                <esri:LayerMapSource MapLayerID="1" />
                            </esri:DynamicLayerInfo.Source>
                        </esri:DynamicLayerInfo>
                    </esri:DynamicLayerInfoCollection>
                </esri:ArcGISLocalDynamicMapServiceLayer.DynamicLayerInfos>
            </esri:ArcGISLocalDynamicMapServiceLayer>
        </esri:Map>


I verified that I have a column named [NAME1] available... also tried to use the text as suggested.... nothing worked.

Any help will be appreciated... Thanks.

regards,
Saran
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Dominique,

I verified that I have a column named [NAME1] available... also tried to use the text as suggested.... nothing worked.

If you could share your file States.mpk, I would take a look.
0 Kudos
SaranPon
Emerging Contributor
Hi,

Please find attached...


Thanks,
Saravanan
0 Kudos