Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to adjust my Print Widget so that raster layers do not show up in the legend. My thinking was that I could test for a layer type and not add the item to the legend if it is a raster.

Something like:

Foreach (layer in List<Layers>)
    If layer is a raster:
        do nothing;
    Else: 
        Add it to the legend;

I know there's a LayerInfo thing out there but I'm not really sure how to use it. Incidentally, I'm new to C#/Silverlight/ArcGIS for Server so this simple task is a bit challenging for me. I did notice there was a GetType() method(?) that I might be able to use but I'm not sure if how if that is indeed the answer. The foreach legend item code already exists and such -- I'm looking to wrap some conditions around the legendItems.Add bit. I found the following resources, but not sure how to use them if they are helpful... http://help.arcgis.com/en/webapi/sil...o_members.html --> the "Type" property, perhaps?

Alternatively, if I'm going about this in a difficult/wrong way, feel free to point that out! I'm a new intern with no prior C#/ArcGIS Server/Silverlight experience so it's all a bit overwhelming.

Thanks in advance!

Thread on arcgis forums: http://forums.arcgis.com/threads/83788-How-do-I-retrieve-layer-type

additional thoughts: -- I'll somehow have to create a list of all the layers, too >_<.

share|improve this question
add comment

1 Answer 1

The code below is taken from the Legend With Templates sample under the Toolkit Controls section. Notice how the legend item named "states" gets removed. You could do the same thing for your raster layer, but instead of checking its label, check to see if layerItemVM.Layer is ArcGISImageServiceLayer See documentation on the is operator for more explanation.

using System.Windows.Controls;
using ESRI.ArcGIS.Client.Toolkit;
using ESRI.ArcGIS.Client.Toolkit.Primitives;

namespace ArcGISSilverlightSDK
{
    public partial class LegendWithTemplates : UserControl
    {
        public LegendWithTemplates()
        {
            InitializeComponent();
        }

        private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)
        {
            LayerItemViewModel removeLayerItemVM = null;

            if (e.LayerItem.LayerItems != null)
            {
                foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)
                {
                    if (layerItemVM.IsExpanded)
                        layerItemVM.IsExpanded = false;

                    if (layerItemVM.Label == "states")
                        removeLayerItemVM = layerItemVM;
                }

                if (removeLayerItemVM != null)
                    e.LayerItem.LayerItems.Remove(removeLayerItemVM);
            }
            else
            {
                e.LayerItem.IsExpanded = false;
            }
        }
    }
}
share|improve this answer
    
I could kiss you for pointing me in this direction! It's a brilliant idea. This has contributed to my understanding of how all this ArcGIS Server stuff works (mostly the image service aspect). Thank you! You mentioned testing the layerItemVM.Layer -- I'm not sure how to get the ".Layer" thing working or what's even really meant by that. If you don't mind me troubling you further, could you shed some light on this? –  Jenn May 6 '13 at 17:40
    
Hmm, it doesn't seem like "if maplayer.Layers is ArcGISImageServiceLayer" is a valid test. "The given expression is never of the provided ('ESRI.ArcGIS.Client.ArcGISImageServiceLayer') type". And .Layers doesn't have a "definition or extension method" in the ArcGISImageServiceLayer. –  Jenn May 6 '13 at 21:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.