Turning on or off individual legend items?

425
3
05-22-2012 06:40 AM
JaredWhite
New Contributor III
Has anyone found a workaround on this yet? There was some talk sometime back that toggling individual legenditems might be possible by discovering the parent objects of individual LegendItems, but that is way beyond my understanding in c#. Has anyone cracked this yet?
0 Kudos
3 Replies
vipulsoni
Occasional Contributor
Has anyone found a workaround on this yet? There was some talk sometime back that toggling individual legenditems might be possible by discovering the parent objects of individual LegendItems, but that is way beyond my understanding in c#. Has anyone cracked this yet?


Yes! This has been done. There is a sample for that.

http://forums.arcgis.com/threads/9141-Get-Layer-Legends-for-Rest-service

download the sample  SilverlightAPILegend.zip�?? from the above post.

the primary method responsible for this task is ---

  private void LayerList_Click(object sender, RoutedEventArgs e)
        {
            CheckBox tickedCheckBox = sender as CheckBox;

          //  string serviceName = tickedCheckBox.Tag.ToString();
            bool visible = (bool)tickedCheckBox.IsChecked;

            //int layerIndex = Int32.Parse(tickedCheckBox.Name);
            int layerIndex = tickedCheckBox.TabIndex;

            List<int> visibleLayerList =
                dynamicLayer.VisibleLayers != null
                ? dynamicLayer.VisibleLayers.ToList() : new List<int>();

            if (visible)
            {
                if (!visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Add(layerIndex);
            }
            else
            {
                if (visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Remove(layerIndex);
            }

            dynamicLayer.VisibleLayers = visibleLayerList.ToArray();
        }
0 Kudos
JaredWhite
New Contributor III
Thanks for the tip.
I'm probably being overly dense here, but how could I apply this to a legend? I had looked into using that sample from the api samples, but the functionality has to be part of the legend in my program.
0 Kudos
vipulsoni
Occasional Contributor
Thanks for the tip.
I'm probably being overly dense here, but how could I apply this to a legend? I had looked into using that sample from the api samples, but the functionality has to be part of the legend in my program.


This sample will help you to get the legend you want. see the attached snapshot from my application.[ATTACH=CONFIG]14589[/ATTACH]
0 Kudos