Telogis.GeoBase.Routing.Route |
A class for constructing point-to-point directions and optimizing multi-stop routes.
var LatLon = Telogis.GeoBase.LatLon; var RouteStop = Telogis.GeoBase.Routing.RouteStop; // Create three route stops var RouteStop1 = new RouteStop(new LatLon(33.587512,-117.741400)); var RouteStop2 = new RouteStop(new LatLon(33.553872,-117.728464)); var RouteStop3 = new RouteStop(new LatLon(33.537614,-117.687859)); // Create an array of route stops var StopsArray = [RouteStop1, RouteStop2, RouteStop3]; // Specify a routing strategy -- RoutingStrategyFastest is the default var RoutingStrategyFastest = new Telogis.GeoBase.Routing.RoutingStrategyFastest(); // Create a new route var myRoute = new Telogis.GeoBase.Routing.Route({ stops: StopsArray, strategy: RoutingStrategyFastest }); // Was the route created? Check that there are three stops... // document.onclick = myTestFunction; function myTestFunction() { alert ('There are ' + myRoute.getStopCount() + ' stops in this route.'); };
Name | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Route(config) | Arguments
|
Name | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
addStopAt (LatLon stop, Number index) | Adds a Routing.RouteStop to the route at a specified location in the list of stops. JavaScript var InsertStop = new Telogis.GeoBase.Routing.RouteStop( new Telogis.GeoBase.LatLon(33.587512,-117.741300)); // Add stop at list index 1 myRoute.addStopAt(InsertStop, 1); // document.onclick = myTestFunction; function myTestFunction() { alert ('Stop 1 in this route is now: ' + myRoute.getStop(1)); };
Routing.RouteStop - The RouteStop that was added to the route. | |||||||||
addWaypointAt (LatLon stop, Number index) | Adds a Routing.Waypoint to the route at a specified location in the list of stops. JavaScript var Waypoint = new Telogis.GeoBase.Routing.Waypoint( new Telogis.GeoBase.LatLon(33.587512,-117.741300) ); // Add stop at route list index 2 myRoute.addWaypointAt(Waypoint, 2);
Routing.Waypoint - The Waypoint that was added to the route. | |||||||||
appendStop (LatLon stop) | Adds a Routing.RouteStop to the route, at the end of the ordered list of stops. JavaScript var NewRouteStop = new Telogis.GeoBase.Routing.RouteStop( new Telogis.GeoBase.LatLon(33.587512,-117.741400)); myRoute.appendStop(NewRouteStop);
Routing.RouteStop - The RouteStop that was added to the route. | |||||||||
appendStops (Array stops) | Adds all supplied Routing.RouteStops to the route at the end of the ordered list of stops. JavaScript // Create two new route stops var newRS1 = new Telogis.GeoBase.Routing.RouteStop(new LatLon(33.612914,-117.745395)); var newRS2 = new Telogis.GeoBase.Routing.RouteStop(new LatLon(33.554736,-117.706501)); // Create an array using the stops var NewStopsArray = [newRS1, newRS2]; // Append the array to the route myRoute.appendStops(NewStopsArray); // document.onclick = myTestFunction; function myTestFunction() { alert ('There are now ' + myRoute.getStopCount() + ' stops in this route.'); };
Array - An array of Routing.RouteStops that were added to the route. | |||||||||
appendWaypoint (LatLon stop) | Adds a Routing.Waypoint to the route, at the end of the ordered list of stops. JavaScript var NewWaypoint = new Telogis.GeoBase.Routing.Waypoint( new Telogis.GeoBase.LatLon(33.587512,-117.741400)); myRoute.appendWaypoint(NewWaypoint);
Routing.Waypoint - The Waypoint that was added to the route. | |||||||||
getDirections (Function callback, Function errorCallback, String units, String culture, Object server) | Calculates the route and passes a representative Routing.Directions object to the specified callback. JavaScript var LatLon = Telogis.GeoBase.LatLon; var RouteStop = Telogis.GeoBase.Routing.RouteStop; // Create three route stops var RouteStop1 = new RouteStop(new LatLon(33.587512,-117.741400)); var RouteStop2 = new RouteStop(new LatLon(33.553872,-117.728464)); var RouteStop3 = new RouteStop(new LatLon(33.537614,-117.687859)); // Create an array of route stops var StopsArray = [RouteStop1, RouteStop2, RouteStop3]; // Specify a routing strategy -- RoutingStrategyFastest is the default var RoutingStrategyFastest = new Telogis.GeoBase.Routing.RoutingStrategyFastest(); // Create a new route var myRoute = new Telogis.GeoBase.Routing.Route({ stops: StopsArray, strategy: RoutingStrategyFastest }); // Specify the units and culture we will use for our Directions object var units = 'Metric'; // Also accepts 'ImperialFeet' and 'ImperialYards'. Optional. var culture = 'en-US'; // Optional. var list = 'Direction instructions for this route:\n\n'; // Create a Directions object containing route navigation instructions myRoute.getDirections(function (result) { var i; var count = 1; for (i = 0; i < result.getLength(); i++) { list += count + ': ' + result.getDirection(i).toString() + '\n' ; count++ } }, function (error) {alert(error)}, units, culture ); //document.onclick = myTestFunction; function myTestFunction() { alert (list); };
| |||||||||
getEnd () | Gets the location that the Routing.Routemust end at. If no end has been specified for the route, null is returned. JavaScript //... create a route (myRoute) without a specified end location, then: //document.onclick = myTestFunction; // test trigger function myTestFunction() { // No end defined so returns 'null' alert ('The end of this route (undefined end) is ' + myRoute.getEnd()); // Now specify a route stop, which is returned myRoute.setEnd(RouteStop1); alert ('The end of this route is now ' + myRoute.getEnd()); }; LatLon - The location that the route ends at. | |||||||||
getPath (Function callback, Function errorCallback, Object server) | Calculates the route and passes a representative Routing.Directions object without textual driving instructions to the specified callback. JavaScript // Create a route ('myRoute') and a map object ('map') then.. myRoute.getPath(function (result) { dirsLayer = new Telogis.GeoBase.MapLayers.RouteLayer({ id: 'route_directions', map: map, lineColor: new Telogis.GeoBase.Color(0,18,255, 0.5), lineWidth: 6 }); dirsLayer.setPoints(result.getPoints()); dirsLayer.show(); }, function (error) {alert(error)} );
| |||||||||
getQuickDirections (Function callback, Function errorCallback, Object server) | Get the 'quick directions', ignoring legality and without generating natural language directions. JavaScript // Create a route ('myRoute') and a map object ('map') then.. myRoute.getQuickDirections(function (result) { dirsLayer = new Telogis.GeoBase.MapLayers.RouteLayer({ id: 'route_directions', map: map, lineColor: new Telogis.GeoBase.Color(0,18,255, 0.5), lineWidth: 6 }); dirsLayer.setPoints(result.getPoints()); dirsLayer.show(); }, function (error) {alert(error)} );
| |||||||||
getRouteHighlight (Function callback, Function errorCallback, String dataUrl, Object server, Array customRoutingAccessKeys) | Reads point data from a file, gets the likely route that was taken between the points, and passes an abbreviated Routing.Directions object to the specified callback. JavaScript // Create a map object (map), then... // Create a route object var myRoute = new Telogis.GeoBase.Routing.Route(); dir = myRoute.getRouteHighlight( // Callback function function(result){ // Create a map layer to display the route highlight on dirsLayer = new Telogis.GeoBase.MapLayers.RouteLayer({ id: 'route_highlight', map: map }); // Add the fetched directions to the map layer dirsLayer.setPoints(result.getPoints()); dirsLayer.show(); }, // Error function function(error){ alert(error); }, // URL of CSV data file 'http://localhost/GeoStream/highlight.csv' );
| |||||||||
getStart () | Gets the location that the Routing.Routemust begin at. If no start has been specified for the route, null is returned. JavaScript //... create a route (myRoute) without a specified start location, then: //document.onclick = myTestFunction; // test trigger function myTestFunction() { // No end defined so returns 'null' alert ('The start of this route (undefined start) is ' + myRoute.getStart()); // Now specify a route stop, which is returned myRoute.setStart(RouteStop1); alert ('The start of this route is now ' + myRoute.getStart()); }; LatLon - The location that the route starts at. | |||||||||
getStop (Number i) | Finds the stop at a given placing in the route. JavaScript //... create a route (myRoute) with at least three stops, then: //document.onclick = myTestFunction; // test trigger function myTestFunction() { // zero-based: first stop is '0', third stop '2' alert ('The first stop in this route is ' + myRoute.getStop(0) + ' the third stop is ' + myRoute.getStop(2)); };
LatLon - The stop at position Routing.Route.getStop.i in the route. | |||||||||
getStopCount () | Finds how many stops there are in the route. JavaScript //... create a route (myRoute), then: //document.onclick = myTestFunction; // test trigger function myTestFunction() { alert ('Stops in this route: ' + myRoute.getStopCount()); }; Number - The number of stops that the route is comprised of. | |||||||||
getVehicleSpec () | Gets the specification used to ensure the route is safe for this vehicle. JavaScript // ... create a route (myRoute) and // apply a vehiclespec, then: var mySpec = myRoute.getVehicleSpec(); Routing.VehicleSpec - The Routing.VehicleSpec to be used for this route. | |||||||||
optimize (Function callback, Function errorCallback, Object server) | Rearranges the route's stops for maximum efficiency by the current routing strategy. While a callback function is triggered, the results of the optimization call (a differently-ordered array of stops) are automatically used to modify the route, so no parameters are passed to it. JavaScript //... create a route (myRoute), then: var count = 1; var before_list = 'pre-optimization route order:\n\n'; var after_list = 'post-optimization route order:\n\n'; for (x = 0; x < myRoute.getStopCount(); x++) { before_list += count + ': ' + myRoute.getStop(x) + '\n'; count++; } // Write out the route stops alert (before_list); // Optimize the route myRoute.optimize(function(){ alert ('Route optimized...'); }, function (error) {alert(error)} ); //// //// NOTE: The optimization process may take several seconds to //// complete, depending on the size and complexity of the route //// // Once the route has been optimized (wait required) the route can be re-queried count = 1; for (y = 0; y < myRoute.getStopCount(); y++) { after_list += count + ': ' + myRoute.getStop(y) + '\n'; } // Write out the route stops again alert (after_list);
| |||||||||
removeStopAt (Number index) | Removes the stop at the specified index from the route. Arguments
| |||||||||
setCustomRoutingAccessKeys (Array customRoutingAccessKeys) | Sets the custom routing access keys, which determine which roads can be routed on. Arguments
| |||||||||
setEnd (LatLon stop) | Specifies a location that the Routing.Routemust end at. This stop is not displaced during optimization. If an end was already specified for the route, it is overridden. JavaScript //... create a route (myRoute), then: var myEnd = new Telogis.GeoBase.Routing.RouteStop(new Telogis.GeoBase.LatLon(33.572158,-117.721639)); myRoute.setEnd(myEnd);
| |||||||||
setStart (LatLon stop) | Specifies a location that the Routing.Routemust begin at. This stop is not displaced during optimization. If a start was already specified for the route, it is overridden. JavaScript //... create a route (myRoute), then: var myStart = new Telogis.GeoBase.Routing.RouteStop(new Telogis.GeoBase.LatLon(33.572158,-117.721639)); myRoute.setStart(myStart);
| |||||||||
setStrategy (Routing.RoutingStrategy strategy) | Sets the technique used to optimize the route. JavaScript //... create a route (myRoute), then: var RoutingStrategyShortest = new Telogis.GeoBase.Routing.RoutingStrategyShortest(); myRoute.setStrategy(RoutingStrategyShortest);
| |||||||||
setVehicleSpec (Routing.VehicleSpec vehicleSpec) | Sets the specification used to ensure the route is safe for this vehicle. JavaScript // ... create a route (myRoute), then: // Create a new vehicle specifications object var VehSpec = new Telogis.GeoBase.Routing.VehicleSpec(); // Set the vehicle type (tractor semi trailer) VehSpec.VehicleType = Telogis.GeoBase.Routing.VehicleType.TractorSemiTrailer; // Apply the VehicleSpec to a route -- // Routes will now be generated that are legal for the vehicle specified myRoute.setVehicleSpec(VehSpec);
| |||||||||
useTraffic (Object trafficConfig) | Specifies traffic parameters to be used when calculating and optimizing the Routing.Route. The supplied configuration will replace the existing traffic configuration. JavaScript route.useTraffic({}); route.useTraffic({source: "LosAngeles"}); route.useTraffic({source: "LosAngeles", time: new Date()}); route.useTraffic({source: "LosAngeles", time: "01-Jan-2013 12:00:00"});
|