Select to view content in your preferred language

Radio buttons to toggle layers from a Dynamic map service layer in the legend

3824
10
Jump to solution
09-13-2012 08:49 AM
TanyaOwens
Frequent Contributor
Hi,

I have a application that has several feature layers, a dynamic map service layer and a couple tiled map service layers.  I would like to have the three layers in the dynamic map service layer to be toggled on and off by a radio buttons so only one layer is on at a time. Below is my current code - any help would be greatly appreciated:

MainPage.xaml:
            <esri:Map x:Name="MyMap" Background="White" WrapAround="true" IsLogoVisible="False" Loaded="MyMap_Loaded" Extent="959677,402707,1075561,470675" MouseClick="MyMap_MouseClick">                 <esri:Map.Layers>                     <esri:ArcGISTiledMapServiceLayer ID="AGOLayer"                                                      Url="http://webaddress"/>                                          <esri:ArcGISDynamicMapServiceLayer ID="Attendance Areas"                                                        Opacity=".5"                                                        Url="http://webaddress"/>                                          <esri:ArcGISTiledMapServiceLayer ID="Labels"                                                      Url="http://webaddress"/>                       <esri:FeatureLayer ID="Schools"                                         MouseEnter="FeatureLayer_MouseEnter"                                        MouseLeave="FeatureLayer_MouseLeave"                                        Url="webaddress"                                        OutFields="SCHNAME, ADDRESS, PHONE, URL"/>                      <esri:FeatureLayer ID="Schools Without Attendance Areas"                                         MouseEnter="FeatureLayer_MouseEnter"                                        MouseLeave="FeatureLayer_MouseLeave"                                        Visible="False"                                        Url="http://webaddress"                                        OutFields="SCHNAME, ADDRESS, PHONE, URL"/>                         <esri:GraphicsLayer ID="ResultsGraphicsLayer"/>                     <esri:GraphicsLayer ID="MyGraphicsLayer"/>                     <esri:GraphicsLayer ID="IdentifyIconGraphicsLayer"/>                       <esri:GraphicsLayer ID="AddressToLocationGraphicsLayer">                         <esri:GraphicsLayer.MapTip>                             <Grid Background="LightYellow">                                 <StackPanel Margin="5" >                                     <TextBlock Text="{Binding [Address]}" HorizontalAlignment="Left" />                                     <TextBlock Text="{Binding [LatLon]}" HorizontalAlignment="Left" />                                 </StackPanel>                                 <Border BorderBrush="Black" BorderThickness="1" />                             </Grid>                         </esri:GraphicsLayer.MapTip>                     </esri:GraphicsLayer>                 </esri:Map.Layers>             </esri:Map>


App.xaml:
        <Style TargetType="esri:Legend">             <Setter Property="LayerItemsMode" Value="Flat" />             <Setter Property="LayerTemplate">                 <Setter.Value>                              <DataTemplate>                                 <StackPanel Orientation="Horizontal">                                     <CheckBox Content="{Binding Label}"                           IsChecked="{Binding IsEnabled, Mode=TwoWay}"                           IsEnabled="{Binding IsInScaleRange}" >                                     </CheckBox>                                     </StackPanel>                             </DataTemplate>                 </Setter.Value>             </Setter>             <Setter Property="MapLayerTemplate">                 <Setter.Value>                      <DataTemplate>                         <StackPanel Orientation="Horizontal">                             <CheckBox Content="{Binding Label}"                           IsChecked="{Binding IsEnabled, Mode=TwoWay}"                           IsEnabled="{Binding IsInScaleRange}" >                             </CheckBox>                          </StackPanel>                     </DataTemplate>                 </Setter.Value>              </Setter>         </Style>


MainPage.xaml.cs:

        private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e)         {             LayerItemViewModel removeLayerItemVM = null;              if (e.LayerItem.Layer is ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer)                 e.LayerItem.LayerItems = null;              if (e.LayerItem.LayerItems != null)             {                 foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems)                 {                     if (layerItemVM.IsExpanded)                         layerItemVM.IsExpanded = false;                   }                  if (removeLayerItemVM != null)                     e.LayerItem.LayerItems.Remove(removeLayerItemVM);             }             else             {                 e.LayerItem.IsExpanded = false;             }         }
0 Kudos
10 Replies
TanyaOwens
Frequent Contributor
Ok - One change seems to fixed both problems - I changed LayerItemsMode from flat to tree. Now I don't have the dynamic layer disappearing and it added a check button for the attendance layers to turn all of them on and off.
0 Kudos