Select to view content in your preferred language

Hiding the layers that are not drawn at the present scale

951
3
09-26-2011 02:17 PM
AlirezaAhmadi
Emerging Contributor
I am using Configurable Silverlight Sample Viewer for ArcGIS 2.2. I like to hide layers that are not drawn at the present scale. I do not see Visiblity property for LegendItemInfo. For testing I tried to collapse the visibility of all nodes by this
                        Binding bindIsVisible = new Binding("Visibility");
                        bindIsVisible.Mode = BindingMode.TwoWay;
                        bindIsVisible.Source = Visibility.Collapsed;
                        fLayerNode.SetBinding(TreeViewItem.VisibilityProperty, bindIsVisible);



but it did not work.


 private void CreateDynamicLayerTree(string mapID, LayerLegendInfo legendInfo, TreeViewItem layerNode, LayerInfo[] lyrInfos, List<int> layerIDs, List<int> visibleLayerIDs, bool toggleLayer, bool parentVisible)
        {
            if (legendInfo.LayerLegendInfos != null)
            {
                foreach (LayerLegendInfo layerLegendInfo in legendInfo.LayerLegendInfos)
                {
                    if (layerIDs.IndexOf(layerLegendInfo.SubLayerID) > -1)
                    {
                        LayerInfo lyrInfo = lyrInfos[layerLegendInfo.SubLayerID];
                        bool hasSubLayers = lyrInfo.SubLayerIds != null;
                        bool lyrVisib = (toggleLayer) ? ((visibleLayerIDs.Count > 0) ? false : lyrInfo.DefaultVisibility) : lyrInfo.DefaultVisibility;
                        //MessageBox.Show("layerLegendInfo.LayerName= "  + layerLegendInfo.LayerName + " hasSubLayers= " + hasSubLayers + " lyrVisib=" + lyrVisib + " parentVisible " + parentVisible);
                        if (!hasSubLayers && lyrVisib && parentVisible) visibleLayerIDs.Add(layerLegendInfo.SubLayerID);

                        TreeViewItem fLayerNode = CreateFeatureLayerNode(mapID, lyrInfo.Name, lyrInfo.ID, layerLegendInfo.MinimumScale, layerLegendInfo.MaximumScale, lyrVisib, hasSubLayers, toggleLayer);
                        fLayerNode.ItemTemplate = this.Resources["SymbolTreeNode"] as DataTemplate;
                        fLayerNode.ItemsSource = layerLegendInfo.LegendItemInfos;

                        Binding bindIsVisible = new Binding("Visibility");
                        bindIsVisible.Mode = BindingMode.TwoWay;
                        bindIsVisible.Source = Visibility.Collapsed;
                        fLayerNode.SetBinding(TreeViewItem.VisibilityProperty, bindIsVisible);

                        layerNode.Items.Add(fLayerNode);
                        CreateDynamicLayerTree(mapID, layerLegendInfo, fLayerNode, lyrInfos, layerIDs, visibleLayerIDs, false, lyrVisib && parentVisible);
                    }
                }
            }
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
Did you look at the legend control ?

Sample here : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LegendSimple
0 Kudos
AlirezaAhmadi
Emerging Contributor
Thanks for reply. Yes ,I did see the ESRI legend control , but the ESRI legend control does not have any options to hide layers that are not drawn based on the map scale limit set in MXD. I want to show the layer in the legend if it is in map scale range, and hide it when it is out of the range.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

Yes ,I did see the ESRI legend control , but the ESRI legend control does not have any options to hide layers that are not drawn based on the map scale


There is such an option called 'ShowOnlyVisibleLayers'. The default value is 'true', so by default the legend control should work as you expect.
0 Kudos