Skip to main content
You are viewing help content for a version that is no longer maintained/updated.
All docs
V21.1
  • BingRouteOptions.OptimizeWaypoints Property

    Specifies whether the service rearranges route waypoints to reduce route cost.

    Namespace: DevExpress.Xpf.Map

    Assembly: DevExpress.Xpf.Map.v21.1.dll

    NuGet Package: DevExpress.Wpf.Map

    Declaration

    public bool OptimizeWaypoints { get; set; }

    Property Value

    Type Description
    Boolean

    true if waypoints are rearranged; otherwise, false. The default value is false.

    Property Paths

    You can access this nested property as listed below:

    Object Type Path to OptimizeWaypoints
    BingRouteDataProvider
    .RouteOptions .OptimizeWaypoints

    Remarks

    Enable the OptimizeWaypoints property to rearrange waypoints passed to the BingRouteDataProvider.CalculateRoute method to create an optimized route.

    The following images depict non-optimized and optimized routes for six waypoints (“San Francisco”, “Las Vegas”, “San Jose”, “Chico”, “Los Angeles”, “Oakland”):

    OptimizeWaypoints = false
    A non-optimized route.
    OptimizeWaypoints = true
    An optimized route.

    The OptimizeWaypoints option is available only for Driving mode (Mode is set to Driving). The list of waypoints should include more than 2 points.

    Example

    The following code creates an optimized route for a list of waypoints:

    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:RouteOptimization"
            xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" x:Class="RouteOptimization.MainWindow"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800" Loaded="OnLoaded">
        <Grid>
            <dxm:MapControl x:Name="mapControl">
                <dxm:ImageLayer>
                    <dxm:BingMapDataProvider BingKey="Insert your Bing key." 
                                             Kind="RoadLight" />
                </dxm:ImageLayer>
                <dxm:InformationLayer x:Name="infoLayer" DataRequestCompleted="OnDataRequestCompleted">
                    <dxm:BingRouteDataProvider x:Name="routeProvider" 
                                               BingKey="Insert your Bing key."  
                                               LayerItemsGenerating="OnLayerItemsGenerating">
                        <dxm:BingRouteDataProvider.RouteOptions>
                            <dxm:BingRouteOptions Mode="Driving" 
                                                  OptimizeWaypoints="False"/>
                        </dxm:BingRouteDataProvider.RouteOptions>
                    </dxm:BingRouteDataProvider>
                </dxm:InformationLayer>
            </dxm:MapControl>
        </Grid>
    </Window>
    
    using DevExpress.Xpf.Map;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Media;
    
    namespace RouteOptimization {
        public partial class MainWindow : Window {
            private void OnLoaded(object sender, RoutedEventArgs e) {
                List<RouteWaypoint> waypoints = new List<RouteWaypoint>() {
                    new RouteWaypoint("San Francisco", new GeoPoint( 37.4639, -122.2459)),
                    new RouteWaypoint("Las Vegas", new GeoPoint( 36.1030, -115.0811)),
                    new RouteWaypoint("San Jose", new GeoPoint( 37.20, -121.54)),
                    new RouteWaypoint("Chico", new GeoPoint(39.4424, -121.508)),
                    new RouteWaypoint("Los Angeles", new GeoPoint( 34.03, -118.15)),
                    new RouteWaypoint("Oakland", new GeoPoint( 37.4816, -122.1615))
                };
                routeProvider.CalculateRoute(waypoints);
            }
            private void OnLayerItemsGenerating(object sender, LayerItemsGeneratingEventArgs args) {
                foreach (MapItem item in args.Items) {
                    MapPolyline polyline = item as MapPolyline;
                    if (polyline != null) {
                        polyline.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x72, 0xC6));
                        polyline.StrokeStyle = new StrokeStyle { Thickness = 2 };
                    }
                }
            }
            private void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
                // Call the ZoomToFitLayerItems method to zoom the map so that it displays the whole generated route.
                mapControl.ZoomToFitLayerItems();
            }
        }
    }
    
    See Also