Export (0) Print
Expand All

DirectionsManager Class

Bing

Contains methods for calculating directions and displaying a route on a map.

Constructor

Name Definition Description

DirectionsManager

DirectionsManager(map: Map )

Initializes a new instance of the DirectionsManager class.

Methods

Name Definition Return Value Description

addWaypoint

addWaypoint(waypoint: Waypoint , index:number )

None

Adds a waypoint to the route at the given index, if specified. If an index is not specified the waypoint is added as the last waypoint in the route.

To recalculate the route, use calculateDirections.

The maximum number of walking or driving waypoints is 25. The maximum number of transit waypoints is 2.

Up to 10 via points are allowed between two stop waypoints.

calculateDirections

calculateDirections()

None

Calculates directions based on request and render options set (setRequestOptions, setRenderOptions) and the waypoints added (addWaypoint). The directionsUpdated event fires when the calculation is complete and the route is displayed on the map.

You must call this method after making any changes to the route options or waypoints.

clearDisplay

clearDisplay()

None

Clears the directions displayed and removes the route line from the map. This method does not remove waypoints from the route and retains all calculated direction information and option settings. To clear the calculated directions and options, use resetDirections.

dispose

dispose()

None

Deletes the DirectionsManager object and releases any associated resources.

getAllWaypoints

getAllWaypoints()

Waypoint[]

Returns the waypoints for the route.

getMap

getMap()

Map

Returns the map object associated with the directions manager.

getNearbyMajorRoads

getNearbyMajorRoads(location: Location , callback:function, errorCallback:function, userData:object)

None

Searches around the specified location for nearby major roads and returns them as an object to the callback function.

getRenderOptions

getRenderOptions()

DirectionsRenderOptions

Returns the route render options.

getRequestOptions

getRequestOptions()

DirectionsRequestOptions

Returns the directions request options.

getRouteResult

getRouteResult()

Route[]

Returns the current calculated route(s). If the route was not successfully calculated, null is returned.

removeWaypoint

removeWaypoint(waypoint: Waypoint ) or removeWaypoint(index:number)

None

Removes the given waypoint or the waypoint identified by the given index from the route. Use calculateDirections to update the route once a waypoint has been removed.

resetDirections

resetDirections(options: ResetDirectionsOptions )

None

If no options object is supplied, clears the directions request and render options and removes all waypoints.

reverseGeocode

reverseGeocode(location: Location , callback:function, errorCallback:function, userData:object)

None

Matches the specified location to an address and returns the address to the specified callback function.

setMapView

setMapView()

None

Sets the map view based on the current route index.

setRenderOptions

setRenderOptions(options: DirectionsRenderOptions )

None

Sets the specified render options for the route.

setRequestOptions

setRequestOptions(options: DirectionsRequestOptions )

None

Sets the specified route calculation options.

Events

Name Arguments Description

afterRouteSelectorRender

RouteSelectorRenderEventArgs

Occurs after the route selector has fully rendered.

afterStepRender

DirectionsStepRenderEventArgs

Occurs after each step in the itinerary has fully rendered.

afterSummaryRender

RouteSummaryRenderEventArgs

Occurs after the route summary has fully rendered.

afterWaypointRender

WaypointRenderEventArgs

Occurs after each route waypoint has fully rendered.

beforeDisambiguationRender

DisambiguationRenderEventArgs

Occurs before the waypoint disambiguation element is rendered. Use the autoDisplayDisambiguation directions render option to automatically display waypoint disambiguation.

beforeRouteSelectorRender

RouteSelectorRenderEventArgs

Occurs just before the route selector renders.

beforeStepRender

DirectionsStepRenderEventArgs

Occurs just before each step in the itinerary renders.

beforeSummaryRender

RouteSummaryRenderEventArgs

Occurs just before the route summary renders.

beforeWaypointRender

WaypointRenderEventArgs

Occurs just before each route waypoint renders.

directionsError

DirectionsErrorEventArgs

Occurs when calculating the directions caused an error.

directionsUpdated

DirectionsEventArgs

Occurs when the directions calculation was successful and the itinerary and route on the map have been updated.

dragDropCompleted

None

Occurs when the drag of a waypoint or route is completed.

itineraryStepClicked

DirectionsStepEventArgs

Occurs when a step in the itinerary is clicked.

mouseEnterRouteSelector

RouteSelectorEventArgs

Occurs when the mouse cursor is over the route selector.

mouseEnterStep

DirectionsStepEventArgs

Occurs when the mouse cursor is over a directions step.

mouseLeaveRouteSelector

RouteSelectorEventArgs

Occurs when the mouse cursor leaves the route selector.

mouseLeaveStep

DirectionsStepEventArgs

Occurs when the mouse cursor leaves a directions step.

routeSelectorClicked

RouteSelectorEventArgs

Occurs when the route selector is clicked.

waypointAdded

WaypointEventArgs

Occurs when a new waypoint is added to the route.

waypointRemoved

WaypointEventArgs

Occurs when a waypoint is removed from the route.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

      <script type="text/javascript">
         
         var map = null;

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Bing Maps Key"});
            Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: directionsModuleLoaded });

         }


         function directionsModuleLoaded()
         {
            // Initialize the DirectionsManager
            var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

            // Create start and end waypoints
            var startWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Seattle, WA"});
            var endWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Portland, OR"});

            directionsManager.addWaypoint(startWaypoint);
            directionsManager.addWaypoint(endWaypoint);

            // Set the id of the div to use to display the directions
            directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('itineraryDiv') });

            // Specify a handler for when an error occurs
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayError);

            // Calculate directions, which displays a route on the map
            directionsManager.calculateDirections();

         } 

         function displayError(e)
         {
            alert(e.message);
         }


      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>       
      <div id='itineraryDiv' style="position:relative; width:400px;"></div>
   </body>
</html>
Show:
© 2014 Microsoft