Skip to main content

BingRouteDataProvider.RouteCalculated Event

Occurs when a route has been calculated.

Namespace: DevExpress.XtraMap

Assembly: DevExpress.XtraMap.v24.2.dll

Declaration

public event BingRouteCalculatedEventHandler RouteCalculated

Event Data

The RouteCalculated event's data class is BingRouteCalculatedEventArgs. The following properties provide information specific to this event:

Property Description
CalculationResult Returns a result of a route calculation.
Cancelled Gets a value indicating whether an asynchronous operation has been canceled. Inherited from AsyncCompletedEventArgs.
Error Gets a value indicating which error occurred during an asynchronous operation. Inherited from AsyncCompletedEventArgs.
UserState Gets the unique identifier for the asynchronous task. Inherited from AsyncCompletedEventArgs.

The event data class exposes the following methods:

Method Description
RaiseExceptionIfNecessary() Raises a user-supplied exception if an asynchronous operation failed. Inherited from AsyncCompletedEventArgs.

Example

View Example

private void OnRouteCalculated(object sender, BingRouteCalculatedEventArgs e) {
    RouteCalculationResult result = e.CalculationResult;
    if((result.RouteResults == null) ||
        (result.ResultCode == RequestResultCode.BadRequest)) {
        rtbResults.Text = "The Bing Route service does not work for this location.";
        return;
    }

    StringBuilder resultList = new StringBuilder("");

    if(result.IntermediatePoints != null) {
        resultList.Append(String.Format("_________________________\n"));

        for(int i = 0; i < e.CalculationResult.IntermediatePoints.Count; i++)
            resultList.Append(
                String.Format("Starting point {0}: {1} ({2})\n",
                i + 1,
                e.CalculationResult.IntermediatePoints[i].Description,
                e.CalculationResult.IntermediatePoints[i].Location)
            );
    }

    if((result.RouteResults != null) & (result.ResultCode == RequestResultCode.Success)) {

        for(int rnum = 0; rnum < e.CalculationResult.RouteResults.Count; rnum++) {
            resultList.Append(String.Format("_________________________\n"));
            resultList.Append(String.Format("Path {0}:\n", rnum + 1));
            resultList.Append(String.Format(
                "Distance: {0}\n",
                e.CalculationResult.RouteResults[rnum].Distance
            ));
            resultList.Append(String.Format(
                "Time: {0}\n",
                e.CalculationResult.RouteResults[0].Time
            ));

            if(e.CalculationResult.RouteResults[rnum].Legs != null) {
                int legNum = 1;
                foreach(BingRouteLeg leg in e.CalculationResult.RouteResults[rnum].Legs) {
                    resultList.Append(String.Format("\tLeg {0}:\n", legNum++));
                    resultList.Append(String.Format("\tDistance: {0}\n", leg.Distance));
                    resultList.Append(String.Format("\tTime: {0}\n", leg.Time));
                    if(leg.Itinerary != null) {
                        foreach(BingItineraryItem itineraryItem in leg.Itinerary) {
                            resultList.Append(String.Format(itineraryItem.Maneuver + "\n"));
                            resultList.Append(String.Format(
                                "\t\tLocation: {0}\n",
                                itineraryItem.Location
                            ));
                        }
                    }
                }
            }
        }
    }
    rtbResults.Text = resultList.ToString();
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the RouteCalculated event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also