Class: MapRouting

cercaliagl.MapRouting


Useful class to interact with routing, map and menus. Never use constructor. To access to cercaliagl.MapRouting access it with module:cercaliagl/Map~Map#getMapRouting.

Example usage.

const map = new cercaliagl.Map({
  target: 'map',
  zoom: 7,
  center: new cercaliagl.LonLat(-1.8995067857179038, 40.77795650493354),
});

map.whenReady(() => {
  const routingMap = map.getMapRouting();
  const origin = new cercaliagl.LonLat(2.1589900, 41.3887900);
  const destination = new cercaliagl.LonLat(-3.7025600, 40.4165000);

  routingMap.disableAutoZoom(true);
  routingMap.setCustomCallbackFunction(() => {
    const notification = new cercaliagl.Notification('Route calculated', Severity.WARNING, 60000);
    notification.display(map);
  });

  routingMap.setRoutingStep(MarkerType.ORIGIN, origin);
  routingMap.setRoutingStep(MarkerType.DESTINATION, destination);
});

new MapRouting(options)

Name Type Description
options
Name Type Description
routing3d boolean

Draw 3D polyline for calculated route feature. Default true.

Extends

  • EventEmitter

Methods

addMarkerStep(marker, position, draggedPoint)

Add step/waypoint marker.

Name Type Description
marker module:cercaliagl/Marker~Marker

Marker

position number

Step position

draggedPoint boolean

true if is a dragged point.

calculateReport(callbackFn)

Calculate report and handle report in a callback function.

Name Type Description
callbackFn function

Callback function.

cleanRoute()

Delete route from map and its markers.

disableAutoZoom(autoZoomDisabled)

Disable auto zoom (center to features) after draw route feature.

Name Type Description
autoZoomDisabled boolean

true disables center to features after calculated route. false active restores default behaviour.

disableRightClickMenu()

Disable right click context menu. It is enabled by default.

enableRightClickMenu()

Enable right click context menu. It is enabled by default.

Get route features.

Returns:
Array feature.

Get route alternative features.

Returns:
Array feature.
Returns:
Routing options

Obtain routing service object.

Returns:
Routing service

getWKT(){string|null}

Obtain WKT

Returns:
WKT.

Invert origin and destination.

isActive(){boolean}

Return if MapRouting is active

Returns:
`truè if map routing is actived.

isLogistics(){boolean}

Obtain if logistics service mode is enabled.

Returns:
true if route is logistics.

removeFeatures()

Clear route features from map.

removeMarkers()

Clear route markers from map.

removeStepIndex(index)

Name Type Description
index number

Index.

selectAlternativeRoute(routeIndex)

Select active an alternative route by index.

Name Type Description
routeIndex number

Route index

set3DRouting(enable)

EXPERIMENTAL. Enable or not to draw 3D routes.

Name Type Description
enable boolean

Enable or disable to draw 3D features

setAddedCosts(consumption, gasType, gasPrice)

Update Routing widget costs.

Name Type Description
consumption number

Consumption L/100 km. Example: 8.2.

gasType string | undefined

Gas Type. Available values: gas95|gas98|diesel|biodiosel.

gasPrice number | undefined

Gasoline price. €/L. Example: 1.51.

setCustomCallbackErrorFunction(func)

Set custom callback error function. This function is called after route with errors.

Name Type Description
func function

Custom callback function to handle error

setCustomCallbackFunction(func)

Set custom callback function. This function is called after route calculation. Setting null, it disables previous custom function.

Name Type Description
func function

Custom callback function.

setDraggable(draggable)

Set route draggable and its steps

Name Type Description
draggable boolean

Draggable

setReorder(reorder){boolean}

Update route parameter option weight. Use this instead setWeight from cercalia.service.Routing.

Name Type Description
reorder boolean

Reorder

Returns:
Return true if route options has been modified

setRoutingOptions(options)

Name Type Description
options

Routing 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.

setRoutingStep(stepType, position, formattedAddress)

Set a routing step. It can be origin, destination or a step/waypoint.

Name Type Description
stepType string

Step type. Values origin|destination|step.

position module:cercaliagl/LonLat~LonLat

Position

formattedAddress string (defaults to false)

Formatted address.

setWeight(weight){boolean}

Update route parameter option weight. Use this instead setWeight from cercalia.service.Routing.

Name Type Description
weight string

Weight

Returns:
Return true if route options has been modified

updateOptions(weight, reorder, logisticsEnabled, logisticsParams, departuretime)

Name Type Description
weight string

Weight.

reorder boolean

Optimized route.

logisticsEnabled boolean

Enable or disable logistics params.

logisticsParams module:cercaliagl/MapRouting~LogisticsParams

Logistics params.

departuretime string (defaults to null)

Departure time

logisticsParams.vweight number

Vehicle max wegiht

logisticsParams.vaxleweight number

Vehicle max axle weight

logisticsParams.vheight number

Vehicle max height

logisticsParams.vlength number

Vehicle max length

logisticsParams.vwidth number

Vehicle max width

logisticsParams.vmaxvel number

Vehicle max speed

logisticsParams.rimp boolean

Dangerous goods

logisticsParams.trinfodate string

YYYYMMDD

logisticsParams.trinfodays number

Number days to consecutives to show restrictions.

logisticsParams.trstart number

Avoid route restrictions. In timestamp format.