Select to view content in your preferred language

SimpleLineSymbol display in Legend

563
1
02-16-2011 11:38 PM
SantoshV
Emerging Contributor
HI ,
I have written the below code

 
            <esriSymbols:SimpleLineSymbol x:Name="LineSymbolDeepPink" Color="DeepPink" Width="3" />
            <esriSymbols:SimpleLineSymbol x:Name="LineSymbolRed" Color="Red"  Width="3" />

                   for (int i = 0; i < featureSet.Features.Count(); i++)
                    {
                        selectedFeature = featureSet.Features;
                        if (selectedFeature.Attributes["ROAD_CATEGORY"].ToString() == "1")
                        {
                            selectedFeature.Symbol = LineSymbolDeepPink;
                        }
                        else if (selectedFeature.Attributes["ROAD_CATEGORY"].ToString() == "2")
                        {
                            selectedFeature.Symbol = LineSymbolGreen;
                        }

                        graphicsLayer.Graphics.Add(selectedFeature);
                    }
                    //   Hightlight selected feature
                    graphicsLayer.Graphics.Add(selectedFeature);


The graphic shows on the map but Does not show on the Legend

I tried

                <esri:UniqueValueRenderer.Infos>
                    <esri:UniqueValueInfo Value="1" Symbol="{StaticResource LineSymbolDeepPink}" />
                    <esri:UniqueValueInfo Value="2" Symbol="{StaticResource LineSymbolRed}" />
                </esri:UniqueValueRenderer.Infos> 
and also
                <!--<esri:UniqueValueInfo Symbol="{StaticResource LineSymbolDeepPink}">
                    <esri:UniqueValueInfo.Value>
                        <sys:Int32>1</sys:Int32>
                    </esri:UniqueValueInfo.Value>
                </esri:UniqueValueInfo>
                <esri:UniqueValueInfo Symbol="{StaticResource LineSymbolRed}">
                    <esri:UniqueValueInfo.Value>
                        <sys:Int32>2</sys:Int32>
                    </esri:UniqueValueInfo.Value>
                </esri:UniqueValueInfo>

but either the legend wont show or the graphic wont show
what am I missing here? I want to show only the queried ROAD_CATEGORY on the map and the legend
0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor
Based on the code-snippet you provided, you are trying to use a Renderer with Symbol. This will not work, you have to choose one or the other.

If you want to take advantage of the Legend control, you need to use the Renderer version. But the UniqueValueInfo.Value must match the field attribute in order for the symbol to show. Notice when you were updating the symbol, the comparison was:
selectedFeature.Attributes["ROAD_CATEGORY"].ToString() == "1")

You had to convert them to the same data type. The same thing holds true for UniqueValueRenderer, data type is also checked against. If neither string "1" nor int 1 worked, then maybe first check what the field data type is, maybe it's a double.

You can check when the layer gets Initialized using the following code:
FeatureLayer l = sender as FeatureLayer;
Field.FieldType type = Field.FieldType.Unknown;
foreach (var f in l.LayerInfo.Fields)
{
 if (f.Name == "ROAD_CATEGORY")
 {
  type = f.Type;
  break;
 }
}
0 Kudos