How to Bind Multiple Layered Chached map service ArcGIS silver light

1151
4
03-22-2011 08:52 AM
NaveenMaram
New Contributor
Hi All,

I am new to ArcGIS silverlight. I am working on creating an application where i will be having a cached map service with 4 layers( Country, state, county and zip code levels) in it. my requirement is we need to bind this service to the silverlight application and when we zoom to each level and click on state or county or zip code levels, at each level we need to able to select single or multiple state or county or zip code. I have couple of questions in this


  1. whether do i need to use ArcGISTiledMapService layer or ArcGISDyanamicMapservice layer for this.

  2. How can we select each state or county or zip code based on determing which layer we are in.

  3. To select each state or county or zip code do i need to use Graphics layers or anything

Please guide me how this can be implemented or any help links will be much appreciated.

Thanks in advance.

Naveen.
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
1) If the service is cached, use the tiled layer, else use the dynamic.
2) Use Identify and make sure you set the width/height and extent properties to Map.ActualWidth/Height and Map.Extent. That way it will automatically return the state/county/etc based on what's currently visible.
3) If you need to highlight the feature, add the returned geometry/graphic from the Identify result to a graphics layer.
0 Kudos
NaveenMaram
New Contributor
1) If the service is cached, use the tiled layer, else use the dynamic.
2) Use Identify and make sure you set the width/height and extent properties to Map.ActualWidth/Height and Map.Extent. That way it will automatically return the state/county/etc based on what's currently visible.
3) If you need to highlight the feature, add the returned geometry/graphic from the Identify result to a graphics layer.


Hi Morten Nielsen,

Thanks for the reply.

As my map service is Cached service, so i tried using tiled map service layer. with this i am able to view the maps and i am able to zoom in to different layers in the map as well.

But for acheving the point # 3 i have used Graphics layers. for this below are the steps i have followed to implement this.


  1. declared a graphics layer in xaml below my arcGISTiledmapservicelayer with an id.

  2. In xaml code behind in page constructor i declared a querytask and for the querytask i and i have passed state level layer[http://10.12.12334/ArcGIS/rest/services/Europe/MapServer/2] as url and then creating the MyDrawSurface_DrawComplete and QueryTask_Executecompleted and QueryTask_executeFailed methods.

  3. If i am doing this, i am able to select only state, even if i am in country or state or county or zip zoom levels.

  4. But my requirement is if i am in state level then i should only be able to select state level or if i am in county level then i should only be able to select county level or if iam at zip level then i should be able to select only zip level. to achieve this how i need to pass all different layers urls to queryTask. Or If you have any better implementation for this please let me know or any sample code or help links will be helpfull.


Any help links or samples will also be much helpfull.

Thanks In advance.

Naveen.
0 Kudos
dotMorten_esri
Esri Notable Contributor
As you mentioned in step 2, you always query the state layer, so naturally you would never get the other layers back in your query. If you want to use QueryTask for this, you will need to change the endpoint you are querying based on the current resolution/scale.
That's why I suggested you instead use the IdentifyTask instead because this will automatically only query the layers that are visible at a specific scale.
0 Kudos
NaveenMaram
New Contributor
As you mentioned in step 2, you always query the state layer, so naturally you would never get the other layers back in your query. If you want to use QueryTask for this, you will need to change the endpoint you are querying based on the current resolution/scale.
That's why I suggested you instead use the IdentifyTask instead because this will automatically only query the layers that are visible at a specific scale.


Hi Morten Nielsen,

Thanks for your reply.

As you said i have used the IdentifyTask to achieve this, i am able to get the results i required and i am able to display in the results grid, but the problem i am facing is i am not able to highlight the selected country or state or county or zip with diffrent colors. I am not sure what the problem is, for your refference i am pasting my code below

private void MyMap_Click(object sender, Map.MouseEventArgs e)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint clickpoint = e.MapPoint;
            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
               Geometry = clickpoint,
                MapExtent = MyMap.Extent,
                Width = (int)MyMap.Width,
                Height = (int)MyMap.Height,
                LayerOption = LayerOption.visible
            };
            IdentifyTask identifyTask = new IdentifyTask("http://10.12.12334/ArcGIS/rest/services/France/MapServer");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new Graphic()
            {
                Geometry = clickpoint,
                Symbol = ResultsFillSymbol
            };
            graphicsLayer.Graphics.Add(graphic);

        }
  private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
            {
                EditArea.Visibility = Visibility.Visible;
                foreach (IdentifyResult result in args.IdentifyResults)
                {
                    txtName.Text = result.Value.ToString();
                    string[] strZoomLevel = result.LayerName.ToString().Split('.');
                    for (int i = 0; i < strZoomLevel.Length; i++)
                    {
                        if (i == 2){txtZoomLevel.Text = strZoomLevel.ToString();}
                    }
                }
            }
            else
            {
                EditArea.Visibility = Visibility.Collapsed;
            }
           // MyDrawSurface.IsEnabled = false;
        }

        private void IdentifyTask_Failed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Identified failed. Error: " + e.Error);
        }
  
XAML:
<Grid x:Name="LayoutRoot">
            <Grid.Resources>
          <esriSymbols:FillSymbol x:Name="DefaultFillSymbol" >
                <esriSymbols:FillSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Path x:Name="Element" IsHitTestVisible="False" Fill="#66FF0000"
                            Stroke="Red" StrokeThickness="1"/>
                    </ControlTemplate>
                </esriSymbols:FillSymbol.ControlTemplate>
            </esriSymbols:FillSymbol>
            <esriSymbols:FillSymbol x:Name="ResultsFillSymbol">
                <esriSymbols:FillSymbol.ControlTemplate>
                    <ControlTemplate x:Name="CustomPolygonTemplate">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#880000FF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Path x:Name="Element" Stroke="Blue" Fill="#880000FF"
                                StrokeStartLineCap="Round" StrokeThickness="2"
                                StrokeLineJoin="Round" StrokeEndLineCap="Round" />
                        </Grid>
                    </ControlTemplate>
                </esriSymbols:FillSymbol.ControlTemplate>
            </esriSymbols:FillSymbol>
        </Grid.Resources>
            <esri:Map x:Name="MyMap" Background="White" Width="2000" Height="2200" Margin="-600,-130,0,10" MouseClick="MyMap_Click" >
                <esri:Map.Layers>
                    <esri:ArcGISTiledMapServiceLayer ID="BaseMapLayer"
                        Url="http://10.12.12334/ArcGIS/rest/services/France/MapServer"/>
                    <esri:GraphicsLayer ID="MyGraphicLayer"></esri:GraphicsLayer>
                </esri:Map.Layers>
            </esri:Map>
                 <Grid HorizontalAlignment="Right" x:Name="EditArea" Height="250" VerticalAlignment="Bottom" Margin="0,10,10,0" Visibility="Collapsed" >

                <Rectangle   Fill="#ee4b7ba7" Stroke="White"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
                    <Rectangle.Effect>
                        <DropShadowEffect/>
                    </Rectangle.Effect>
                </Rectangle>
                <Rectangle Fill="#FFFFFFFF" Stroke="Black" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
                 <Grid>
                    <Grid.RowDefinitions >
                        <RowDefinition Height="70"></RowDefinition>
                        <RowDefinition Height="100"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="30,20,20,30"  x:Name="EditDetails">
                        <Grid VerticalAlignment="Top" >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="150"></ColumnDefinition>
                                <ColumnDefinition Width="150"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock x:Name="CustomareaName" Width="120" Grid.Row="0" Grid.Column="0"
                                   Text="Custom area Name:" TextAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Bottom" />
                            <TextBox x:Name="txtName" Grid.Row="0"  Grid.Column="1" Height="20"  />
                            <TextBlock x:Name="Zoomlevel" Width="120" Grid.Row="1"  Grid.Column="0"
                                   Text="Zoom Level:" TextAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Bottom" />
                            <TextBox x:Name="txtZoomLevel" Grid.Row="1"  Grid.Column="1"  />
                        </Grid>

                    </StackPanel>
                    <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="top"  >
                        <Button Height="25" Content="Define as custom area"  x:Name="UnionButton" Width="150"
                                  IsEnabled="False" />
                        <Button Height="25" Content="Modify"  x:Name="ModifyButton" Width="70"
                               Visibility="Collapsed"   />
                        <Button Height="25" Content="Delete"  x:Name="DeleteButton" Width="70"
                               Visibility="Collapsed"    />
                    </StackPanel>
                </Grid>
            </Grid>
         
        </Grid>

If i am using i_about.png to display where the user clicks, then i_about image is displaying, but when i tried to highlight the selected country or state or zip as block with different color then i am not able to do it.

Could you please help me in this.

Thanks,
Naveen
0 Kudos