Back to Devexpress

Elevation

wpf-116061-controls-and-libraries-map-control-gis-data-elevation.md

latest5.4 KB
Original Source

Elevation

  • Jul 08, 2025
  • 3 minutes to read

This document explains how to provide a Map control with the capability to obtain elevation information of a location on a map.

The document consists of the following sections.

Important

The Elevation information support is now obsolete. Microsoft deprecated Bing Maps Elevation API on June 30th, 2025. Update your implementation to use alternative solutions.

Overview

The Map control supports the Microsoft Bing Elevation service, allowing you to embed elevation requesting functionality to your map. When this feature is enabled, you can click on the map and obtain elevation information from the service.

The search functionality in the map control is performed by the Bing Search data providers. This provider is represented by the BingElevationDataProvider object. The section below explains how to use the BingElevationDataProvider in the map control.

Enable Elevation Requesting

To enable elevation requesting in the Map control, do the following.

  • Create an information layer and add it to the map.

  • Create an instance of the BingElevationDataProvider and assign it to the InformationLayer.DataProvider property.

  • Specify the Bing Maps key using the BingMapDataProviderBase.BingKey property.

The code snippet below shows how this can be done.

xaml
<dxm:InformationLayer>
    <dxm:BingElevationDataProvider BingKey="{Binding Source={StaticResource bingKey}}" 
                       GenerateLayerItems="False"
                       ProcessMouseEvents="True"
                       ElevationsCalculated="OnElevationsCalculated"/>
</dxm:InformationLayer>

Use a Custom UI

The Map control provides elevation request functionality for several points. Using this approach, you can build a custom request panel to get additional results from the Microsoft Bing Elevation service.

To send an elevation request, call the BingElevationDataProvider.RequestPointElevation or BingElevationDataProvider.RequestPointsElevations method.

For instance, you have a UI that consists of 2 text boxes named “tbLatitude”, “tbLongitude”, and a button named “Request Elevation”. To send a request, click the button. This calls the RequestPointElevation method.

csharp
private void OnClick(object sender, EventArgs e) {    
    elevationProvider.RequestPointsElevations(new GeoPoint { 
        Latitude = Convert.ToDouble(tbLatitude.Text), 
        Longitude = Convert.ToDouble(tbLongitude.Text)
    });
}
vb
Private Sub OnClick(sender As Object, e As EventArgs)
    elevationProvider.RequestPointsElevations(New GeoPoint() With { _
        .Latitude = Convert.ToDouble(tbLatitude.Text), _
        .Longitude = Convert.ToDouble(tbLongitude.Text) _
    })
End Sub

Process Elevation Request Result

To get the results for the request, handle the BingElevationDataProvider.ElevationsCalculated event, as shown below.

csharp
private void OnElevationsCalculated(object sender, ElevationsCalculatedEventArgs e) {
    if(e.Cancelled == true || e.Error != null) return;
    if(e.Result.ResultCode != RequestResultCode.Success) return;

    itemStorage.Items.Clear();
    // foreach requested location create a new callout with elevation value.
    foreach(ElevationInformation elevationResult in e.Result.Locations) {
        itemStorage.Items.Add(new MapPushpin {
            Location = elevationResult.Location,
            ToolTipPattern = String.Format("Elevation: {0}m.", elevationResult.Elevation)
        });
    }
}
vb
Private Sub OnElevationsCalculated(ByVal sender As Object, ByVal e As ElevationsCalculatedEventArgs)
    If e.Cancelled = True OrElse e.Error IsNot Nothing Then
        Return
    End If
    If e.Result.ResultCode <> RequestResultCode.Success Then
        Return
    End If

    itemStorage.Items.Clear()
    ' foreach requested location create a new callout with elevation value.
    For Each elevationResult As ElevationInformation In e.Result.Locations
        itemStorage.Items.Add(New MapPushpin With {.Location = elevationResult.Location, .ToolTipPattern = String.Format("Elevation: {0}m.", elevationResult.Elevation)})
    Next elevationResult
End Sub

In the code above, the ElevationsCalculatedEventArgs.Result property is used to obtain the request results. The ElevationRequestResult.Locations property stores the elevation data for the points that had to be sent in the request.

See Also

DevExpress Map Control for WPF: Migrate from Bing Maps to Azure Maps