•  
      CommentAuthorPepitaL
    • CommentTimeJul 8th 2009 edited
     
    A few people asked how to show multiple routes on the map, so I decided to give my contribution and add an example. I hope others find this useful.
    First, you define the route stops in a collection or one by one. In this example, the stops are part of a collection:
    // Define stop as a collection
    RouteStop[] stops = new RouteStop[]
    {
    new RouteStop(new LatLon(34.027355, -118.327263)),
    new RouteStop(new LatLon(33.95405, -118.30195)),
    new RouteStop(new LatLon(34.012425, -118.167540)),
    new RouteStop(new LatLon(34.135617, -118.471502))
    };


    Then you create the route with start and end stops:
    // Create route with start and end stops
    Route route1 = new Route(stops[0], stops[1]);
    Route route2 = new Route(stops[0], stops[2]);
    Route route3 = new Route(stops[0], stops[3]);


    You calculate the route directions:
    // Calculate directions for each route
    Directions dir1 = route1.GetDirections();
    Directions dir2 = route2.GetDirections();
    Directions dir3 = route3.GetDirections();


    Finally, you render the route and the stops by adding them to the map renderList:
    // Set the main map to use the render list
    mapMain.Renderer = renderList;
    // Render route stops and route
    // And define rendering color
    // Route1
    dir1.RenderColor = Color.Red;
    renderList.Add(stops[0]);
    renderList.Add(stops[1]);
    renderList.Add(dir1);
    // Route 2
    dir2.RenderColor = Color.Green;
    renderList.Add(stops[2]);
    renderList.Add(dir2);
    // Route 3
    dir3.RenderColor = Color.Black;
    renderList.Add(stops[3]);
    renderList.Add(dir3);
    mainMap.Invalidate();