public SCMap AddBingRouteLayer(BingRouteWayPoint[] wayPoints, BingRouteLayerOptions options = null) { if (wayPoints == null || wayPoints.Length < 1) { throw new Exception("Route requires at least 1 way point."); } options ??= new BingRouteLayerOptions(); var provider = new BingRouteDataProvider() { BingKey = Parameters.BingMapKey, ConnectionProtocol = ConnectionProtocol.Https, GenerateLayerItems = true, MaxVisibleResultCount = options.ResultCount, ProcessMouseEvents = false }; if (options.AvoidRoads.HasValue) { provider.RouteOptions.AvoidRoads = (DevExpress.XtraMap.BingAvoidRoads)options.AvoidRoads.Value; } if (options.DistanceUnit.HasValue) { provider.RouteOptions.DistanceUnit = (DevExpress.XtraMap.DistanceMeasureUnit)options.DistanceUnit.Value; } if (options.Mode.HasValue) { provider.RouteOptions.Mode = (DevExpress.XtraMap.BingTravelMode)options.Mode.Value; } if (options.RouteOptimization.HasValue) { provider.RouteOptions.RouteOptimization = (DevExpress.XtraMap.BingRouteOptimization)options.RouteOptimization.Value; } var routePoints = new List <RouteWaypoint>(); foreach (var bingWayPoint in wayPoints) { var routePoint = ConvertWayPoint(bingWayPoint); routePoints.Add(routePoint); } options.CreateLayer(this, provider); provider.CalculateRoute(routePoints, options.Culture, null); return(this);
public override InformationDataProviderBase CreateDataProvider(InformationLayer layer, int resultCount) { var provider = new BingRouteDataProvider() { BingKey = Parameters.BingMapKey, ConnectionProtocol = ConnectionProtocol.Https, GenerateLayerItems = true, MaxVisibleResultCount = resultCount, ProcessMouseEvents = false }; if (AvoidRoads.HasValue) { provider.RouteOptions.AvoidRoads = AvoidRoads.Value; } if (DistanceUnit.HasValue) { provider.RouteOptions.DistanceUnit = DistanceUnit.Value; } if (Mode.HasValue) { provider.RouteOptions.Mode = Mode.Value; } if (RouteOptimization.HasValue) { provider.RouteOptions.RouteOptimization = RouteOptimization.Value; } var wayPoints = new List <RouteWaypoint>(); if (WayPoints == null || WayPoints.Length < 1) { throw new Exception("Route requires at least 1 way point."); } foreach (var bingWayPoint in WayPoints) { var wayPoint = ConvertWayPoint(bingWayPoint); wayPoints.Add(wayPoint); } layer.DataProvider = provider; provider.CalculateRoute(wayPoints, Culture, null); return(provider);
private void Form1_Load(object sender, EventArgs e) { // Create a new route provider. BingRouteDataProvider provider = new BingRouteDataProvider { BingKey = yourBingKey }; informationLayer.DataProvider = provider; // Send a request and handle request result. provider.RouteCalculated += OnRouteCalculated; // Note that waypoints are created using address instead of the location. provider.CalculateRoute(new List <RouteWaypoint>() { new RouteWaypoint("New York", "Belmont Park, New York, USA"), new RouteWaypoint("Las Vegas", "Lorenzi Park, Las Vegas, USA") }); splashScreenManager1.ShowWaitForm(); }
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 }
//Bing key form account Microsoft Bing //WayPoint function //For add we need devexpress.Data dll public void AddWayPoint() { try { BingRouteDataProvider provider = new BingRouteDataProvider { BingKey = bingKey }; mapControl1.Layers.Add(new InformationLayer { DataProvider = provider }); mapControl1.Layers.Add(new ImageLayer() { DataProvider = new BingMapDataProvider() { BingKey = bingKey } }); //this event will generate later List <RouteWaypoint> waypoints = new List <RouteWaypoint>(); //Add waypoint means Address FromAddress = txtFromAddress.Text; ToAddress = txtToAddress.Text; waypoints.Add(new RouteWaypoint("From Address", FromAddress)); waypoints.Add(new RouteWaypoint("To Address", ToAddress)); provider.CalculateRoute(waypoints); provider.RouteCalculated += OnRouteCalculated; provider.LayerItemsGenerating += routeLayerItemGenerating; System.Threading.Thread.Sleep((int)System.TimeSpan.FromSeconds(2).TotalMilliseconds); } catch { } }
private void Form1_Load(object sender, System.EventArgs e) { imageProvider.BingKey = yourBingKey; routeProvider = new BingRouteDataProvider { BingKey = yourBingKey }; informationLayer.DataProvider = routeProvider; #region #Waypoints // Create three waypoints and add them to a route waypoints list. List <RouteWaypoint> waypoints = new List <RouteWaypoint> { new RouteWaypoint("New York", new GeoPoint(41.145556, -73.995)), new RouteWaypoint("Oklahoma", new GeoPoint(36.131389, -95.937222)), new RouteWaypoint("Las Vegas", new GeoPoint(36.175, -115.136389)) }; #endregion #Waypoints // Call the BingRouteDataProvider.CalculateRoute method. splashScreenManager.ShowWaitForm(); routeProvider.CalculateRoute(waypoints); // Handle the BingRouteDataProvider.LayerItemsGenerating event. routeProvider.LayerItemsGenerating += routeLayerItemsGenerating; }