Select to view content in your preferred language

layer selection in Map Service

1584
15
04-25-2013 07:29 AM
Labels (1)
FrancoisGilbert
Deactivated User
This looks like a simple question

Someone prepares a map package in ArcMap and decides to unselect some layers. When I read this map package in my ArcGis runtime component, all the layers are selected. The layer selection done previously is not kept.

Is there a way to keep this layer selection done in the Map package.

François
0 Kudos
15 Replies
FrancoisGilbert
Deactivated User
An answer would be greatly appreciated
0 Kudos
DavidMartin
Frequent Contributor
ESRI.ArcGIS.Client.LayerInfo.DefaultVisibility is probably what you need here. Here's a sample:

http://resources.arcgis.com/en/help/runtime-wpf/samples/index.html#/SubLayer_List/02q20000003t000000...

...where in the code behind, the ArcGISLocalDynamicMapServiceLayer.VisibleLayers is being set on initialization by the method "GetDefaultVisibleLayers", which simply returns an array of Layer IDs, the LayerInfo.DefaultVisibility of which is true.
0 Kudos
FrancoisGilbert
Deactivated User
Here is the source code.
The layers that have not "DefaultVisibility=True" are not added to the visibleLayerIDList which is OK. However, when I display my application with the ESRI:Legend, they all get selected in the table of content. The visibleLayerIDList is filled-up for a layer that is called "DymamicLayer"


        Private Function GetDefaultVisibleLayers(dynamicService As ArcGISLocalDynamicMapServiceLayer) As Integer()
            Try
                Dim visibleLayerIDList As New List(Of Integer)()
                Dim layerInfoArray As ESRI.ArcGIS.Client.LayerInfo() = dynamicService.Layers
                For index As Integer = 0 To layerInfoArray.Length - 1
                    'seulement la configuration statique est sélectionable repli la liste  And layerInfoArray(index).SubLayerIds Is Nothing
                    If dynamicService.ID = "StaticLayers" Then
                        _LayerToSelectDictionary.Add(layerInfoArray(index).Name, layerInfoArray(index).ID)
                        If layerInfoArray(index).SubLayerIds IsNot Nothing Then
                            LayerCombobox.Items.Add(layerInfoArray(index).Name)  'layer group
                        Else
                            LayerCombobox.Items.Add(" -" & layerInfoArray(index).Name)  'layer
                        End If
                    End If
                    If layerInfoArray(index).DefaultVisibility Then
                        visibleLayerIDList.Add(index)   'index
                    End If
                Next
                LayerCombobox.SelectedIndex = 0
                Return visibleLayerIDList.ToArray()

            Catch ex As Exception
                Return Nothing
                MessageBox.Show(ex.Message)
            End Try
          
        End Function
0 Kudos
DavidMartin
Frequent Contributor
If you're using the esri:Legend control as a TOC, then you must have skinned the control by overriding its default DataTemplates.

I'll guess that you have used CheckBoxes in the DataTemplate? So these must have their IsChecked property binding to the IsEnabled property of the LayerItemViewModel class? If this class isn't initializing the IsEnabled property according to the layer visibilities of the Map, then it could be worth calling Legend.Refresh() after you have set the Map's layer visibilities. If that doesn't work, you could always initialize the IsEnabled property in code using the DefaultVisibility previously discussed?

Also worth checking (copied from the doc) :
Note: The Legend.LayerItemsMode Property has great impact on what is displayed in the Legend. For users who want to see the most information available in the Legend, developers should set the LayerItemsMode to Tree. If customizations are made to the MapLayerTemplate and they seem to be overridden at runtime back to a default setting, it is most likely that the LayerItemsMode is set to the default of Flat and it should be set to Tree.
0 Kudos
FrancoisGilbert
Deactivated User
In the XAML code, I have only this below. There are no Datatemplate defined for the legend. Also I think I need to set something like the "check" properties not the "IsEnabled".


            <!--SnapsToDevicePixels="True"-->
            <esri:Legend x:Name="MyLegend"                                         
                         ReverseLayersOrder="True"
                         Map="{Binding ElementName=MyMap}"
                         Refreshed="Legend_Refreshed"/>
0 Kudos
RonaldNatalie
Emerging Contributor
After the layer service has been initialized, you can run down and twiddle the visibility.

Example:
                var map_layer= new ArcGISLocalDynamicMapServiceLayer(map_file_name);

                map_layer.Initialized += (s, e) =>
                {
                      foreach (LayerInfo sublayer in map_layer)  {

                             // figure out if you wan it visible
                             map_layer.SetLayerVisibility(sublayer.ID, visible);
                       }

    
                };

0 Kudos
DavidMartin
Frequent Contributor
@Francois,
I'm no longer clear now by what you mean when you say the layers are selected in the legend. Do you simply mean they're listed when you want them not to be? If this is the case, you can set Legend.ShowOnlyVisibleLayers = true
0 Kudos
FrancoisGilbert
Deactivated User
I do not have any problem with LAYER VISIBILITY, I have problems with LAYER SELECTION.

The layers are all there and they are all visible and are all displayed in the table of content.

What I need is the following ex:

  I have 3 visible layer
  Only the first one has been selected when the user has produced the map package in ArcMap
  My app display the 3 layers and select the 3 of them. Instead, I want to have one the first one selected.

François
0 Kudos
FrancoisGilbert
Deactivated User
Sorry again,

I do have a style defined for the legend for my TOC control. The "IsChecked" property is bound to "IsVisible" but it does not seem to work. When I step to the code, I see that the layers are not visible but once the TOC display, the layers are all selected.
<Grid VerticalAlignment="Center">
      <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" />
      <CheckBox IsChecked="{Binding IsEnabled}" IsEnabled="{Binding IsVisible}" IsHitTestVisible="False" />
</Grid>



            <Style TargetType="esri:Legend">
                <Setter Property="LayerItemsMode" Value="Tree" />
                <Setter Property="ShowOnlyVisibleLayers" Value="False" />

                <Setter Property="MapLayerTemplate" >
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel>
                                <StackPanel.Resources>
                                    <DataTemplate x:Key="BusyIndicatorTemplate">
                                        <Grid x:Name="BusyIndicator" Background="Transparent" Margin="3,0"
                                              HorizontalAlignment="Left" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" >
                                            <Grid.Triggers>
                                                <EventTrigger RoutedEvent="Grid.Loaded">
                                                    <EventTrigger.Actions>
                                                        <BeginStoryboard>
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0:0:1" RepeatBehavior="Forever" To="360" Storyboard.TargetName="BusyIndicator"
                                                             Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </EventTrigger.Actions>
                                                </EventTrigger>
                                            </Grid.Triggers>

                                            <Grid.RenderTransform>
                                                <RotateTransform />
                                            </Grid.RenderTransform>
                                            <Ellipse Fill="#1E525252" Margin="11,2,11,20" Width="2" Height="2"/>
                                            <Ellipse Fill="#3F525252" Height="3" Width="3" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,4,5,0" />
                                            <Ellipse Fill="#7F525252" Width="4" HorizontalAlignment="Right" Height="4" VerticalAlignment="Top" Margin="0,9,1,0" />
                                            <Ellipse Fill="#BF525252" Height="5" Width="5" VerticalAlignment="Bottom" Margin="0,0,3,3" HorizontalAlignment="Right" />
                                            <Ellipse Fill="#FF525252" Height="6" Width="6" VerticalAlignment="Bottom" Margin="9,0" />
                                        </Grid>
                                    </DataTemplate>
                                </StackPanel.Resources>

                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="450">
                                        <TextBlock FontWeight="Bold" Text="{Binding Layer.CopyrightText}" TextWrapping="Wrap" />
                                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
                                        <TextBlock Text="{Binding Layer.Url, StringFormat='Url : {0}'}" />
                                        <TextBlock Text="{Binding MinimumResolution, StringFormat='Minimum Resolution : {0:F6}'}" />
                                        <TextBlock Text="{Binding MaximumResolution, StringFormat='Maximum Resolution : {0:F6}'}" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>

                                <StackPanel Orientation="Horizontal">

                                    <Grid VerticalAlignment="Center">
                                        <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" />
                                        <CheckBox IsChecked="{Binding IsEnabled}" IsEnabled="{Binding IsVisible}" IsHitTestVisible="False" />
                                    </Grid>
                                    <ContentControl ContentTemplate="{StaticResource BusyIndicatorTemplate}"
                                                    Visibility="{Binding BusyIndicatorVisibility}" VerticalAlignment="Center"/>
                                    <Slider Minimum="0" Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="30" VerticalAlignment="Center" />
                                    <TextBlock Text="{Binding Label}" FontWeight="Bold" VerticalAlignment="Center" />
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
0 Kudos