Select to view content in your preferred language

Specify Map Service layers to draw

1258
11
12-09-2010 06:09 AM
JayKappy
Frequent Contributor
WMS I did this

XAML:
<esri:WmsLayer ID="AGSWMSLayer" 
Url="http://serverapps.esri.com/ArcGIS/services/California/MapServer/WMSServer"
Initialized="WmsLayer_Initialized"/>

VB:
Private Sub WmsLayer_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim myWmsLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.WmsLayer
    myWmsLayer = TryCast(MyMap.Layers("AGSWMSLayer"), ESRI.ArcGIS.Client.Toolkit.DataSources.WmsLayer)
    ' You can control the visibility of which WMS layers are displayed by adding the
    ' sub-LayerID's to the String Array. 
    Dim myVisibleWmsLayers() As String = {"0", "1", "2", "3", "4", "5", "6", "7", "8"}
    myWmsLayer.Layers = myVisibleWmsLayers
End Sub


But now I have a ArcGISDynamicMapServiceLayer.....

I cant figure out how to specify which layer draws....this below line has to change...how do I DIM the DynamicMapSerive Layer....As its not a GeoRSSLayer, HeatMapLayer, OpenStreetMapLayer, or WMS Layer
    Dim myWmsLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.WmsLayer

Any thoughts on how to specify individual layers in the Map Service to draw?

Thanks
0 Kudos
11 Replies
JayKappy
Frequent Contributor
I tried this but all three layers drew anyway....
Trying to specify the First layer with the 0

                    <esri:ArcGISDynamicMapServiceLayer ID="MyLOGISLayer"
                     Url="http://gis.logis.org/arcgis/rest/services/SOMESERVER/MapServer/0"/>
0 Kudos
DominiqueBroux
Esri Frequent Contributor

<esri:ArcGISDynamicMapServiceLayer ID="MyLOGISLayer"
Url="http://gis.logis.org/arcgis/rest/services/SOMESERVER/MapServer/0"/>


Due to the trailing '/0', http://gis.logis.org/arcgis/rest/services/SOMESERVER/MapServer/0 is not a map service end point but a feature layer end point. So it can't work.

Try:
<esri:ArcGISDynamicMapServiceLayer ID="MyLOGISLayer"
Url="http://gis.logis.org/arcgis/rest/services/SOMESERVER/MapServer" />

Then if your service is not cached, you can set the property VisibleLayers to filter the visible layers.
0 Kudos
JenniferNery
Esri Regular Contributor
When working with ArcGISDynamicMapServiceLayer, there is a VisibleLayers property that can identify which layers need to be drawn.
API Reference:  http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDyna...
SDK Sample:  http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList
0 Kudos
JayKappy
Frequent Contributor
Bit confused because I am getting two completly different exmaples here...the second one shows how to display all the layers as selectable....
The first gives you a filter...more of what I am looking for...LOOKING at this example you gave me
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDyna...

Although Notice the begining of the vb code
        ' The myArcGISDynamicMapServiceLayer (an ArcGISDynamicServiceLayer object) and TextBlock_VisibleLayers
        ' (a TextBlock object) were defined previously in the XAML or code-behind.
So how am I to know whats going on there?  If I cannot see it...
I want to specify individual layers so I uncommented the two lines to specify which layers to include

Of course I error out:
TextBlock_VisibleLayers

This is obviously being set in the xaml, of which I cannot see in the example???????


XAML
<esri:ArcGISDynamicMapServiceLayer ID="MyLOGISLayer"
 Url="http://gis.logis.org/arcgis/rest/services/SomeServer/MapServer"
 Initialized="LOGIS_Initialized"/>


VB
    Private Sub LOGIS_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ' The myArcGISDynamicMapServiceLayer (an ArcGISDynamicServiceLayer object) and TextBlock_VisibleLayers 
        ' (a TextBlock object) were defined previously in the XAML or code-behind.

        ' Get the first layer in the LayerInfo collection. 
        Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = MyMap.Layers.Item(0)

        ' VisibleLayers (Read/Write)
        ' ==========================

        ' In this example there are three sub-layers (0, 1, 2) that are turned on by default for the 
        ' myArcGISDynamicMapServiceLayer. 

        ' Uncomment the next two lines of code to set only the 2nd and 3rd sub-layers to be visible.
        Dim myVisibleLayers2() As Integer = {1}
        myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers2

        ' Display which sub-layers (via their index number) are visible in a TextBlock.
        Dim myVisibleLayers() As Integer = myArcGISDynamicMapServiceLayer.VisibleLayers
        If myVisibleLayers IsNot Nothing Then
            Dim myVisibleLayersText As String = "Number VisibleLayers: " + myVisibleLayers.Length.ToString
            Dim myVisibleLayersText2 As String = ""
            Dim I2 As Integer
            For I2 = 0 To myVisibleLayers.Length - 1
                myVisibleLayersText2 = myVisibleLayersText2 + " " + myVisibleLayers(I2).ToString
            Next
            TextBlock_VisibleLayers.Text = myVisibleLayersText + ". VisibleLayers ID's: " + myVisibleLayersText2
        Else
            TextBlock_VisibleLayers.Text = "[VisibleLayers not set - Meaning all layers are visible.]"
        End If

    End Sub
0 Kudos
JayKappy
Frequent Contributor
.......................................................................
0 Kudos
JayKappy
Frequent Contributor
Let me scratch the last two entries...

I was able to get this one working...
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList
1. I created another selection box to turn on and off
2. I could not figure out how to get them into my existing layer list box
3. I NEED TO Figure out how to get them in my existing Layer List

This example:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.ArcGISDyna...
1. Was confusing because it was referencing things I could not see.  Including objects on the XAML page.  If you cant see them set up its very hard as a novice to visualize that.
2. I like this option but cant figure out the TextBlock thing that it is referencing....AGAIN I woudl like to push these two my existing layer list...

So with all that I am still looking....I woudl love to get both examples workign as a learning tool for myself...any other thoughts you could provide would be much appreciated...

Thanks


I see that my Layer path to include in the box is not the same as the example
                    <ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
vs
                     <ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=MyMap, Path=Layers.[DynamicLayerCalifornia].Layers}"
Is there a way to combine them to give the simple list and then the breakdown of individual layers in the DynamicLayerCalifornia?


CURRENT LAYER LIST TO DISPLAY LAYERS IN MAP
            <!-- LAYER LIST  -->
            <Grid>
                <Border Background="#996495ED" BorderThickness="1" CornerRadius="5"
            HorizontalAlignment="right"  VerticalAlignment="bottom"
            Margin="10,10,10,10" Padding="5" BorderBrush="red" >

                    <ListBox x:Name="MyList" ItemsSource="{Binding ElementName=MyMap, Path=Layers}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <!--Layer visibility checkbox-->
                                    <CheckBox IsChecked="{Binding Visible, Mode=TwoWay}" />
                                    <!--Opacity slider-->
                                    <Slider Margin="-5,0,0,0" Minimum="0" Maximum="1" Width="30" 
                                Value="{Binding Opacity, Mode=TwoWay}" Height="18" />
                                    <!--Layer name-->
                                    <TextBlock Text="{Binding ID, Mode=OneWay}" Margin="5,0,0,0" > 
                            <!-- Tooltip on hover-->
                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="400">
                                      <!--  <TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
                                        <TextBlock Text="{Binding Description}" TextWrapping="Wrap" />  -->
                                        <TextBlock FontWeight="Bold" Text="HUH" TextWrapping="Wrap" />
                                        <TextBlock Text="WOW" TextWrapping="Wrap" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    
                </Border>
            </Grid>
0 Kudos
JenniferNery
Esri Regular Contributor
The two examples are actually the same in that they both affect the VisibleLayers property.

In the SDK Sample, all sub layers are by default visible until you uncheck them as is done in the CheckBox_Click event handler.

In the API Reference sample, it simply demonstrates how VisibleLayers property can be set.
For example, for a map service with 3 sub layers (ID's 0, 1, 2), you can turn off visibility of ID=0

If you do the following:
MyArcGISDynamicMapServiceLayer.VisibleLayers = New Integer() {1, 2}
0 Kudos
JayKappy
Frequent Contributor
Can we start with the API example:
In the API example I get errors because I dont have an Textblock object...so the line errors out on TextBlock_VisibleLayers.Text
If I remove that part of it where it shows the sub layers and the textblock as seen below it still draws all three layers.

I really appreciate your help here....very apprecaited....

Remove this code block...including this
TextBlock_VisibleLayers.Text = myVisibleLayersText + ". VisibleLayers ID's: " + myVisibleLayersText2



XAML
<esri:ArcGISDynamicMapServiceLayer ID="Logis Layers" 
 Url="http://gis.logis.org/arcgis/rest/services/Something/MapServer"
 Initialized="LOGIS_Initialized"/>


VB
    Private Sub LOGIS_Initialized(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ' Get the first layer in the LayerInfo collection. 
        Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = MyMap.Layers.Item(0)

        ' Uncomment the next two lines of code to set only the 2nd and 3rd sub-layers to be visible.
        Dim myVisibleLayers2() As Integer = {1}
        myArcGISDynamicMapServiceLayer.VisibleLayers = myVisibleLayers2
End Sub
0 Kudos
JenniferNery
Esri Regular Contributor
Take the following for example:
XAML-code:
    <esri:Map x:Name="MyMap" >
            <esri:ArcGISDynamicMapServiceLayer ID="MyLayer" Initialized="ArcGISDynamicMapServiceLayer_Initialized"
                Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" />
    </esri:Map>


Code-behind:
Private Sub ArcGISDynamicMapServiceLayer_Initialized(sender As Object, e As System.EventArgs)
 Dim l As ArcGISDynamicMapServiceLayer = TryCast(sender, ArcGISDynamicMapServiceLayer)
 l.VisibleLayers = New Integer() {0}
End Sub


If all 3 sub layers were visible, it would look like this:
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapSe...

But since in the Initialized event handler, I specified that only sub layer ID=0 is visible, the rest of the layers were not drawn.

I have no idea why this does not work for you because I don't have access to your map service and I'm not sure if the first layer on your map is the ArcGISDynamicMapServiceLayer.


If you intend to get the layer by index it is:
Dim l As ArcGISDynamicMapServiceLayer =  TryCast(Me.MyMap.Layers(0), ArcGISDynamicMapServiceLayer)


But a better practice for retrieving the layer is to get them by ID.
Dim l As ArcGISDynamicMapServiceLayer = TryCast(Me.MyMap.Layers("MyLayer"), ArcGISDynamicMapServiceLayer)
0 Kudos