If you want to alter the display of a route, you can't use the default RouteResultSet
, you're going to have to implement your own logic for displaying the route Polyline
and the waypoints. When you receive the route, just create a Container
and throw the objects into it as you create them. You can alter the text and color of the StandardMarkers
or replace them with custom Markers
if you want. Something like this:
var legContainer = new nokia.maps.map.Container();
var onRouteCalculated = function (observedRouter, key, value) {
if (value == "finished") {
var firstroute = observedRouter.getRoutes()[0];
// First clear any previous route.
legContainer.objects.clear();
for (var i = 0; i < firstroute.waypoints.length; i++){
legContainer.objects.add(new nokia.maps.map.StandardMarker(
firstroute.waypoints[i].mappedPosition,
{ text: i + 1 }
));
}
for (var i = 0; i < firstroute.legs.length; i++){
var strokeColor = "#22CA";
if (i % 2 == 0){
strokeColor = "#CACA00"
}
legContainer.objects.add(new nokia.maps.map.Polyline(
firstroute.legs[i].points,
{
pen: {
strokeColor: strokeColor,
lineWidth: 5
}
}
));
}
map.objects.add(legContainer);
map.zoomTo(legContainer.getBoundingBox(), true);
} else if (value == "failed") {
// Something has gone horribly wrong e.g. route too long.
alert("The routing request failed.");
}
}
You can see an example of a custom route rendering here - it just sets the route polyline to a different color, but you should get the idea.
Assuming legContainer
is given the correct scope, you can use legContainer.objects.clear();
to empty any MapObjects
rendered previously.