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.
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="Bisque" BorderThickness="1"
Background="Blue" 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="Green" 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>
<dataVisualization:RadMap x:Name="myMap" Margin="50">
<dataVisualization:RadMap.Provider>
<telerikMap:BingRestMapProvider x:Name="restProvider"
ApplicationId="Bing_Map_Key"
CalculateElevationCompleted="BingRestMapProvider_CalculateElevationCompleted"
CalculateElevationError="BingRestMapProvider_CalculateElevationError"
Mode="Aerial"/>
</dataVisualization:RadMap.Provider>
<telerikMap:VisualizationLayer x:Name="vizLayer" ItemTemplate="{StaticResource pushTemplate}"/>
</dataVisualization:RadMap>
</Grid>
Example 2: Setting list of locations
public sealed partial class ExamplePage : ExamplePageBase
{
private BindableCollection<ElevationModel> models = new BindableCollection<ElevationModel>();
public ExamplePage()
{
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, 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, BingRestCalculateElevationErrorEventArgs e)
{
var errorMessage = e.Error;
}
}
public class ElevationModel
{
public Location ModelLocation { get; set; }
public double ElevationHeight { get; set; }
}