Click or drag to resize

Telogis.GeoBase.MapLayers.RouteLayer

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release

MapLayers.RouteLayer inherits from MapLayers.CanvasLayer.

A class used for displaying a path or route described by a sequence of latitude-longitude coordinates. This may be constructed with the directions generated by a routing call. Note also that this layer can be used for any arbitrary path: not necessarily ones generated by routing calls.

JavaScript
// Method 1:
// First create a route (myRoute) and a map object (map)
// Then use getDirections or getQuickDirections to retrieve directions
myRoute.getQuickDirections(function (result) {
    // Wrap the RouteLayer constructor within the callback function
    directionsRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
        id: 'route_directions',
        map: map,
        // Pass the directions object to the RouteLayer
        directions: result,
        lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
        lineWidth: 4,
        show: true
    });
    }, function (error) {alert(error)}
);

// Method 2:
// Or, alternatively, create a RouteLayer object without directions
myRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
    id: 'route_directions',
    map: map,
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
    lineWidth: 4,
    show: true
});

// Then use getDirections or getQuickDirections to set the points of the RouteLayer
// setPoints may also be used with an arbitrary array of LatLons
myRoute.getQuickDirections(function (result) {
    myRouteLayer.setPoints(result.getPoints());
    myRouteLayer.show();
    }, function (error) {alert(error)}
);
Constructor
NameDescription
MapLayers.RouteLayer(config)

Arguments

  • config (Object) - Configuration options for the route layer.

    Properties
    NameTypeDescription
    directionsRouting.Directions

    The route directions to derive points for the route layer from. Overrides MapLayers.RouteLayer.config.points if present.

    Defaults to null.
    lineColorColor

    The RGBA description of the color with which to draw the path.

    This property may also be referenced by the name: lineColour.
    lineWidthNumber

    The pixel width to draw the path with.

    Defaults to 8.
    pointsArray

    The array of LatLon coordinates that describe the path to display. This can be set later with a call to MapLayers.RouteLayer.setPoints.

    Defaults to [].
Functions
NameDescription
addStopAt (LatLon stop, Number index)

Adds a Routing.RouteStop to the route at a specified location in the list of stops.

JavaScript
// Create a RouteLayer object without directions
myRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
    id: 'route_directions',
    map: map,
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
    lineWidth: 4,
    show: true
});

// Add stops at indexes 1 and 2
myRouteLayer.addStopAt(new Telogis.GeoBase.LatLon(33.554736,-117.706501), 1);
myRouteLayer.addStopAt(new Telogis.GeoBase.LatLon(33.612914,-117.745395), 2);
Arguments
  • stop (LatLon) - The route stop to add.

  • index (Number) - The index in the list of stops to place Routing.Route.addStopAt.stop.

addWaypointAt (LatLon stop, Number index)

Adds a Routing.Waypoint to the route at a specified location in the list of stops.

JavaScript
// Create a RouteLayer object without directions
myRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
    id: 'route_directions',
    map: map,
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
    lineWidth: 4,
    show: true
});

// Add stop at index 0 -- Waypoints cannot be the start or end of a route.
myRouteLayer.addStopAt(new Telogis.GeoBase.LatLon(33.567888,-117.752183), 0);

// Add waypoints at indexes 1 and 2
myRouteLayer.addWaypointAt(new Telogis.GeoBase.LatLon(33.554736,-117.706501), 1);
myRouteLayer.addWaypointAt(new Telogis.GeoBase.LatLon(33.612914,-117.745395), 2);

// Add stop at index 3
myRouteLayer.addStopAt(new Telogis.GeoBase.LatLon(33.590845,-117.702854), 3);
Arguments
  • stop (LatLon) - The waypoint to add.

  • index (Number) - The index in the list of stops to place Routing.Route.addWaypointAt.stop.

appendStop (LatLon stop)

Adds a Routing.RouteStop to the route, at the end of the ordered list of stops.

Arguments
appendStops (Array stops)

Adds all supplied Routing.RouteStops to the route at the end of the ordered list of stops.

JavaScript
// Create a RouteLayer object without directions
myRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
    id: 'route_directions',
    map: map,
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
    lineWidth: 4,
    show: true
});

// Add a stop at end of the route list. Not the stop the route must end at.
myRouteLayer.appendStop(new Telogis.GeoBase.LatLon(33.567888,-117.752183));
Arguments
  • stops (Array) - An array of route stops to add, as LatLons.

appendWaypoint (LatLon stop)

Adds a Routing.Waypoint to the route, at the end of the ordered list of stops.

Arguments
canGetDirections ()

Tests whether a representative Routing.Directions object can be calculated for the route. That is, that the route contains a minimum of two stops, and that neither the first nor last stop on the route is a Routing.Waypoint.

JavaScript
// Create a RouteLayer object without directions
myRouteLayer = new Telogis.GeoBase.MapLayers.RouteLayer({
    id: 'route_directions',
    map: map,
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.5),
    lineWidth: 4,
    show: true
});

// Add stops.
myRouteLayer.appendStop(new Telogis.GeoBase.LatLon(33.567888,-117.752183));
myRouteLayer.appendStop(new Telogis.GeoBase.LatLon(33.590845,-117.702854));

// Check that a directions object can be retrieved for the route
if (myRouteLayer.canGetDirections()) {
    // Yes (true)...
    myRouteLayer.getDirections(function (callback) {
        myRouteLayer.setPoints(callback.getPoints());
        myRouteLayer.show();
        }, function (error) {alert(error)}
    );
} else {
    // No (false)..
    alert('Unable to generate a directions object for this route.\n\n- Are there at least two stops ' +
        'on the route?\n- Is the start and/or the end a waypoint (not permitted)?');
}
Returns

Boolean - True if a Routing.Directions object can be calculated for the route; false otherwise.

DragMarkerTemplate ()

Creates a custom drag marker icon. Used when route is draggable.

Returns

Canvas.Shapes.AbstractShape - The custom shape.

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.

Arguments
  • callback (Function) - The function to call when the directions have been fetched.

    Arguments
    • directions (Routing.Directions) - The resulting directions from the server-side call to GetDirectionsStateless.

  • (Optional) errorCallback (Function) - A callback to execute if an error or timeout occurs when fetching directions. Defaults to null.

    Arguments
    • error (Telogis.Errors.GeoBaseError) - An exception describing the problem that was encountered.

  • units (String) - An optional argument describing the units that the directions are desired in. The valid unit strings can be found at Telogis.GeoBase.Navigation.UnitSystem.

  • culture (String) - An optional argument specifying the language of the directions to be fetched. Available cultures can be found by querying Telogis.GeoBase.getCultures().

  • server (Object) - An optional object that contains server.url and server.authToken to be used for this request

getEnd ()

Gets the location that the Routing.Routemust end at. If no end has been specified for the route, null is returned.

Returns

LatLon - The location that the route ends at.

getPath ()

Gets the Canvas.Shapes.Path that is displayed on this layer.

Returns

Canvas.Shapes.Path - The path shown on this layer.

getStart ()

Gets the location that the Routing.Routemust begin at. If no start has been specified for the route, null is returned.

Returns

LatLon - The location that the route starts at.

getStop (Number i)

Finds the stop at a given placing in the route.

Arguments
  • i (Number) - The index of the stop to get.

Returns

LatLon - The stop at position Routing.Route.getStop.i in the route.

getStopCount ()

Finds how many stops there are in the route.

Returns

Number - The number of stops that the route is comprised of.

OnDirectionsError (Telogis.Errors.GeoBaseError error)

A callback to execute if an error or timeout occurs when fetching directions.

Arguments
  • error (Telogis.Errors.GeoBaseError) - An exception describing the problem that was encountered.

OnDirectionsGenerated (Routing.Directions directions)

The function to call when the directions have been fetched.

Arguments
  • directions (Routing.Directions) - The resulting directions from the server-side call to getDirections.

OnStopAdded (Object RouteStopBinder)

Called after a stop has been added to the route.

Arguments
  • RouteStopBinder (Object) - An object that contains the icon and routestop.

    Properties
    NameTypeDescription
    iconString

    The routestop icon. Defaults to 14 x 14 pixels; yellow for waypoint, red for end/destination stop, green for start, and blue for default stop.

    routestopNumber

    The routestop added.

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.

Arguments
  • (Optional) callback (Function) - The function to call when the optimizations have been fetched. Defaults to null.

  • (Optional) errorCallback (Function) - A callback to execute if an error or timeout occurs when optimizing the route. Defaults to null.

    Arguments
    • error (Telogis.Errors.GeoBaseError) - An exception describing the problem that was encountered.

  • server (Object) - An optional object that contains server.url and server.authToken to be used for this request

removeStopAt (Number index)

Removes the stop at the specified index from the route.

Arguments
  • index (Number) - The index to remove the RouteStop from.

reset ()

Clears all stops and directions.

RouteStopTemplate (String type, MapLayers.RouteLayer routelayer)

Creates a custom Routing.RouteStop icon.

ArgumentsReturns

Object - An object containing methods used to draw a custom RouteStop Icon.

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.

Arguments
setPoints (Array points)

Changes the list of coordinates that describe the route being drawn on the layer.

Arguments
  • points (Array) - The new array of LatLon coordinates to plot the route with.

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.

Arguments
setStrategy (Routing.RoutingStrategy strategy)

Sets the technique used to optimize the route.

Arguments
show ()

Shows the layer on the map. See AbstractDOMEntity.show for arguments and more information.

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. Examples:

JavaScript
route.useTraffic({});
route.useTraffic({source: "LosAngeles"});
route.useTraffic({source: "LosAngeles", time: new Date()});
route.useTraffic({source: "LosAngeles", time: "01-Jan-2008 12:00:00"});
Arguments
  • trafficConfig (Object) - Traffic configurations have "source" property of type String, and a "time" property of type Date or String.

    Properties
    NameTypeDescription
    sourceString

    The source of the traffic as a string, for example "LosAngeles". If no value is specified, no traffic is used.

    timeString

    A date or string specifying the traffic time to use when optimizing routes, for example "01-Jan-2012 12:00:00". If no time is specified, the current system time will be used.