Class: Routing

cercaliagl.service/Routing


Javascript ES5

const routingService = new cercaliagl.service.Routing({ ... });

Routing class calculate routes between two or more points. It make calls against Cercalia WS (https://www.cercalia.com/Documentacion/webservices/calculo-de-rutas).
There are many options to calculate route, below in constructor options those are listed.
This class can calculate logistics route for vans and trucks.

Example usage:

const routingService = new cercaliagl.service.Routing({
  origin: new cercaliagl.LonLat(-3.712916732, 40.440202761),
  destination: new cercaliagl.LonLat(-3.669923363, 40.443071692)
  weight: 'time'
});

routingService.calculateRoute((data) => {
  // Draw feature with route.
  if (data.cercalia.route.stages && data.cercalia.route.stages.stage) {
    const wkt = data.cercalia.route.stages.stage[0].wkt.value
    const feature = new cercaliagl.Feature({wkt: wkt});
    map.addFeature(feature);
    map.centerToFeatures([feature]);
  }
});

new Routing(opt_options)

Name Type Description
options

Options

Name Type Description
destination module:cercaliagl/LonLat~LonLat | module:cercaliagl/service/Routing~RoutingStep

Destination coordinates.

edges boolean

Get edges IDs

infoedges boolean

Adds specific information for each section to the route report.
An infoedges tag is added to each substage with specific information of each section.
The following attributes are reported for each section:
height: height from sea level in meters.
gradient: slope of the section
geometry: Stretch geometry
meters: Length of the section
maxkph: Legal maximum speed.

lang string

Report language (only if report parameter is true).

mindist boolean

Minimum substage distance, in meters. The larger this distance , the smaller the number of substages. Default value 1000.

origin module:cercaliagl/LonLat~LonLat | module:cercaliagl/service/Routing~RoutingStep

Origin coordinates.

reorder boolean

Specify if you want to reorder or not the route stops, to get the faster/shorter route. Maximum 10 stop points.

report boolean

Get the textual route report (if not, gets a faster response). Default 0.

steps Array.<module:cercaliagl/LonLat~LonLat> | Array.<module:cercaliagl/service/Routing~RoutingStep>

Array with stop points coordinates.

tolerance number

Route geometry generalization, in meters (if =0, returns the original geometry). Default value 5 (meters).

toll boolean

Specify if you need to get the toll roads cost for the route. Currently only avaliable for Spain, Portugal and Andorra. Default false.

weight string

Route type: time (faster), distance (shorter), money (toll free route). Default value: time.

vweight number

Route logistics parameter. Total maximum vehicle weight.

vaxleweight number

Route logistics parameter. Maximum vehicle axle weight.

vheight number

Route logistics parameter. Maximum vehicle height.

vlength number

Route logistics parameter. Maximum vehicle length.

vwidth number

Route logistics parameter. Maximum vehicle width.

vmaxvel number

Route logistics parameter. Maximum vehicle speed.

rimp boolean

Route logistics parameter. Dangerous goods

trinfodate string

Route logistics parameter. Number days to consecutives to show restrictions. Info date format YYYYMMDD.

trinfodays number

Route logistics parameter. Avoid route restrictions. In timestamp format.

trstart number

Route logistics parameter. Avoid route restrictions. In timestamp format.

originIsDepot boolean

This parameter only works if REORDER parameter is used. Values:
true (default): origin cannot be reordered (default).
false: origin is one more stop and can be reordered. Useful when you cannot choose the starting point of the vehicle.

destinationIsDepot boolean

This parameter only works if REORDER parameter is used. Values:
true (default): Destination cannot be reordered (default).
false: Destination is one more stop and can be reordered. Useful when after attending some services you don’t have to return to a base.

concurrency boolean | undefined

Default true. Multiple requests at same time. If false it cancel previous pending requests.

departuretime string

Departure time in format ISO8601.

Extends

  • module:cercaliagl/service/Service~Service

Methods

addStep(step)

Add step (or waypoint).

Name Type Description
step module:cercaliagl/LonLat~LonLat | module:cercaliagl/service/Routing~RoutingStep

Step.

calculateRoute(callbackFn, callbackErrorFn)

Calcula la ruta especificando una funcion de callback que se ejecuta al volver el resultado

Name Type Description
callbackFn function

Callback Function after calculate route

callbackErrorFn function

Callback Error Function after calculate route error.

Clear all option values to calculate route.

getDeparturetime(){string}

Returns:
Departuretime

Get route destination position

Returns:
lonLat Destination

getDestinationIsDepot(){boolean}

Returns:
Get destinationisdepot parameter value.

getEdges(){boolean}

Returns:
edges true or false if edges option is enabled.

getInfoedges(){boolean}

Returns:
edges true or false if edges option is enabled.

getMindist(){number}

Returns:
Get minimum distance option.

getNumSteps(){number}

Return number of way points.

Returns:
Number of way points.

Get route origin position

Returns:
lonLat Origin

getOriginIsDepot(){boolean}

Returns:
Get originisdepot parameter value.

getPoicats(){Array.<string>}

Returns:
poicats Array of POI categories.

getResponse(){Object}

Get response

Returns:
response

getRouteId(routeIndex){string|null}

Get Route Id (internal id from Cercalia servers)

Name Type Description
routeIndex number (defaults to 0)

Route index alternative.

Returns:
Cercalia route id

getShowBreaktimes(){boolean}

Returns:
Show break times.

Obtiene stages.

Name Type Description
routeIndex number (defaults to 0)

Route index alternative.

Returns:
WKT de la ruta calculada. Devuelve null si no se ha calculado ninguna

Get all steps

Returns:
Steps

getTolerance(){number}

Returns:
tolerance

getTollX(){string}

Returns:
intoll_x Get ifalculating route using roads with tolls is enabled.

getWeight(){string}

Get route weight time|realtime|money|distance

Returns:
Route weight

getWKT(routeIndex){string|null}

Obtiene WKT de la ruta calculada

Name Type Description
routeIndex number (defaults to 0)

Route index alternative.

Returns:
WKT de la ruta calculada. Devuelve null si no se ha calculado ninguna

isAlternatives(){boolean}

Returns:
Return if alternatives flag is enabled

isLogistics(){boolean}

Returns:
true if route has logistics parameters.

isReady(){boolean}

Returns true if it is ready to calculate. When options has been set. (minimum origin and destination)

Returns:
true if can calculate route.

isReorder(){boolean}

Get if reorder options to calculate route is enabled.

Returns:
Reorder true or false.

isReporting(){boolean}

Returns:
report true if report is enabled. Else false.

isToll(){boolean}

Get if toll option is enabled.

Returns:
Toll is true or false.

setAlternatives(destinationIsDepot)

Enable alternatives routing calculation

Name Type Description
destinationIsDepot boolean

Enable alternatives flag

setDeparturetime(departuretime)

Name Type Description
departuretime string

Departuretime. Example: 2019-08-26T11:49+02:00-

setDestination(destination)

Set route destination

Name Type Description
destination module:cercaliagl/LonLat~LonLat | module:cercaliagl/service/Routing~RoutingStep

Destination

setDestinationIsDepot(destinationIsDepot)

Name Type Description
destinationIsDepot boolean

Enable destinationisdepot parameter

setEdges(edges)

Set to get edges from route calculation.

Name Type Description
edges number

Edges options enabled true. Else false.

setInfoedges(infoedges)

Adds specific information for each section to the route report.
An infoedges tag is added to each substage with specific information of each section.
The following attributes are reported for each section:
height: height from sea level in meters.
gradient: slope of the section
geometry: Stretch geometry
meters: Length of the section
maxkph: Legal maximum speed

Name Type Description
infoedges boolean

Enable true. Else false.

setLogistics(isLogistics)

Name Type Description
isLogistics boolean

Enable logistic route.

setLogisticsParams(logisticsParams)

Name Type Description
logisticsParams

Logistics params.

Name Type Description
vweight number

Vehicle max wegiht

vaxleweight number

Vehicle max axle weight

vheight number

Vehicle max height

vlength number

Vehicle max length

vwidth number

Vehicle max width

vmaxvel number

Vehicle max speed

rimp boolean

Dangerous goods

trinfodate string

YYYYMMDD

trinfodays number

Number days to consecutives to show restrictions.

trstart number

Avoid route restrictions. In timestamp format.

setMindist(mindist)

Set minimum distance option.

Name Type Description
mindist number

Minimum distance

setOrigin(origin)

Set route origin

Name Type Description
origin module:cercaliagl/LonLat~LonLat | module:cercaliagl/service/Routing~RoutingStep

Origin

setOriginIsDepot(originIsDepot)

Name Type Description
originIsDepot boolean

Enable originisdepot parameter

setPoicats(poicats)

Name Type Description
poicats Array.<string>

Array of POI categories.

setReorder(reorder)

Enable calculation route reorder points in calculation.

Name Type Description
reorder boolean

true or false.

setReporting(reporting)

Enable route report.

Name Type Description
reporting boolean

Boolean to enable route report. (First need to calculate route).

setShowBreaktimes(showBreakTimes)

Name Type Description
showBreakTimes boolean

Show break times.

setSteps(steps)

Set steps passing an array.

Name Type Description
steps Array.<(module:cercaliagl/LonLat~LonLat|module:cercaliagl/service/Routing~RoutingStep)>

Steps.

setTolerance(tolerance)

Route tolerance

Name Type Description
tolerance number

Tolerance

setToll(toll)

Enable tolls in route calculation.

Name Type Description
toll boolean

true or false.

setTollX(intoll_x)

Name Type Description
intoll_x string

Calculating route using roads with tolls.

setTwoDrivers(twoDrivers)

Name Type Description
twoDrivers boolean

Two drivers in the vehicle

setWeight(weight)

Set weight to calculate route. Weight values available: time|realtime|money|distance

Name Type Description
weight string

Weight. time|realtime|money|distance