Select to view content in your preferred language

How to deal with a mixture of service layer types?

757
6
06-03-2010 10:17 AM
DougCollins
Regular Contributor
I have a map with several types of service layers (ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer, and FeatureServiceLayers).  I can create a layer list (i.e. TOC) that displays all of the layers in these services, which is fine.  However when I try to add in MapTips for these layers is where I run into trouble. 

If for example I have an <esri:ArcGISDynamicMapServiceLayer> element that has 3 layers, then I must define each layer in that service as an <esri:FeatureLayer> and build the MapTip for this element.  When I do this, I get a red dot as an icon for the FeatureLayer placed on top of the normal icon, and I now get 4 entries to the layer list (TOC).

Is there a way to define the MapTips for the ArcGISDynamicMapServiceLayer without having to add a FeatureLayer element for each layer?

Thanks,
Charlie
0 Kudos
6 Replies
ChrisBradberry
Deactivated User
Charlie,

You can only have maptips with feature layers.  And as you have discovered, the feature layers will duplicate the layers in your services.  It is like making a layer file in ArcMap.  I gave up on map tips and went with an identify function instead.

Chris
0 Kudos
DougCollins
Regular Contributor
Chris,

Thanks for the reply.  Unfortunately the layer list (TOC) and legend are still two areas where the silverlight api lag behind the .net webADF.  A lot of customers still like to see the layer list and want the ability to turn layers on and off.  I still prefer to use the silverlight API though.  It is a big improvement over the .net webADF.

Thanks,
Charlie
0 Kudos
dotMorten_esri
Esri Notable Contributor
"A lot of customers still like to see the layer list and want the ability to turn layers on and off. "

Did you look at this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList as well as this: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LayerList
0 Kudos
SanjayRajput
Deactivated User
Morten, Iam using following sample link example to display my layers in the TOC to turnon and turnoff the layers (in ArcGISDynamicMapServiceLayer).
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SubLayerList

I am able to see the layers list with the checkboxes but when I click on any of the layers checkboxes to turnon or turnoff the layers nothing happens. i.e. Layers are still there on the map. Below is my code snippet. My mxd file contains some group layers also. Is that the problem or anything else. I will appreciate your reply. Sanjay.


<Grid x:Name="LayoutRoot">

        <esri:Map x:Name="MyMap">            

            <esri:ArcGISDynamicMapServiceLayer ID="MyLayers" 
                    Url="http://srajput/arcgis/rest/services/LCEC20/MapServer" 
                    Initialized="ArcGISDynamicMapServiceLayer_Initialized" />
        </esri:Map>

        <Border Background="#779DE26F" BorderThickness="1" CornerRadius="5"
                HorizontalAlignment="Right"  VerticalAlignment="Top"
                Margin="20,20,20,30" Padding="10" BorderBrush="Black">
            <Border.Effect>
                <DropShadowEffect/>
            </Border.Effect>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="15" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <TextBlock Text="Layers in LCEC20" FontWeight="Bold" Grid.Row="0" />
                <ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=MyMap, Path=Layers.[0].Layers}" 
                         Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Margin="2"
                                  Name="MyLayers"
                                  Content="{Binding Name}" 
                                  IsChecked="{Binding DefaultVisibility}" 
                                  Tag="{Binding ID}"
                                  ClickMode="Press" 
                                  Click="CheckBox_Click" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
        </Border>

    </Grid>


CODE BEHIND FILE:

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox tickedCheckBox = sender as CheckBox;

            string serviceName = tickedCheckBox.Name;
            bool visible = (bool)tickedCheckBox.IsChecked;

            int layerIndex = (int)tickedCheckBox.Tag;

            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer = MyMap.Layers[serviceName] as
                ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

            List<int> visibleLayerList =
                dynamicServiceLayer.VisibleLayers != null
                ? dynamicServiceLayer.VisibleLayers.ToList() : new List<int>();

            if (visible)
            {
                if (!visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Add(layerIndex);
            }
            else
            {
                if (visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Remove(layerIndex);
            }

            dynamicServiceLayer.VisibleLayers = visibleLayerList.ToArray();
            
        }

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

        private int[] GetDefaultVisibleLayers(ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicService)
        {
            List<int> visibleLayerIDList = new List<int>();

            ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = dynamicService.Layers;

            for (int index = 0; index < layerInfoArray.Length; index++)
            {
                if (layerInfoArray[index].DefaultVisibility)
                    visibleLayerIDList.Add(index);
            }
            return visibleLayerIDList.ToArray();
        }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
At first glance, your code looks good. So likely the problem is with group layers.
Take care that if a group layer is visible all sublayers are automatically visible as well.
If you want to see only some sublayers of a group layer, remove the groupLayer ID from the visibleLayerList and add the IDs of the sublayers.
0 Kudos
dotMorten_esri
Esri Notable Contributor
I think you are missing a layer.Refresh() in there after setting the LayerIDs?
0 Kudos