Back to Devexpress

BingItineraryItem.Maneuver Property

windowsforms-devexpress-dot-xtramap-dot-bingitineraryitem-cec4ae2c.md

latest20.2 KB
Original Source

BingItineraryItem.Maneuver Property

Gets the maneuver type associated with the itinerary item.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public BingManeuverType Maneuver { get; }
vb
Public ReadOnly Property Maneuver As BingManeuverType

Property Value

TypeDescription
BingManeuverType

A BingManeuverType enumeration value specifying the maneuver type.

|

Available values:

Show 62 items

NameDescription
None

No maneuver.

| | Unknown |

Unknown maneuver.

| | DepartStart |

Depart the first stop on the route.

| | DepartIntermediateStop |

Depart an intermediate stop on the route.

| | DepartIntermediateStopReturning |

Return to an intermediate stop on the route.

| | ArriveFinish |

Arrive at the last stop in the route.

| | ArriveIntermediateStop |

Arrive at an intermediate stop in the route.

| | TurnLeft |

Turn left.

| | TurnRight |

Turn right.

| | TurnBack |

Turn around.

| | UTurn |

Take a U-turn.

| | TurnToStayLeft |

Turn then stay left.

| | TurnToStayRight |

Turn then stay right.

| | BearLeft |

Bear left.

| | BearRight |

Bear right.

| | KeepToStayLeft |

Keep on the current road then stay left.

| | KeepToStayRight |

Keep on the current road then stay right.

| | KeepToStayStraight |

Keep on the current road then go straight.

| | KeepLeft |

Keep left.

| | KeepRight |

Keep right.

| | KeepStraight |

Keep straight.

| | Take |

Take a new road.

| | TakeRampLeft |

Take a ramp left.

| | TakeRampRight |

Take a ramp right.

| | TakeRampStraight |

Take a ramp straight ahead.

| | KeepOnrampLeft |

Keep on the left side of the ramp.

| | KeepOnrampRight |

Keep on the right side of the ramp.

| | KeepOnrampStraight |

Keep straight ahead on the ramp.

| | Merge |

Merge onto another road.

| | Continue |

Continue along the current road.

| | RoadNameChange |

The road name has changed.

| | EnterRoundabout |

Enter a roundabout.

| | ExitRoundabout |

Exit a roundabout.

| | TurnRightThenTurnRight |

Turn right then turn right.

| | TurnRightThenTurnLeft |

Turn right then turn left.

| | TurnRightThenBearRight |

Turn right then bear right.

| | TurnRightThenBearLeft |

Turn right then bear left.

| | TurnLeftThenTurnLeft |

Turn left then turn left.

| | TurnLeftThenTurnRight |

Turn left then turn right.

| | TurnLeftThenBearLeft |

Turn left then bear left.

| | TurnLeftThenBearRight |

Turn left then bear right.

| | BearRightThenTurnRight |

Bear right then turn right.

| | BearRightThenTurnLeft |

Bear right then turn left.

| | BearRightThenBearRight |

Bear right then bear right.

| | BearRightThenBearLeft |

Bear right then bear left.

| | BearLeftThenTurnLeft |

Bear left then turn left.

| | BearLeftThenTurnRight |

Bear left then turn right.

| | BearLeftThenBearRight |

Bear left then bear right.

| | BearLeftThenBearLeft |

Bear left then bear left.

| | RampThenHighwayRight |

Take a ramp to the highway on the right.

| | RampThenHighwayLeft |

Take a ramp to the highway on the left.

| | RampToHighwayStraight |

Take a ramp to the highway straight ahead.

| | EnterThenExitRoundabout |

Enter then exit a roundabout.

| | BearThenMerge |

Bear then merge onto another road.

| | TurnThenMerge |

Turn then merge onto another road.

| | BearThenKeep |

Bear then keep on the current road.

| | Transfer |

Transfer from one transit to another.

| | Wait |

Wait.

| | TakeTransit |

Take transit.

| | Walk |

Walk.

| | TurnLeftSharp |

Turn sharp left.

| | TurnRightSharp |

Turn sharp right.

|

Example

This example calculates routes to the destination point from major roads. For this do the following.

  • To calculate routes from major roads the BingRouteDataProvider.CalculateRoutesFromMajorRoads method should be called. In this example it is called in the Calculate Routes From Major Roads button click event handler.

  • To process request result the BingRouteDataProvider.RouteCalculated event should be handled. The requested results contain the total distance of a route, itinerary item (BingRouteResult.Distance, BingRouteLeg.Distance, BingItineraryItem.Distance), the time required to follow the calculated route (BingRouteResult.Time) and pass the route leg and itinerary item (BingRouteLeg.Time, BingItineraryItem.Time). You can also see the maneuvers associated with the itinerary item (BingItineraryItem.Maneuver) and other parameters.

  • To customize map items generated by the BingRouteDataProvider object (because the InformationDataProviderBase.GenerateLayerItems property value is true by default) the InformationDataProviderBase.LayerItemsGenerating event should be handled.

  • Form1.cs

  • Form1.vb

csharp
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraMap;

namespace CalculateRoutesFromMajorRoads {
    public partial class Form1 : Form {
        const double minLat = -90;
        const double maxLat = 90;
        const double minLon = -180;
        const double maxLon = 180;

        const string yourBingKey = "Insert Your Bing Key Here";//"Your Bing Key";

        double lat = 40;
        double lon = -120;
        BingRouteDataProvider routeProvider;

        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            imageProvider.BingKey = yourBingKey;

            routeProvider = new BingRouteDataProvider { BingKey = yourBingKey };
            routeProvider.LayerItemsGenerating += OnLayerItemsGenerating;
            routeProvider.RouteCalculated += OnRouteCalculated;
            informationLayer.DataProvider = routeProvider;
            informationLayer.DataRequestCompleted += OnDataRequestCompleted;

            teLatitude.Text = lat.ToString();
            teLongitude.Text = lon.ToString();
            #region #InitBingRouteOptions
            cbeTravelMode.Properties.Items.AddRange(Enum.GetValues(typeof(BingTravelMode)));
            cbeTravelMode.SelectedIndex = 0;
            cbeRouteOptimization.Properties.Items.AddRange(Enum.GetValues(typeof(BingRouteOptimization)));
            cbeRouteOptimization.SelectedIndex = 0;
            #endregion #InitBingRouteOptions
        }

        #region #LayerItemsGenerating
        void OnLayerItemsGenerating(object sender, LayerItemsGeneratingEventArgs e) {
            foreach(MapItem item in e.Items) {
                MapPolyline polyline = item as MapPolyline;
                if(polyline != null) {
                    polyline.Stroke = Color.FromArgb(0xFF, 0x00, 0x72, 0xC6);
                    polyline.StrokeWidth = 4;
                }
            }
        }
        #endregion #LayerItemsGenerating

        #region #DataRequestCompleted
        void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
            mapControl.ZoomToFitLayerItems(0.4);
        }
        #endregion #DataRequestCompleted

        #region #BingRouteOptionsChanged
        private void OnTravelModeSelectedIndexChanged(object sender, EventArgs e) {
            routeProvider.RouteOptions.Mode = (BingTravelMode)cbeTravelMode.SelectedItem;
        }

        private void OnRouteOptimizationSelectedIndexChanged(object sender, EventArgs e) {
            routeProvider.RouteOptions.RouteOptimization = (BingRouteOptimization)cbeRouteOptimization.SelectedItem;
        }
        #endregion #BingRouteOptionsChanged

        void ShowErrorMessage(string variable, double minVal, double maxVal) {
            MessageBox.Show(
                        this,
                        String.Format(
                            "The {0} value shoud be larger or equals {1} and less or equals {2}.",
                            variable,
                            minVal,
                            maxVal
                        ),
                        variable
                    );
        }

        private void OnLatitudeValidating(object sender, CancelEventArgs e) {
            if(!Double.TryParse(teLatitude.Text, out lat) ||
                (lat > maxLat) || (lat < minLat)) {
                e.Cancel = true;
                ShowErrorMessage("Latitude", minLat, maxLat);
            }
        }

        private void OnLongitudeValidating(object sender, CancelEventArgs e) {
            if(!Double.TryParse(teLongitude.Text, out lon) ||
                (lon > maxLon) || (lon < minLon)) {
                e.Cancel = true;
                ShowErrorMessage("Longitude", minLon, maxLon);
            }
        }

        private void OnCalculateRoutesClick(object sender, EventArgs e) {
            RouteWaypoint targetPoint = new RouteWaypoint("Searched location", new GeoPoint(lat, lon));
            routeProvider.CalculateRoutesFromMajorRoads(targetPoint);
        }

        #region #RouteCalculated
        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();
        }
        #endregion #RouteCalculated
    }
}
vb
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraMap

Namespace CalculateRoutesFromMajorRoads
    Partial Public Class Form1
        Inherits Form

        Private Const minLat As Double = -90
        Private Const maxLat As Double = 90
        Private Const minLon As Double = -180
        Private Const maxLon As Double = 180

        Private Const yourBingKey As String = "Insert Your Bing Key Here" '"Your Bing Key";

        Private lat As Double = 40
        Private lon As Double = -120
        Private routeProvider As BingRouteDataProvider

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            imageProvider.BingKey = yourBingKey

            routeProvider = New BingRouteDataProvider With {.BingKey = yourBingKey}
            AddHandler routeProvider.LayerItemsGenerating, AddressOf OnLayerItemsGenerating
            AddHandler routeProvider.RouteCalculated, AddressOf OnRouteCalculated
            informationLayer.DataProvider = routeProvider
            AddHandler informationLayer.DataRequestCompleted, AddressOf OnDataRequestCompleted

            teLatitude.Text = lat.ToString()
            teLongitude.Text = lon.ToString()
' #Region "#InitBingRouteOptions"
            cbeTravelMode.Properties.Items.AddRange(System.Enum.GetValues(GetType(BingTravelMode)))
            cbeTravelMode.SelectedIndex = 0
            cbeRouteOptimization.Properties.Items.AddRange(System.Enum.GetValues(GetType(BingRouteOptimization)))
            cbeRouteOptimization.SelectedIndex = 0
' #End Region ' #InitBingRouteOptions
        End Sub

        #Region "#LayerItemsGenerating"
        Private Sub OnLayerItemsGenerating(ByVal sender As Object, ByVal e As LayerItemsGeneratingEventArgs)
            For Each item As MapItem In e.Items
                Dim polyline As MapPolyline = TryCast(item, MapPolyline)
                If polyline IsNot Nothing Then
                    polyline.Stroke = Color.FromArgb(&HFF, &H0, &H72, &HC6)
                    polyline.StrokeWidth = 4
                End If
            Next item
        End Sub
        #End Region ' #LayerItemsGenerating

        #Region "#DataRequestCompleted"
        Private Sub OnDataRequestCompleted(ByVal sender As Object, ByVal e As RequestCompletedEventArgs)
            mapControl.ZoomToFitLayerItems(0.4)
        End Sub
        #End Region ' #DataRequestCompleted

        #Region "#BingRouteOptionsChanged"
        Private Sub OnTravelModeSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbeTravelMode.SelectedIndexChanged
            routeProvider.RouteOptions.Mode = CType(cbeTravelMode.SelectedItem, BingTravelMode)
        End Sub

        Private Sub OnRouteOptimizationSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbeRouteOptimization.SelectedIndexChanged
            routeProvider.RouteOptions.RouteOptimization = CType(cbeRouteOptimization.SelectedItem, BingRouteOptimization)
        End Sub
        #End Region ' #BingRouteOptionsChanged

        Private Sub ShowErrorMessage(ByVal variable As String, ByVal minVal As Double, ByVal maxVal As Double)
            MessageBox.Show(Me, String.Format("The {0} value shoud be larger or equals {1} and less or equals {2}.", variable, minVal, maxVal), variable)
        End Sub

        Private Sub OnLatitudeValidating(ByVal sender As Object, ByVal e As CancelEventArgs) Handles teLatitude.Validating
            If (Not Double.TryParse(teLatitude.Text, lat)) OrElse (lat > maxLat) OrElse (lat < minLat) Then
                e.Cancel = True
                ShowErrorMessage("Latitude", minLat, maxLat)
            End If
        End Sub

        Private Sub OnLongitudeValidating(ByVal sender As Object, ByVal e As CancelEventArgs) Handles teLongitude.Validating
            If (Not Double.TryParse(teLongitude.Text, lon)) OrElse (lon > maxLon) OrElse (lon < minLon) Then
                e.Cancel = True
                ShowErrorMessage("Longitude", minLon, maxLon)
            End If
        End Sub

        Private Sub OnCalculateRoutesClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnCalculateRoutes.Click
            Dim targetPoint As New RouteWaypoint("Searched location", New GeoPoint(lat, lon))
            routeProvider.CalculateRoutesFromMajorRoads(targetPoint)
        End Sub

        #Region "#RouteCalculated"
        Private Sub OnRouteCalculated(ByVal sender As Object, ByVal e As BingRouteCalculatedEventArgs)
            Dim result As RouteCalculationResult = e.CalculationResult
            If (result.RouteResults Is Nothing) OrElse (result.ResultCode = RequestResultCode.BadRequest) Then
                rtbResults.Text = "The Bing Route service does not work for this location."
                Return
            End If

            Dim resultList As New StringBuilder("")

            If result.IntermediatePoints IsNot Nothing Then
                resultList.Append(String.Format(" _________________________" & ControlChars.Lf))

                For i As Integer = 0 To e.CalculationResult.IntermediatePoints.Count - 1
                    resultList.Append(String.Format("Starting point {0}: {1} ({2})" & ControlChars.Lf, i + 1, e.CalculationResult.IntermediatePoints(i).Description, e.CalculationResult.IntermediatePoints(i).Location))
                Next i
            End If

            If (result.RouteResults IsNot Nothing) And (result.ResultCode = RequestResultCode.Success) Then

                For rnum As Integer = 0 To e.CalculationResult.RouteResults.Count - 1
                    resultList.Append(String.Format(" _________________________" & ControlChars.Lf))
                    resultList.Append(String.Format("Path {0}:" & ControlChars.Lf, rnum + 1))
                    resultList.Append(String.Format("Distance: {0}" & ControlChars.Lf, e.CalculationResult.RouteResults(rnum).Distance))
                    resultList.Append(String.Format("Time: {0}" & ControlChars.Lf, e.CalculationResult.RouteResults(0).Time))

                    If e.CalculationResult.RouteResults(rnum).Legs IsNot Nothing Then
                        Dim legNum As Integer = 1
                        For Each leg As BingRouteLeg In e.CalculationResult.RouteResults(rnum).Legs
                            resultList.Append(String.Format(ControlChars.Tab & "Leg {0}:" & ControlChars.Lf, legNum))
                            legNum += 1
                            resultList.Append(String.Format(ControlChars.Tab & "Distance: {0}" & ControlChars.Lf, leg.Distance))
                            resultList.Append(String.Format(ControlChars.Tab & "Time: {0}" & ControlChars.Lf, leg.Time))
                            If leg.Itinerary IsNot Nothing Then
                                For Each itineraryItem As BingItineraryItem In leg.Itinerary
                                    resultList.Append(String.Format(itineraryItem.Maneuver & ControlChars.Lf))
                                    resultList.Append(String.Format(ControlChars.Tab & ControlChars.Tab & "Location: {0}" & ControlChars.Lf, itineraryItem.Location))
                                Next itineraryItem
                            End If
                        Next leg
                    End If
                Next rnum
            End If
            rtbResults.Text = resultList.ToString()
        End Sub
        #End Region ' #RouteCalculated
    End Class
End Namespace

See Also

Migrate from Bing Maps to Azure Maps Providers

BingItineraryItem Class

BingItineraryItem Members

DevExpress.XtraMap Namespace