| Package | com.afcomponents.umap.display.routemanager |
| Class | public class BingRouteService |
| Inheritance | BingRouteService flash.events.EventDispatcher |
| Implements | flash.events.IEventDispatcher, IRouteService |
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
| Property | Defined by | ||
|---|---|---|---|
| routeResults : RouteResults
[read-only]
Returns route results obtained by previous doRoute operation.
| BingRouteService | ||
| Method | Defined by | ||
|---|---|---|---|
|
doRoute(locations:Array, options:Object = null):Boolean
Request a route between 2 or more locations.
| BingRouteService | ||
| Method | Defined 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 | ||
| Constant | Defined 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 | ||
| routeResults | property |
routeResults:RouteResults [read-only]Returns route results obtained by previous doRoute operation.
Implementation public function get routeResults():RouteResults
| 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.
locations:Array — Array of 2 or more locations.
|
|
options:Object (default = null) — Additonal options in a known to service format.
|
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):ObjectAdds properties from the default options Object to the target options Object, only if they are are not specified in the target options Object.
Parametersoptions:Object |
Object — Merged options object.
|
| OPTIMIZATION_DISTANCE | constant |
public static const OPTIMIZATION_DISTANCE:String = "MinimizeDistance"
| OPTIMIZATION_TIME | constant |
public static const OPTIMIZATION_TIME:String = "MinimizeTime"
| ROUTE_TYPE_CAR | constant |
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_SHORTEST | constant |
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_FOOT | constant |
public static const ROUTE_TYPE_FOOT:String = "foot"
Defines the value of the routeType property.
Use this value to get the foot route.
| TRAVELMODE_DRIVING | constant |
public static const TRAVELMODE_DRIVING:String = "Driving"
| TRAVELMODE_WALKING | constant |
public static const TRAVELMODE_WALKING:String = "Walking"