Generating LayerLegendInfo for Custom Renderer

3455
6
02-09-2012 01:07 PM
christophermire
New Contributor
Hello!

New member, been using esri silverlight API for several months now, but have run into issue.

I have a custom renderer, inheriting from IRenderer, and ILegendSupport.  It works fine, except I can get symbols to display in legend.  I'm using the toolkit legend.

Basically, in QueryLegendInfos, i am creating LayerLegendInfo to send to callback.  LayerLegendInfo has member LegendItemInfo, which has ImageSource property for symbol.  I have my symbol defined in XAML, and ImageSource is expecting bitmap, so how can I convert my symbol to bitmap to assign to ImageSource?

Everything currently works, its in legend, shows label, but no symbol because I'm not sure what to do.  Taking suggestions.  If someone willing to post example custom renderer with legend support for reference, that would be ideal.

Thanks.
0 Kudos
6 Replies
christophermire
New Contributor
I was able to make something work for my project using class breaks renderer, but I'm still curious about writing custom renderer with legend support if anyone has any links or sample code they would like to post.  Thanks.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Sample of a custom implementation of ILegendSupport (with 2 legend swatches):

public class MyCustomLayer : ElementLayer, ILegendSupport
{
     public event EventHandler<EventArgs> LegendChanged;
     public void QueryLegendInfos(Action<LayerLegendInfo> callback, Action<Exception> errorCallback)
    {
        BitmapImage bitmapImage1 = new BitmapImage(new Uri("Images/collapse.png", UriKind.Relative));
        BitmapImage bitmapImage2 = new BitmapImage (new Uri("Images/logo.png", UriKind.Relative));
        var legendItemInfos = new List<LegendItemInfo>
                                {
                                    new LegendItemInfo {Label = "Legend Item1", ImageSource = bitmapImage1},
                                    new LegendItemInfo {Label = "Legend Item2", ImageSource = bitmapImage2}
                                };
         callback(new LayerLegendInfo { LegendItemInfos = legendItemInfos });
    }
}


The BitmapImages can also be defined in XAML instead of code.
0 Kudos
christophermire
New Contributor
Thanks for example.

Is there a way to take esri symbol and generate bitmap from it?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Thanks for example.

Is there a way to take esri symbol and generate bitmap from it?


You can create a SimpleRenderer with the esri symbol and call QueryLegendInfos on this renderer to get the bitmap.

To do it with a list of symbols at once, yo can use an UniqueValueRenderer populated with your symbols and labels, and just call QueryLegendInfos on this renderer.
0 Kudos
christophermire
New Contributor
Thanks.  Ended up using a classbreaks renderer with custom clusterer, but I found your posts useful.
0 Kudos