Click or drag to resize

Displaying a Route

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
Overview

After a route has been calculated you will typically display it to the user - either in textual form or graphically. In this example we will demonstrate how to draw a route on a map.

Generating Directions

In this example we will generate two Directions for a Route: the fastest and the shortest.

C#
Route r = new Route();

r.AddStops(...); // see previous tutorials

// By default, a Route will generate fast directions
Directions fastdirs = r.GetDirections();

// Change the route to generate short directions
r.Strategy = new RoutingStrategyShortest();
Directions shortdirs = r.GetDirections();

Each Directions object implements the IMapRenderer interface, which means that a Directions object can be drawn directly on a map.

Tip Tip

Any object that implements the IMapRenderer interface can be quickly drawn on map.

Assuming that we have a MapCtrl object named myMapCtrl, we can draw each Directions object as follows:

C#
// set the color for each route
fastdirs.RenderColor = Color.Red;
shortdirs.RenderColor = Color.Yellow;

// because we're drawing multiple objects we should use a RendererList,
// otherwise we can only draw one object at a time
RendererList rlist = new RendererList();
rlist.Add(fastdirs);
rlist.Add(shortdirs);

// draw everything on the RenderList in one hit
myMapCtrl.Renderer = rlist;

If RenderArrow properties are also used (RenderArrowLength, RenderArrowColor, RenderArrowWidth, and RenderArrowSpacing) arrows can be overlaid above the route highlight, indicating direction of travel:

C#
// set the color for each route
fastdirs.RenderColor = Color.Red;
shortdirs.RenderColor = Color.Yellow;

// configure render arrows
fastdirs.RenderArrowColor = Color.Blue;
fastdirs.RenderArrowLength = 20;
fastdirs.RenderArrowWidth = 15;
fastdirs.RenderArrowSpacing = 40;

shortdirs.RenderArrowColor = Color.Yellow;
shortdirs.RenderArrowLength = 20;
shortdirs.RenderArrowWidth = 15;
shortdirs.RenderArrowSpacing = 40;

// because we're drawing multiple objects we should use a RendererList,
// otherwise we can only draw one object at a time
RendererList rlist = new RendererList();
rlist.Add(fastdirs);

// draw everything on the RenderList in one hit
myMapCtrl.Renderer = rlist;
Note Note

To display arrows, RenderArrowLength must be set to a value greater than 0. All other RenderArrow properties are optional.

Next Topic