ArcGIS Runtime SDK for WPF - Library Reference
GetTileUrl Method
See Also  Example
ESRI.ArcGIS.Client.Toolkit.DataSources Namespace > OpenStreetMapLayer Class : GetTileUrl Method

level
Layer level
row
Tile row
col
Tile column
Returns a URL to the specified tile in an OpenStreetMapLayer.

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
)

Remarks

An OpenStreetMapLayer 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 web 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 OpenStreetMapLayer.TileLoading Event (see the code example in this document).

Parameters

level
Layer level
row
Tile row
col
Tile column

Return Value

URL to the tile image

Example

How to use:

After the OpenStreetMapLayer 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 OpenStreetMapLayer 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 OpenStreetMapLayer.

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 OpenStreetMapLayer 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 
    OpenStreetMapLayer 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 an OpenStreetMapLayer. The InitializationFailed Event is used to notify the user in case the 
        OpenStreetMapLayer service is down. The TileLoading Event provides details about individual tiles 
        in the OpenStreetMapLayer service that is necessary to get the input parameters (Level, Row, Column) 
        of the OpenStreetMapLayer.GetTileUrl Method. 
        -->
        <esri:OpenStreetMapLayer ID="myOpenStreetMapLayer" Style="CycleMap"
              InitializationFailed="OpenStreetMapLayer_InitializationFailed"
              TileLoading="OpenStreetMapLayer_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" />
  
  <!-- OpenStreetMapLayer.GetTileUrl results. -->
  <sdk:Label Height="28" HorizontalAlignment="Left" Margin="32,631,0,0" Name="Label_GetTileUrl" 
       VerticalAlignment="Top" Width="344" Content="OpenStreetMapLayer.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 OpenStreetMapLayer_InitializationFailed(object sender, System.EventArgs e)
{
  // Notify the user if there is a failure with the OpenStreetMapLayer service.
  ESRI.ArcGIS.Client.Layer aLayer = (ESRI.ArcGIS.Client.Layer)sender;
  MessageBox.Show(aLayer.InitializationFailure.Message);
}
            
private void OpenStreetMapLayer_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 = (string)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 OpenStreetMapLayer. 
  ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer theOpenStreetMapLayer = (ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer)Map1.Layers["myOpenStreetMapLayer"];
  
  // Obtain a specific tile Url from the OpenStreetMapLayer using the three arguments for the GetTileUrl Method.
  string theGetTileUrl = theOpenStreetMapLayer.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 System.Windows.Media.Imaging.BitmapImage(myUri);
  }
}
VB.NETCopy Code
Private Sub OpenStreetMapLayer_TileLoading(sender As System.Object, 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 OpenStreetMapLayer. 
  Dim theOpenStreetMapLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer = Map1.Layers("myOpenStreetMapLayer")
  
  ' Obtain a specific tile Url from the OpenStreetMapLayer using the three arguments for the GetTileUrl Method.
  Dim theGetTileUrl As String = theOpenStreetMapLayer.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

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.