Select to view content in your preferred language

UniqueValueRender for n values in a GraphicLayer

2709
4
Jump to solution
04-09-2014 12:38 PM
Labels (1)
Cristian_Galindo
Frequent Contributor
DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far???

I have a GraphicsLayer, it has n objects in the Graphics property. I want to use a UniqueValueRenderer for this layer.

I had use this kind of approach with an ArcGISLocalFeatureLayer and the GenerateRendererTask, but the GenerateRendererTask object requires an URL, it the used approach I used the service URL from the ArcGISLocalFeatureLayer. but a GraphicsLayer, it is not attached to a service.

can I use this task to generate the render based in a ColorRamp for a Graphicslayer?

If I have to iterate over each one of the grpahics in the layer to create the simbols, Can i use color ramp to calculate the color?

thanks!!
0 Kudos
1 Solution

Accepted Solutions
Cristian_Galindo
Frequent Contributor
Ok fellows, i got it :

            var uniqueValueRenderer = new UniqueValueRenderer();             var defaultSymbol = new ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol { Width = 2.5 };             uniqueValueRenderer.DefaultSymbol = defaultSymbol;             uniqueValueRenderer.Field = attributeField; //parameter              var colorRange = new ColorRange                                  {                                      From = this.GetRandomColor(),                                      To = this.GetRandomColor()                                  };              var rampInterpolator = new RampInterpolator                                        {                                            ColorRange = colorRange                                        };              foreach (var graphic in layer.Graphics)             {                 var valueInfo = new UniqueValueInfo                                     {                                         Label = graphic.Attributes[attributeField].ToString(),                                         Value = graphic.Attributes[attributeField].ToString(),                                         Symbol =                                             rampInterpolator.GetInterpolatedSymbol(                                                 defaultSymbol, graphic, 0, layer.Graphics.Count, layer.Graphics.IndexOf(graphic))                                     };                 uniqueValueRenderer.Infos.Add(valueInfo);             }             return uniqueValueRenderer

View solution in original post

0 Kudos
4 Replies
Cristian_Galindo
Frequent Contributor
Ok fellows, i got it :

            var uniqueValueRenderer = new UniqueValueRenderer();             var defaultSymbol = new ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol { Width = 2.5 };             uniqueValueRenderer.DefaultSymbol = defaultSymbol;             uniqueValueRenderer.Field = attributeField; //parameter              var colorRange = new ColorRange                                  {                                      From = this.GetRandomColor(),                                      To = this.GetRandomColor()                                  };              var rampInterpolator = new RampInterpolator                                        {                                            ColorRange = colorRange                                        };              foreach (var graphic in layer.Graphics)             {                 var valueInfo = new UniqueValueInfo                                     {                                         Label = graphic.Attributes[attributeField].ToString(),                                         Value = graphic.Attributes[attributeField].ToString(),                                         Symbol =                                             rampInterpolator.GetInterpolatedSymbol(                                                 defaultSymbol, graphic, 0, layer.Graphics.Count, layer.Graphics.IndexOf(graphic))                                     };                 uniqueValueRenderer.Infos.Add(valueInfo);             }             return uniqueValueRenderer
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

If you do have services in your solution, you can use the GenerateRendererTask to create your renderer, even for a GraphicsLayer. The renderer it returns does not have to be related to the actual data in the service I believe.

Cheers

Mike
0 Kudos
MichalKowalczuk
Deactivated User

If you do have services in your solution, you can use the GenerateRendererTask to create your renderer, even for a GraphicsLayer.


Hi,
If above is true, what should I pass to Url property when I want to create renderer for a GraphicsLayer. I didn't find this case in API reference and samples.

Mike
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Sorry for the incorrect information - I thought the it was possible to use the GenerateRendererTask independently of the layers within a service by specifying some additional values but it does appear to only work against the source data. It does however work with both the original service layers and additional layers defined through the DynamicLayer capability.

Cheers
0 Kudos