Skip to main content

Elevation

  • 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.

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.

Enabling Elevation Requesting

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

The code snippet below shows how this can be done.

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

Using 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.

private void OnClick(object sender, EventArgs e) {    
    elevationProvider.RequestPointsElevations(new GeoPoint { 
        Latitude = Convert.ToDouble(tbLatitude.Text), 
        Longitude = Convert.ToDouble(tbLongitude.Text)
    });
}

Processing Elevation Request Result

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

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)
        });
    }
}

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.