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

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

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 WmtsLayer 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 WmtsLayer 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 a WmtsLayer.

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 WmtsLayer 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 WmtsLayer 
       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 WmtsLayer. The use of a ProxyUrl is needed in addition to the regular Url property because the 
        WMTS service is not hosted on a site that provides a cross domain policy file (clientaccesspolicy.xml
        or crossdomain.xml). The InitializationFailed Event is used to notify the user in case the WMTS 
        service is down. The TileLoading Event provides details about individual tiles in the WMTS service
        that is necessary to get the input parameters (Level, Row, Column) of the WmtsLayer.GetTileUrl Method. 
        -->
        <esri:WmtsLayer ID="WMTS1" ServiceMode="KVP" Layer="usa:states"
                        Url="http://v2.suite.opengeo.org/geoserver/gwc/service/wmts"
                        ProxyUrl="http://serverapps.esri.com/SilverlightDemos/ProxyPage/proxy.ashx"
                        InitializationFailed="WmtsLayer_InitializationFailed"
                        TileLoading="WmtsLayer_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 HorizontalAlignment="Left" Margin="239,564,0,208" Name="Label_Row" 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" />
  
  <!-- WmtsLayer.GetTileUrl results. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="32,631,0,0" Name="Label_GetTileUrl" 
             VerticalAlignment="Top" Width="344" Content="WmtsLayer.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 WmtsLayer_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 WmtsLayer_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 WmtsLayer. 
  ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer theWMTSLayer = (ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer)Map1.Layers["WMTS1"];
  
  // Obtain a specific tile Url from the WmtsLayer using the three arguments for the GetTileUrl Method.
  string theGetTileUrl = theWMTSLayer.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 WmtsLayer_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 WmtsLayer_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 WmtsLayer. 
  Dim theWMTSLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer = Map1.Layers("WMTS1")
  
  ' Obtain a specific tile Url from the WmtsLayer using the three arguments for the GetTileUrl Method.
  Dim theGetTileUrl As String = theWMTSLayer.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 WmtsLayer 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 a WMTS 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. As of ArcGIS Server version 10.1, serving WMTS layers as a native REST service is supported.

It is possible to obtain the complete list of various Level, Row, and Column input parameter values that can be used by the GetTileUrl Method by interrogating the XML information returned from a GetCapabilities request in the address bar of a web browser but this is tedious (see the WmtsLayer documentation for a few examples of using the GetCapabilities request). A programmatic way to determine the various Level, Row, and Column information can be obtained by writing some code-behind logic in the WmtsLayer.TileLoading Event (see the code example in this document).

If the ProxyUrl Property has been set to create the WmtsLayer, 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.