Select to view content in your preferred language

sublayer List display

714
2
08-20-2010 10:04 AM
TonyAlmeida
MVP Regular Contributor
How do i create a sublayer list like the sample here http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList, but i don't want the layers to be displayed at first i want the option to turn layers on my self. How do i go about doing this?
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
You can replace the ListBox ItemsSource="{Binding ElementName=MyMap, Path=Layers.[DynamicLayerCalifornia].Layers}" with an instance of ObservableCollection<LayerInfo> that gets populated when dynamic layer is initialized. Set the dynamic layer's VisibleLayers to an empty int[]. You also need to remove IsChecked="{Binding DefaultVisibility}" from the CheckBox.

With these minor tweaks in the sample, you can control the sublayer visibility using the listbox.

                <ListBox Margin="0,5,0,0"
                         x:Name="LayerList"                        
                         Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Margin="2"
                                      Name="DynamicLayerCalifornia"
                                      Content="{Binding Name}"                                      
                                      Tag="{Binding ID}"
                                      ClickMode="Press"
                                      Click="CheckBox_Click" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>


        private ObservableCollection<LayerInfo> layers = new ObservableCollection<LayerInfo>();
        public MainPage()
        {
            InitializeComponent();
            this.LayerList.ItemsSource = layers;
        }

        private void ArcGISDynamicMapServiceLayer_Initialized(object sender, EventArgs e)
        {
            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer =
                sender as ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

            foreach (LayerInfo l in dynamicServiceLayer.Layers)
                layers.Add(l);
            dynamicServiceLayer.VisibleLayers = new int[] { };
        }
0 Kudos
TonyAlmeida
MVP Regular Contributor
Thanks for the replay.

I only changed two lines and it works great!

dynamicServiceLayer.VisibleLayers = GetDefaultVisibleLayers(dynamicServiceLayer);

to

dynamicServiceLayer.VisibleLayers = new int[] { };

and

IsChecked="{Binding DefaultVisibility}"

to

IsEnabled="{Binding DefaultVisibility}"
0 Kudos