Edit this page

Elevation

RadMap Bing Elevation Service allows you to obtain elevation information of a location on a map. You can get the elevation information for a set of locations, polyline or area on the Earth. You can access the elevation service via BingRestMapProvider provider.

The RadMap built-in elevation service wraps the Elevation API of the Bing Maps Rest services.

Rad Rest Map Routing Example

In order to get the elevation data you can create instance of the BingRestElevationRequest object. Then you can call the CalculateElevationAsync() method of the BingRestMapProvider which uses the request object as a parameter. Then you can subscribe to the BingRestMapProvider's CalculateElevationCompleted and CalculateElevationError event. You can take a look at the following steps:

  • Set the ApplicationId property of the BingRestMapProvider. This property represents a key, which allows you to use the Bing Rest Maps services.

    Without supplying a valid key you won't be able to visualize the map inside the RadMap control. In order to learn how to obtain one, please read Accessing the Control Using a Bing Maps.

  • Create instance of the BingRestRouteRequest object

  • Handle CalculateElevationCompleted and CalculateElevationError events of the BingRestMapProvider
  • Call CalculateElevationAsync() method of the BingRestRouteRequest and provide the request as a parameter

You can customize the BingRestElevationRequest object by setting the following properties.

  • ElevationType: A property of type BingRestElevationRequestType that gets or sets the type of the elevation to be calculated. This mode is enumeration and it allows the following values.
    • List: Get elevations for latitude and longitude coordinates. Required parameters of the BingRestElevationRequest object Points property.
    • Polyline: Get elevations at equally-spaced locations along a polyline path. Required parameters of the BingRestElevationRequest object Points and Samples properties.
    • Bounds: Get elevations at equally-spaced locations within an area on the Earth defined as a bounding box. Required parameters of the BingRestElevationRequest object Bounds, Rows, Columns properties.
    • SeaLevel: Get the offset of the geoid sea level Earth model from the ellipsoid Earth model at a set of latitude and longitude coordinates. Required parameters of the BingRestElevationRequest object Points property.
  • HeightsType: A property of type BingRestElevationHeightsType that gets or sets the elevation heights type used in the elevation service request. This mode is enumeration and it allows the following values.
    • SeaLevel: Use the geoid Earth model (EGM2008 2.5').
    • Ellipsoid: Use the ellipsoid Earth model (WGS84).
  • Points: Gets or sets a set of coordinates on the Earth to use in elevation calculations. The exact use of these points depends on the type of elevation request.
  • Bounds: Gets or sets the rectangular area over which to provide elevation values.
  • Rows: Gets or sets the number of rows to use to divide the bounding box area into a grid. The rows that define the bounding box each count as two (2) of the rows. Elevation values are returned for all vertices of the grid. Integers with a value of two 2 or greater. The number of rows and columns can define a maximum of 1024 locations (rows * cols <= 1024).
  • Columns: Gets or sets the number of columns to use to divide the bounding box area into a grid. The columns that define the bounding box each count as two (2) of the columns. Elevation values are returned for all vertices of the grid. Integers with a value of two 2 or greater. The number of rows and columns can define a maximum of 1024 locations (rows * cols <= 1024).
  • Samples: Gets or sets the number of equally-spaced elevation values to provide along with a polyline path. A positive integer. The maximum number of samples is 1024.

Get elevations for list of points

When the ElevationType enumeration is set to List the ElevationRequest gets elevations for given list of latitude and longitude coordinates. Elevations are returned for each set of coordinates.

Example 1: Defining BingRestMapProvider in XAML

 <Grid>
    <Grid.Resources>
        <DataTemplate x:Key="pushTemplate">
            <Grid VerticalAlignment="Top" HorizontalAlignment="Center" MinWidth="50">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Border BorderBrush="{telerik:Windows8Resource ResourceKey=AccentBrush}" BorderThickness="1" 
                        Background="{telerik:Windows8Resource ResourceKey=AccentBrush}"  UseLayoutRounding="True">
                    <TextBlock Margin="4 2" Text="{Binding ElevationHeight}" Foreground="White" FontFamily="Segoe UI" FontSize="11" HorizontalAlignment="Center"/>
                </Border>
                <Path Data="M0,0L7,14L14,0" Fill="{telerik:Windows8Resource ResourceKey=AccentBrush}" Stretch="Fill" 
                      Width="14" Height="7" UseLayoutRounding="True" Stroke="Black"
                      VerticalAlignment="Bottom" HorizontalAlignment="Center"  Grid.Row="1" Margin="0 -1 0 0"/>
            </Grid>
        </DataTemplate>
    </Grid.Resources>
    <telerik:RadMap x:Name="myMap">
        <telerik:RadMap.Provider>
            <telerik:BingRestMapProvider x:Name="restProvider"                 
                                         ApplicationId="Bing_Key"
                                         CalculateElevationCompleted="BingRestMapProvider_CalculateElevationCompleted"
                                         CalculateElevationError="BingRestMapProvider_CalculateElevationError"
                                         Mode="Aerial"/>
        </telerik:RadMap.Provider>
        <telerik:VisualizationLayer x:Name="vizLayer" ItemTemplate="{StaticResource pushTemplate}"/>
    </telerik:RadMap>
</Grid>

Example 2: Setting list of locations

public partial class MainWindow : Window
{
    private ObservableCollection<ElevationModel> models = new ObservableCollection<ElevationModel>();
    public MainWindow()
    {
        InitializeComponent();
        this.myMap.Center = new Location(46.9481529297053, 10.9671020507813);
        this.myMap.ZoomLevel = 13;
        models.Add(new ElevationModel() { ModelLocation = new Location(46.9421687679625, 10.9677565097809) });
        models.Add(new ElevationModel() { ModelLocation = new Location(46.9189765706718, 10.9194660186768) });
        models.Add(new ElevationModel() { ModelLocation = new Location(46.923684692032, 10.921847820282) });
        models.Add(new ElevationModel() { ModelLocation = new Location(46.968539, 11.008300) });
        models.Add(new ElevationModel() { ModelLocation = new Location(46.9774489498581, 10.9834121062829) });

        BingRestElevationRequest request = new BingRestElevationRequest();
        request.HeightsType = BingRestElevationHeightsType.SeaLevel;
        request.ElevationType = BingRestElevationRequestType.List;
        request.Points = models.Select(x => x.ModelLocation).ToList();
        this.restProvider.CalculateElevationAsync(request);
    }

    private void BingRestMapProvider_CalculateElevationCompleted(object sender, Telerik.Windows.Controls.Map.BingRestElevationCompletedEventArgs e)
    {
        for (int i = 0; i < e.Elevations[0].Elevations.Count(); i++)
        {
            models[i].ElevationHeight = e.Elevations[0].Elevations[i];
        }
        this.vizLayer.ItemsSource = this.models;
    }

    private void BingRestMapProvider_CalculateElevationError(object sender, Telerik.Windows.Controls.Map.BingRestCalculateElevationErrorEventArgs e)
    {
        MessageBox.Show(e.Error.ToString());
    }
}
public class ElevationModel
{
    public Location ModelLocation { get; set; }
    public double ElevationHeight { get; set; }
}
Class MainWindow
    Private models As New ObservableCollection(Of ElevationModel)()
    Public Sub New()
        InitializeComponent()
        Me.myMap.Center = New Location(46.9481529297053, 10.9671020507813)
        Me.myMap.ZoomLevel = 13
        Dim locationOne = New ElevationModel()
        locationOne.ModelLocation = New Location(46.9421687679625, 10.9677565097809)
        Dim locationTwo = New ElevationModel()
        locationTwo.ModelLocation = New Location(46.9189765706718, 10.9194660186768)
        Dim locationThree = New ElevationModel()
        locationThree.ModelLocation = New Location(46.923684692032, 10.921847820282)
        Dim locationFour = New ElevationModel()
        locationFour.ModelLocation = New Location(46.968539, 11.0083)
        Dim locationFive = New ElevationModel()
        locationFive.ModelLocation = New Location(46.9774489498581, 10.9834121062829)
        models.Add(locationOne)
        models.Add(locationTwo)
        models.Add(locationThree)
        models.Add(locationFour)
        models.Add(locationFive)
        Dim request As New BingRestElevationRequest()
        request.HeightsType = BingRestElevationHeightsType.SeaLevel
        request.ElevationType = BingRestElevationRequestType.List
        request.Points = models.Select.ToList()
        Me.restProvider.CalculateElevationAsync(request)
    End Sub
    Private Sub BingRestMapProvider_CalculateElevationCompleted(sender As Object, e As Telerik.Windows.Controls.Map.BingRestElevationCompletedEventArgs)
        For i As Integer = 0 To e.Elevations(0).Elevations.Count() - 1
            models(i).ElevationHeight = e.Elevations(0).Elevations(i)
        Next
        Me.vizLayer.ItemsSource = Me.models
    End Sub

    Private Sub BingRestMapProvider_CalculateElevationError(sender As Object, e As Telerik.Windows.Controls.Map.BingRestCalculateElevationErrorEventArgs)
        MessageBox.Show(e.Error.ToString)
    End Sub
End Class
Class ElevationModel
    Private m_ModelLocation As Location
    Public Property ModelLocation() As Location
        Get
            Return m_ModelLocation
        End Get
        Set
            m_ModelLocation = Value
        End Set
    End Property
    Public Property ElevationHeight() As Double
        Get
            Return m_ElevationHeight
        End Get
        Set
            m_ElevationHeight = Value
        End Set
    End Property
    Private m_ElevationHeight As Double
End Class

See Also