Select to view content in your preferred language

Graphic Layer Legend display

2705
7
02-13-2011 09:20 PM
SantoshV
Emerging Contributor
HI,
I have done Dynamic segmentation on roads, I am returning a graphic layer that is displaying on the map according to the road surface types there is more than 40 types of roads

My problem is how do I assign unique colors to each road and also display its legend

I guess ClassBreaksRenderer can't be used as I have to mention the min and max..

Please guide
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
The Legend control will pick up the symbols based on whatever renderer you have selected to use.

If you don't need to distinguish between types or classes, you can use SimpleRenderer.

This sample use the 3 types of Renderer (Simple, UniqueValue, ClassBreaks):http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#RenderersXAML.

You can add this piece of code to see what the Legend control will display for these types of Renderer:
<esri:Legend Map="{Binding ElementName=MyMap}" VerticalAlignment="Top" HorizontalAlignment="Right" />


You may also create and use your own Renderer that implements IRenderer.
0 Kudos
SantoshV
Emerging Contributor
Hey Jennifer thnx for the reply
but I still have a problem with class ClassBreaksRenderer

            <esri:ClassBreaksRenderer x:Key="MyClassBreaksRenderer" Attribute="POP1990" >
                <esri:ClassBreaksRenderer.Classes>
                    <esri:ClassBreakInfo MinimumValue="0" MaximumValue="30000" Symbol="{StaticResource MySmallMarkerSymbol}" />
                    <esri:ClassBreakInfo MinimumValue="30000" MaximumValue="300000" Symbol="{StaticResource MyMediumMarkerSymbol}" />
                    <esri:ClassBreakInfo MinimumValue="300000" MaximumValue="5000000" Symbol="{StaticResource MyLargeMarkerSymbol}" />
                </esri:ClassBreaksRenderer.Classes>
            </esri:ClassBreaksRenderer>


Here I have hard-coded the min and max but My requirement is such that I get the Min and Max on the run and it could go upto 80 unique values how do I assign a symbol in such cases
0 Kudos
JenniferNery
Esri Regular Contributor
You can create your own renderer by implementing IRenderer. You will be required to define GetSymbol() method. At this time, you will have access to the graphic attributes and decide programmatically which symbol to use.
0 Kudos
dotMorten_esri
Esri Notable Contributor
If you need unique colors for each type, use the UniqueValueRenderer instead of the ClassBreaksRenderer.
0 Kudos
SantoshV
Emerging Contributor
Hey UniqueValueRenderer  works fine for me but I have another problem with uniqueValueInfo.Value

My value is like this eg.. 12-12, 12-11, 56-60 etc..

I get this from two different attribute value graphic.Attributes["ROW_LEFT"].ToString() and
graphic.Attributes["ROW_RIGHT"].ToString() which I join later

           <esri:UniqueValueRenderer x:Name="uniqueValueRenderer">
                    </esri:UniqueValueRenderer>

                uniqueValueRenderer.Attribute = "ROW_RIGHT";
                string strValueassg = "";
                UniqueValueInfo uniqueValueInfo = new UniqueValueInfo();
                foreach (Graphic graphic in e.FeatureSet.Features)
                {
                    string strUniqueLabel = graphic.Attributes["ROW_LEFT"].ToString() + "-" +   graphic.Attributes["ROW_RIGHT"].ToString();
                    graphicsLayer.Graphics.Add(graphic);
                    Random random = new Random();
                    SimpleLineSymbol symbol = new SimpleLineSymbol();
                    if (strUniqueLabel != "" && strUniqueLabel != strValueassg)
                    {
                        symbol.Color = new SolidColorBrush(Color.FromArgb(255, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255)));
                        symbol.Width = 3;
                    }

                    uniqueValueInfo.Symbol = symbol;
                    uniqueValueInfo.Value = graphic.Attributes["ROW_RIGHT"];
                    uniqueValueInfo.Label = strUniqueLabel;

                    strValueassg = graphic.Attributes["ROW_LEFT"].ToString() + "-" + graphic.Attributes["ROW_RIGHT"].ToString();
                }
                uniqueValueRenderer.Infos.Add(uniqueValueInfo);

                graphicsLayer.Renderer = uniqueValueRenderer;



the color appears in the Legend but not on the map ..
I want to know if I can set any other value for uniqueValueRenderer.Attribute and uniqueValueInfo.Value
0 Kudos
SantoshV
Emerging Contributor
Hey UniqueValueRenderer worked just fine but the problem is uniqueValueInfo.Value,
I use a combination to two attributes string strUniqueLabel = graphic.Attributes["ROW_LEFT"].ToString() + "-" + graphic.Attributes["ROW_RIGHT"].ToString();

so I am unable to unique the output values coz the values could be eg 12-12, 12-11, 12-16

my code goes like this
                uniqueValueRenderer.Attribute = "ROW_LEFT";
                string strValueassg = "";
                UniqueValueInfo uniqueValueInfo = new UniqueValueInfo();
                foreach (Graphic graphic in e.FeatureSet.Features)
                {
                    string sss = graphic.Attributes["ROW_LEFT"].ToString();
                    string ddd = graphic.Attributes["ROW_RIGHT"].ToString();
                    string strUniqueLabel = graphic.Attributes["ROW_LEFT"].ToString() + "-" + graphic.Attributes["ROW_RIGHT"].ToString();

                    graphicsLayer.Graphics.Add(graphic);
                    Random random = new Random();
                    SimpleLineSymbol symbol = new SimpleLineSymbol();
                    if (strUniqueLabel != "" && strUniqueLabel != strValueassg)
                    {
                        symbol.Color = new SolidColorBrush(Color.FromArgb(255, (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255)));
                        symbol.Width = 3;
                        uniqueValueInfo.Symbol = symbol;
                        uniqueValueInfo.Value = graphic.Attributes["ROW_LEFT"];
                        uniqueValueInfo.Label = strUniqueLabel;
                        uniqueValueRenderer.Infos.Add(uniqueValueInfo);
                        graphicsLayer.Renderer = uniqueValueRenderer;
                    }

                    strValueassg = graphic.Attributes["ROW_LEFT"].ToString() + "-" + graphic.Attributes["ROW_RIGHT"].ToString();
                }


How do I give custom value to uniqueValueInfo.Value and also uniqueValueRenderer.Attribute ?
0 Kudos
JenniferNery
Esri Regular Contributor
UniqueValueRenderer only checks against one attribute. If you need to check against multiple attribute, you need to write your own renderer. Implementation should be similar to that of UniqueValueRenderer but in your GetSymbol() you will be checking for more attributes.
0 Kudos