Rod Yager


I have an application that need to show multple multi-point routes using a different color for each route. Using the following code, only the last route that calls GetDirections get a route color. Is this a bug

function renderRoute(r,g,b)

{

var options = new VERouteOptions;

options.RouteColor = new VEColor(r,g,b,.7);

// Otherwise what's the point

options.DrawRoute = true;

// So the map doesn't change:

options.SetBestMapView = true;

options.ShowErrorMessages = true;

// Show as miles

options.DistanceUnit = VERouteDistanceUnit.Mile;

// Show the disambiguation dialog

options.ShowDisambiguation = true;

map.GetDirections(locations, options);

}




Re: Creating multiple mutli-point routes only colors last route created.

Derrick (MSFT)


v6 only supports showing 1 route at the time.






Re: Creating multiple mutli-point routes only colors last route created.

Rod Yager

That is unfortunate for me. My project requires this. Interesting enough though, the route start and end icons along with the numbered direction polygons show up for all the routes that I try to create. Only one will have the colored route line though. So in a sense it is almost working. I hope this is a feature that they will add soon

For now I am doing .GetDirections with the route option DrawRoute = false. On the route options RouteCallback, I remove all the route icons and create my own colored polyline for each leg of the route. Seems to works although it doesn't follow the roads.

Code Block

function renderRoute(r,g,b)
{
routeR = r;
routeG = g;
routeB = b;
var options = new VERouteOptions();
options.RouteCallback = RouteCallbackEvent;
options.DrawRoute = false;
//options.RouteColor = new VEColor(r,g,b,.7);

map.GetDirections(locations,options);
}

function RouteCallbackEvent(route)
{
var polyPoints = new Array();

if (route && route.RouteLegs)
{
for(i=0; i < route.RouteLegs.length; ++i)
{
var leg = route.RouteLegs[i];
if (leg.Itinerary && leg.Itinerary.Items)
{
for(var j=0; j < leg.Itinerary.Items.length; ++j)
{
var item = leg.Itinerary.Items[j];
if (item && item.Shape)
{
item.Shape.Hide();
}

if (item && item.LatLong)
{
polyPoints.push(item.LatLong);
}
}
}
}
}

if (polyPoints.length > 0)
{
var newLine = new VEShape(VEShapeType.Polyline, polyPoints);
newLine.SetLineColor(new VEColor(routeR,routeG,routeB,.8));
newLine.SetLineWidth(5);
newLine.HideIcon();
map.AddShape(newLine);
}

map.SetMapView(allPoints);
}