ArcGIS API for WPF - Library Reference
GetTileUrl Method
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > ArcGISTiledMapServiceLayer Class : GetTileUrl Method

level
Layer level
row
Tile row
col
Tile column
Returns a URL to the specific tile in an ArcGISTiledMapServiceLayer.

Syntax

Visual Basic (Declaration) 
Public Overrides Function GetTileUrl( _
   ByVal level As Integer, _
   ByVal row As Integer, _
   ByVal col As Integer _
) As String
C# 
public override string GetTileUrl( 
   int level,
   int row,
   int col
)

Parameters

level
Layer level
row
Tile row
col
Tile column

Return Value

URL to the tile image

Example

How to use:

After the ArcGISTiledMapServiceLayer loads in the Map Control, the ListBox will be populated with all the combinations of 'Level, Row, and Column' tiles that make up the initial extent of the ArcGISTiledMapServiceLayer image service. Click on any of the combinations in the Listbox and that particular tile will be displayed in an Image Control as well as the Url for that image.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Displaying individual tile images and their URL values for an ArcGISTiledMapServiceLayer.

XAMLCopy Code
<Grid x:Name="LayoutRoot" >
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="78" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="640" 
     TextWrapping="Wrap" Text="After the ArcGISTiledMapServiceLayer loads in the Map Control, the ListBox will be 
     populated with all the combinations of 'Level, Row, and Column' tiles that make up the initial extent of the 
     ArcGISTiledMapServiceLayer image service. Click on any of the combinations in the Listbox and that particular 
     tile will be displayed in an Image Control as well as the Url for that image." />
  
  <!-- The Map Control. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="33,160,0,0" Name="Label_MapControl" 
           VerticalAlignment="Top" Width="120" Content="Map Control:"/>
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="32,180,0,0" Name="Map1" 
          VerticalAlignment="Top" WrapAround="True" Height="320" Width="600">
    <esri:Map.Layers>
      <esri:LayerCollection>
      
        <!-- 
        Add a ArcGISTiledMapServiceLayer. The InitializationFailed Event is used to notify the user in case the 
        ArcGISTiledMapServiceLayer service is down. The TileLoading Event provides details about individual tiles 
        in the ArcGISTiledMapServiceLayer service that is necessary to get the input parameters (Level, Row, Column) 
        of the ArcGISTiledMapServiceLayer.GetTileUrl Method. 
        -->
        <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" 
                                         Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"
                                         InitializationFailed="ArcGISTiledMapServiceLayer_InitializationFailed"
                                         TileLoading="ArcGISTiledMapServiceLayer_TileLoading"/>
        
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
  
  <!-- ListBox results. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="33,512,0,0" Name="Label_ListBox1" 
           VerticalAlignment="Top" Width="194" Content="ListBox Control:"/>
  <ListBox Height="93" HorizontalAlignment="Left" Margin="33,526,0,0" Name="ListBox1" 
         VerticalAlignment="Top" Width="194" SelectionChanged="ListBox1_SelectionChanged"/>
  
  <!-- TiledLayer.TileLoadEventsArgs. Level, Row, and Column. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="239,510,0,0" Name="Label_TileLoadEventArgs" 
           VerticalAlignment="Top" Width="120" Content="TileLoadEventArgs:"/>
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="239,542,0,0" Name="Label_Level" 
           VerticalAlignment="Top" Width="48" Content="Level:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="293,536,0,0" Name="TextBox_Level" 
         VerticalAlignment="Top" Width="52" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="239,569,0,0" Name="Label_Row" 
             VerticalAlignment="Top" Width="48" Content="Row:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="293,566,0,0" Name="TextBox_Row" 
         VerticalAlignment="Top" Width="51" />
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="239,602,0,0" Name="Label_Column" 
           VerticalAlignment="Top" Width="48" Content="Column:" />
  <TextBox Height="23" HorizontalAlignment="Left" Margin="293,596,0,0" Name="TextBox_Column" 
         VerticalAlignment="Top" Width="52" />
  
  <!-- ArcGISTiledMapServiceLayer.GetTileUrl results. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="32,631,0,0" Name="Label_GetTileUrl" 
           VerticalAlignment="Top" Width="344" Content="ArcGISTiledMapServiceLayer.GetTileUrl:"/>
  <TextBox Height="124" HorizontalAlignment="Left" Margin="32,648,0,0" Name="TextBox_GetTileUrl" 
         VerticalAlignment="Top" Width="344" TextWrapping="Wrap"/>
  
  <!-- Image Control results. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="384,508,0,0" Name="Label_ImageControl1" 
           VerticalAlignment="Top" Width="198" Content="Image Control:"/>
  <Image Height="250" HorizontalAlignment="Left" Margin="382,522,0,0" Name="Image1" 
       Stretch="Fill" VerticalAlignment="Top" Width="250" />
  
</Grid>
C#Copy Code
private void ArcGISTiledMapServiceLayer_InitializationFailed(object sender, System.EventArgs e)
{
  // Notify the user if there is a failure with the WMTS service.
  ESRI.ArcGIS.Client.Layer aLayer = (ESRI.ArcGIS.Client.Layer)sender;
  MessageBox.Show(aLayer.InitializationFailure.Message);
}
            
private void ArcGISTiledMapServiceLayer_TileLoading(object sender, ESRI.ArcGIS.Client.TiledLayer.TileLoadEventArgs e)
{
  // This Event will fire for each tile that is loaded in the Map Control. For instance, if it takes 4 tiled images
  // to render the Map Control completely, then this Event will fire 4 times. As you Zoom In or Pan around to other
  // geographic areas in the Map, this Event will continue to fire until all of the tiles have been processed. 
  
  // The e argument of the Event returns a TileLoadEventArgs object.
  ESRI.ArcGIS.Client.TiledLayer.TileLoadEventArgs myTileLoadEventArgs = e;
  
  // Get the Tile's Level, Row, and Column Properties
  int myLevel = myTileLoadEventArgs.Level;
  int myRow = myTileLoadEventArgs.Row;
  int myColumn = myTileLoadEventArgs.Column;
  
  // Generate a string that is comma delimited with the Level, Row, and Column values and add them to a Listbox.
  string myString = myLevel.ToString() + "," + myRow.ToString() + "," + myColumn.ToString();
  
  // Do not add any duplicates.
  if (! (ListBox1.Items.Contains(myString)))
  {
    ListBox1.Items.Add(myString);
  }
}
            
private void ListBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
  // Get the SelectedItem from the Listbox and parse out the Level, Row, and Column arguments necessary to 
  // obtain the Url for a specific tile.
  string theConcatenatedString = ListBox1.SelectedItem;
  string[] theParts = theConcatenatedString.Split(',');
  int theLevel = Convert.ToInt32(theParts[0]);
  int theRow = Convert.ToInt32(theParts[1]);
  int theColumn = Convert.ToInt32(theParts[2]);
  
  // Update the Level, Row, and Column information in the TextBoxes for ease of viewing.
  TextBox_Level.Text = theLevel.ToString();
  TextBox_Row.Text = theRow.ToString();
  TextBox_Column.Text = theColumn.ToString();
  
  // Get the ArcGISTiledMapServiceLayer. 
  ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer theArcGISTiledMapServiceLayer = Map1.Layers["myArcGISTiledMapServiceLayer"];
  
  // Obtain a specific tile Url from the ArcGISTiledMapServiceLayer using the three arguments for the GetTileUrl Method.
  string theGetTileUrl = theArcGISTiledMapServiceLayer.GetTileUrl(theLevel, theRow, theColumn);
  TextBox_GetTileUrl.Text = theGetTileUrl;
  
  // Only process valid restults. 
  if (theGetTileUrl != null)
  {
    // Set the specific tile's Url as the Image's Source. 
    Uri myUri = new Uri(theGetTileUrl);
    Image1.Source = new Imaging.BitmapImage(myUri);
  }
}
VB.NETCopy Code
Private Sub ArcGISTiledMapServiceLayer_InitializationFailed(ByVal sender As System.Object, ByVal e As System.EventArgs)
  
  ' Notify the user if there is a failure with the WMTS service.
  Dim aLayer As ESRI.ArcGIS.Client.Layer = sender
  MessageBox.Show(aLayer.InitializationFailure.Message)
  
End Sub
            
Private Sub ArcGISTiledMapServiceLayer_TileLoading(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.TiledLayer.TileLoadEventArgs)
  
  ' This Event will fire for each tile that is loaded in the Map Control. For instance, if it takes 4 tiled images
  ' to render the Map Control completely, then this Event will fire 4 times. As you Zoom In or Pan around to other
 ' geographic areas in the Map, this Event will continue to fire until all of the tiles have been processed. 
  
  ' The e argument of the Event returns a TileLoadEventArgs object.
  Dim myTileLoadEventArgs As ESRI.ArcGIS.Client.TiledLayer.TileLoadEventArgs = e
  
  ' Get the Tile's Level, Row, and Column Properties
  Dim myLevel As Integer = myTileLoadEventArgs.Level
  Dim myRow As Integer = myTileLoadEventArgs.Row
  Dim myColumn As Integer = myTileLoadEventArgs.Column
  
  ' Generate a string that is comma delimited with the Level, Row, and Column values and add them to a Listbox.
  Dim myString As String = myLevel.ToString + "," + myRow.ToString + "," + myColumn.ToString
  
  ' Do not add any duplicates.
  If Not ListBox1.Items.Contains(myString) Then
    ListBox1.Items.Add(myString)
  End If
  
End Sub
            
Private Sub ListBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
  
  ' Get the SelectedItem from the Listbox and parse out the Level, Row, and Column arguments necessary to 
  ' obtain the Url for a specific tile.
  Dim theConcatenatedString As String = ListBox1.SelectedItem
  Dim theParts As String() = Split(theConcatenatedString, ",")
  Dim theLevel As Integer = CInt(theParts(0))
  Dim theRow As Integer = CInt(theParts(1))
  Dim theColumn As Integer = CInt(theParts(2))
  
  ' Update the Level, Row, and Column information in the TextBoxes for ease of viewing.
  TextBox_Level.Text = theLevel.ToString
  TextBox_Row.Text = theRow.ToString
  TextBox_Column.Text = theColumn.ToString
  
  ' Get the ArcGISTiledMapServiceLayer. 
  Dim theArcGISTiledMapServiceLayer As ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer = Map1.Layers("myArcGISTiledMapServiceLayer")
  
  ' Obtain a specific tile Url from the ArcGISTiledMapServiceLayer using the three arguments for the GetTileUrl Method.
  Dim theGetTileUrl As String = theArcGISTiledMapServiceLayer.GetTileUrl(theLevel, theRow, theColumn)
  TextBox_GetTileUrl.Text = theGetTileUrl
  
  ' Only process valid restults. 
  If theGetTileUrl IsNot Nothing Then
    
    ' Set the specific tile's Url as the Image's Source. 
    Dim myUri As New Uri(theGetTileUrl)
    Image1.Source = New Imaging.BitmapImage(myUri)
    
  End If
  
End Sub

Remarks

A ArcGISTiledMapServiceLayer is made up of multiple tiles (or images) that are automatically put together in a mosaic for display in a Map Control. The tiles are pre-generated on an ArcGIS Server and can be accessed individually via a URL. In order to access the URL for a specific tile it is required to know the Level, Row, and Column information.

A programmatic way to determine the various Level, Row, and Column information can be obtained by writing some code-behind logic in the ArcGISTiledMapServiceLayer.TileLoading Event (see the code example in this document).

If the ProxyURL Property has been set to create the ArcGISTiledMapServiceLayer, then the output return string of the GetTileUrl Method will have that ProxyURL value inserted at the beginning.

Note: Using Methods are only available in code-behind. You cannot use a Method via XAML.

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© ESRI, Inc. All Rights Reserved.