Packagecom.afcomponents.umap.display.routemanager
Classpublic class BingRouteService
InheritanceBingRouteService Inheritance flash.events.EventDispatcher
Implementsflash.events.IEventDispatcher, IRouteService

Provides access to the Bing Maps routing API. The class requires valid MapPointProxy configured and the token obtained.


Example
Here is a quick usage example:
 import com.afcomponents.umap.core.UMap;
 import com.afcomponents.umap.providers.microsoft.MapPointProxy;
 import com.afcomponents.umap.providers.microsoft.MapPointTokenRequest;
 import com.afcomponents.umap.display.routemanager.RouteManager;
 import com.afcomponents.umap.events.MapEvent;
 import com.afcomponents.umap.events.RouteEvent;
 import com.afcomponents.umap.events.MapPointProxyEvent;
 import com.afcomponents.umap.types.LatLng;
 import com.afcomponents.umap.types.LatLngBounds;
 import com.afcomponents.umap.overlays.RouteLayer;
 import com.afcomponents.umap.overlays.Marker;
  
 // create UMap instance
 var map:UMap = new UMap();
 map.setSize(550,400);
 addChild(map);
  
 // initialize proxy
 MapPointProxy.initialize("http://www.umapper.com/demo/dmitry/msproxy.php");;
 // request token and wait for it
 var proxy:MapPointProxy = MapPointProxy.getInstance();
 proxy.getToken();
 proxy.addEventListener(MapPointProxyEvent.REQUEST_COMPLETE, requestComplete);
  
 // wait for token load
 function requestComplete(event:MapPointProxyEvent):void
 {
   // check for token request
   if (event.request is MapPointTokenRequest)
   {
     // validate token
     if (proxy.getToken())
     {
       // add 2 markers to the route layer, as target route points
       layer.setMarker(new Marker({position:new LatLng(39.761933, -105.050774)}), 0);
       layer.setMarker(new Marker({position:new LatLng(39.727087, -105.054894)}), 1);
       // set map bounds
       map.setBounds(layer.getBoundsLatLng());
       // perform routing service call
       layer.getDirections();
     }
     else
     {
       // TODO: invalid token, throw error or smth.
     }
   }
 }
 
 // create new route manager
 var route:RouteManager = new RouteManager(RouteManager.BING_SERVICE); 
 map.addManager(route);
  
 // extract and attach route layer
 var layer:RouteLayer = route.getRouteLayer();
 map.addOverlay(layer);
 
 // listen for route events
 route.addEventListener(RouteEvent.READY, routeReady);
 route.addEventListener(RouteEvent.FAILURE, routeFailure);
 
 // route is ready, show
 function routeReady(e:RouteEvent):void
 {
   // set map bounds to the route polyline
   map.setBounds(LatLngBounds.fromLatLngArray(e.routeResults.toLatLngArray()));
 }
  
 // route error
 function routeFailure(e:RouteEvent):void
 {
   // TODO: warn or throw error
 }
 

See also

com.afcomponents.umap.overlays.RouteLayer
RouteManager


Public Properties
 PropertyDefined by
  routeResults : RouteResults
[read-only] Returns route results obtained by previous doRoute operation.
BingRouteService
Public Methods
 MethodDefined by
  
doRoute(locations:Array, options:Object = null):Boolean
Request a route between 2 or more locations.
BingRouteService
Protected Methods
 MethodDefined by
  
mergeOptions(options:Object):Object
Adds properties from the default options Object to the target options Object, only if they are are not specified in the target options Object.
BingRouteService
Public Constants
 ConstantDefined by
  OPTIMIZATION_DISTANCE : String = "MinimizeDistance"
[static]
BingRouteService
  OPTIMIZATION_TIME : String = "MinimizeTime"
[static]
BingRouteService
  ROUTE_TYPE_CAR : String = "car"
[static] Defines the value of the routeType property.
BingRouteService
  ROUTE_TYPE_CAR_SHORTEST : String = "car/shortest"
[static] Defines the value of the routeType property.
BingRouteService
  ROUTE_TYPE_FOOT : String = "foot"
[static] Defines the value of the routeType property.
BingRouteService
  TRAVELMODE_DRIVING : String = "Driving"
[static]
BingRouteService
  TRAVELMODE_WALKING : String = "Walking"
[static]
BingRouteService
Property detail
routeResultsproperty
routeResults:RouteResults  [read-only]

Returns route results obtained by previous doRoute operation.

Implementation
    public function get routeResults():RouteResults
Method detail
doRoute()method
public function doRoute(locations:Array, options:Object = null):Boolean

Request a route between 2 or more locations. Locations can be specified as Objects which can be processed by a concrete service. Additional options should be sepcified in the second parameter in a common to service format.

Parameters
locations:Array — Array of 2 or more locations.
 
options:Object (default = null) — Additonal options in a known to service format.

Returns
Boolean — A value of true if a request has been accepted, and is being processed; false if it is not.
mergeOptions()method 
protected function mergeOptions(options:Object):Object

Adds properties from the default options Object to the target options Object, only if they are are not specified in the target options Object.

Parameters
options:Object

Returns
Object — Merged options object.
Constant detail
OPTIMIZATION_DISTANCEconstant
public static const OPTIMIZATION_DISTANCE:String = "MinimizeDistance"

OPTIMIZATION_TIMEconstant 
public static const OPTIMIZATION_TIME:String = "MinimizeTime"

ROUTE_TYPE_CARconstant 
public static const ROUTE_TYPE_CAR:String = "car"

Defines the value of the routeType property. Use this value to get the car route.

ROUTE_TYPE_CAR_SHORTESTconstant 
public static const ROUTE_TYPE_CAR_SHORTEST:String = "car/shortest"

Defines the value of the routeType property. Use this value to get the shortest car route.

ROUTE_TYPE_FOOTconstant 
public static const ROUTE_TYPE_FOOT:String = "foot"

Defines the value of the routeType property. Use this value to get the foot route.

TRAVELMODE_DRIVINGconstant 
public static const TRAVELMODE_DRIVING:String = "Driving"

TRAVELMODE_WALKINGconstant 
public static const TRAVELMODE_WALKING:String = "Walking"