Class: Distance

cercaliagl.service/Distance


Service class to calculate distance between two or more points.
It can calculate distance by weight. Weight available are: `

new Distance(opt_options)

Name Type Description
options

Params and options for distance calculation

Name Type Description
calculateGeometry boolean

Specify if you need to obtain the shape geometry when calculating the distance. For weight=='line' this option is not avaliable.

origin module:cercaliagl/LonLat~LonLat

Origin. If not defined, then use setOrigin to initialize variable;

destination module:cercaliagl/LonLat~LonLat

Destination. If not defined, then use setDestination to initialize variable;

steps Array.<module:cercaliagl/LonLat~LonLat>

Sequential stop list.

weight string | undefined

Distance calculation considering weight/type line|time|distance|money. Default value line.

Extends

  • module:cercaliagl/service/Service~Service

Methods

module:cercaliagl/service/Distance~Distance.calculateDistanceOnArea(area){number}

Name Type Description
area GeoJSON
Returns:
Distance in quare meters

module:cercaliagl/service/Distance~Distance.calculateDistanceOnLine(line, units){number}

Name Type Description
line GeoJSON

LineString || MultiLineString

units string

Kilometers || miles || radians || degrees. Kilometers by default

Returns:
Distance in the specified units

calculate(callbackFn)

Distance calculation with the assigned parameters, and returns the data to the callback function which is called once server returns response.

Name Type Description
callbackFn function

Callback function

Returns the destination.

Returns:
Destination point

Obtain origin.

Returns:
Returns the origin assigned previously

Get steps (or waypoints)

Returns:
Steps

getWeight(){string}

Get weight. Available values line|time|distance|money

Returns:
weight

isCalculateGeometry(){boolean}

Returns if calculate geometry functionality is active or inactive

Returns:
calculateGeometry true or false. If calculate geometry option is enabled.

setCalculateGeometry(calculateGeometry)

Name Type Description
calculateGeometry boolean

true if geometry will be returned after calculation..

setDestination(lonLat)

Set destination point.

Name Type Description
lonLat module:cercaliagl/LonLat~LonLat

Destination point

setOrigin(lonLat)

Set origin point.

Name Type Description
lonLat module:cercaliagl/LonLat~LonLat

Origin point

setSteps(steps)

Set steps (or waypoints)

Name Type Description
steps Array.<module:cercaliagl/LonLat~LonLat>

Array with steps

setWeight(weight)

Set weight to calculate distance

Name Type Description
weight string

Weight. Available values line|time|distance|money