Select to view content in your preferred language

UniqueValueRenderer.DefaultLabel or How to Handle Null Values

1258
4
05-27-2011 12:37 PM
TonyThatcher
Deactivated User
I think that this is simple, but it is eluding me.

Using a UniqueValueRenderer, how do you handle Null values in the attribute field? I have a simple Attribute Field that is either "X" or is Null. Displaying the features that are attributed with "X" is simple. And I can get the features with Null to display if I use a DefaultSymbol to catch the uncategoriezed values. But I can't figure out how to get a Label in the legend for the DefaultSymbol. There appears to be a DefaultLabel property, but I can't seem to implement it.

Here's what I have:
<esri:UniqueValueRenderer x:Key="TrailsRenderer" Attribute="Snow">                      
                        <esri:UniqueValueRenderer.DefaultSymbol >
                            <esri:SimpleLineSymbol  Color="#70A800" Width="1.5" />
                        </esri:UniqueValueRenderer.DefaultSymbol>
                        <esri:UniqueValueRenderer.Infos>
                            <esri:UniqueValueInfo Value="" Label="Non-Motorized" Symbol="{StaticResource TrailsNonMotorSymbol}" />                            <esri:UniqueValueInfo Value="X" Label="Snowmobile" Symbol="{StaticResource TrailsSnomoSymbol}" />
                        </esri:UniqueValueRenderer.Infos>
                    </esri:UniqueValueRenderer>


I either want the "Non-Motorized" to show up as used in the UniqueValueInfo, or use the DefaultValue, but be able to include a label in the Table of Contents.

Thanks, as always!

-T
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
You can hook up an handler to the legend refreshed event and set the label by code (knowning that the default symbol is the first item).

Something like:
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
{
  if (e.LayerItem.Layer.Renderer is UniqueValueRenderer)
    e.LayerItem.LayerItems[0].Label = "Non-Motorized";
}
0 Kudos
TonyThatcher
Deactivated User
Looks like it might do the trick, but I'm having trouble implementing the code.  First off, I'm in VB, C, so that may be an issue.  But I can't get your first line to compile without error.  I get:
"Renderer is not a member of ESRI.ArcGIS.Client.Layer"

And as long as we are at it, I'll need to be able to identify the correct layer, preferably by name, since about a dozen layers are being added and run through the same Legend_Refreshed event.  I don't want to re-label the legend in every layer.  I can't seem to find a Name/ID/etc. parameter that I can identify the layer with.

A suggestion for future versions.  Either have the renderer handle empty/null values in an attribute field the way the ArcGIS renderers do, or be able to put a Label on the Default value without having to use code in the Refreshed event.

-Tony
0 Kudos
JackCibor
Frequent Contributor
I just wanted to second Tony's suggestion that the defaultLabel property should be supported by the legend in future versions. Maybe in time for 2.2 final??? Please!

In the mean time, thanks for the work around.
0 Kudos
JenniferNery
Esri Regular Contributor
UniqueValueRenderer has a DefaultLabel and DefaultSymbol properties, which get used when none of the UniqueValueInfos match. If the symbol will be used for two values: X and Null. You can use just DefaultSymbol and not specify a UniqueValueInfo with Value=X so that features with this attribute value will also fallback to the DefaultSymbol. Your legend should reflect this DefaultSymbol and DefaultLabel.
<esri:UniqueValueRenderer x:Key="MyRenderer" Attribute="ftype" DefaultLabel="X or Null">    
 <esri:UniqueValueRenderer.DefaultSymbol>
  <esri:SimpleFillSymbol Fill="DarkBlue"/>
 </esri:UniqueValueRenderer.DefaultSymbol>
</esri:UniqueValueRenderer>
0 Kudos