Select to view content in your preferred language

layer selection in Map Service

1481
15
04-25-2013 07:29 AM
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
DavidMartin
Occasional Contributor II
I may be showing my ignorance here, but I don't understand your distinction between a visible layer and a selected layer. If a layer is selected in the TOC (i.e. its checkbox is ticked) then wouldn't you expect it to be visible in the Map? (Unless it was outside its scale range perhaps?)

Your data template also looks rather complicated. For one thing, you have a checkbox that binds its IsEnabled property to the layer's IsVisible property. That would mean that as soon as the layer is no longer visible, you'd have no means by which to make it visible again (because the checkbox would be disabled). I'd refer to the example given here for a useful starting point:

http://resources.arcgis.com/en/help/runtime-wpf/samples/index.html#/Interactive_Legend/02q2000000nr0...
0 Kudos
FrancoisGilbert
Deactivated User
I am the one who got mixed-up. The visible and checked properties are the same. I have got back to a simple form
of esri legend. Still, when I display my map package in ArcMap, I have half of the layer selected. In my ArcGis Runtime map
I always have all the layers selected even if the Property="ShowOnlyVisibleLayers" Value="True"


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

                <Setter Property="MapLayerTemplate" >
                    <Setter.Value>
                        <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
                                    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                    IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>
                            <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
                        </StackPanel>
                    </DataTemplate>
                    </Setter.Value>
                </Setter>                            
               
                <Setter Property="LayerTemplate">
                    <Setter.Value>
                        <DataTemplate>
                        <CheckBox Content="{Binding Label}"
                            IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                            IsEnabled="{Binding IsInScaleRange}" >
                        </CheckBox>
                    </DataTemplate>

                    </Setter.Value>
                </Setter>              
            </Style>
0 Kudos
DavidMartin
Occasional Contributor II
That looks a lot easier to understand! However, refer back to my first post in this thread. It seems that while the visibility of a layer in your map package is captured by LayerInfo.DefaultVisibility, the default for Layer.Visibility is nevertheless always Visible. I'd say you'll therefore need to set your Layer.Visibility explicitly by referring to the relevant LayerInfo.DefaultVisibility. If you do this before your Legend initializes, then I'd imagine you'd see what you'd expect in terms the layer selection therein. If the Legend has already initialized, then you may need to call Legend.Refresh() to get it to sync with the map again (I'm guessing here!).
0 Kudos
FrancoisGilbert
Deactivated User
I think I will need a code example because I am getting lost.
0 Kudos
DavidMartin
Occasional Contributor II
Go to this link and click on "Download Sample Application" (top right)...

http://resources.arcgis.com/en/help/runtime-wpf/samples/index.html#/SubLayer_List/02q20000003t000000...
0 Kudos
FrancoisGilbert
Deactivated User
I finally solved the problem. I have set the layer visibility explicitely in the Legend_Refresh event and now my layers that were not selected in the map package are not selected in my app. It is hard to understand why I need to set the layer visibility when the GetDefaultVisibleLayers sub routine should do the job.



Private Sub Legend_Refreshed(sender As Object, e As Legend.RefreshedEventArgs)
            Try
                ' remove useless base map sublayers
                If TypeOf e.LayerItem.Layer Is ArcGISTiledMapServiceLayer Then
                    e.LayerItem.LayerItems = Nothing
                End If

                'obliger d'ajouter cette partie de code pour déselectionner les layers qui ne sont
                'pas visible dans le map package sinon tous les layer sont sélectionnés

                If Not IsNothing(_currentDynamicServiceLayer) Then

                    For Each sublayer As LayerInfo In _currentDynamicServiceLayer.Layers
                        ' figure out if you wan it visible
                        Dim IsVisible As Boolean
                        IsVisible = False
                        Dim layerInfoArray As ESRI.ArcGIS.Client.LayerInfo() = _currentDynamicServiceLayer.Layers
                        IsVisible = layerInfoArray(sublayer.ID).DefaultVisibility
                        _currentDynamicServiceLayer.SetLayerVisibility(sublayer.ID, IsVisible)
                    Next

                End If

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
           
        End Sub
0 Kudos