Maps SDK for Web

Class TrafficFlowSegmentData

The Flow Segment Data service provides information about the speeds and travel times of the road fragment closest to the given coordinates.

Constructor

TrafficFlowSegmentData(options)

Parameters
Name Description Required Type/Values Default
options Options to be passed to the flowSegmentData call. Yes Object None
options.point Coordinates of the point close to the road segment. Yes String None
options.key Traffic Flow API key that can be obtained from TomTom's developer portal. Yes String None
options.style The type of flow data to be displayed on the tile. Available options: absolute, relative, relative-delay. Yes String None
options.zoom Zoom level. This will affect traffic incident coordinates to present both road sides separately. Yes Number None
options.unit Unit of speed. Available options: KMPH, MPH. No String KMPH
options.thickness Segment width multiplier. Accepts values in range from 0 to 20. No Number 10
options.fail The callback function to be called on failure. No Function None
options.callback The callback function to be called on success. Yes Function None
options.openLr Specifies if response include OpenLR code. Yes Boolean None

Methods

callback([newValue]): Function Chainable

Sets or gets the value of the option callback.

This callback function will be called only after the go method successfully complete its task.

Its first and unique argument passed to the callback will be the result of the request.

Parameters
Name Description Required Type/Values Default
newValue The new callback function No Function None
Throws

If the given argument is not a function

Returns

The same service instance or the current callback function if no argument was given

Example
function callbackFn(results) {
  console.log(results);
}
tomtom.fuzzySearch()
  .query("pizza")
  .callback(callbackFn)
  .go();

fail([newValue]): Function Chainable

Sets or gets the value of the option fail.

This function is called when an error occurs (e.g. invalid values or a communication error).

The callback will receive just one argument which is the error description.

This parameter will be ignored if the callback function is not defined and therefore the go method will return a Promise that will be rejected if an error occurs.

If you don't specificy a failure callback, the default behavior in case of encounter a problem is to throw an error.

Parameters
Name Description Required Type/Values Default
newValue The new callback function No Function None
Throws

If the given argument is not a function

Returns

The same service instance or the current callback function if no argument was given

Example
function successCallback(results) {
  console.log(results);
}
function failureCallback(error) {
  console.log(error);
}
tomtom.fuzzySearch()
  .query("pizza")
  .callback(successCallback)
  .fail(failureCallback)
  .go();

go([success], [fail]): Promise | Null

Executes a predefined asynchronous task using the current configuration and then execute one of the callback functions based on the success of the result.

It receives two optional arguments. The first one is a callback function that will be used when the task is successfully completed. The second one is another callback function that will be used only in case of failure.

Both arguments are shortcuts for the callback and fail methods respectively.

Parameters
Name Description Required Type/Values Default
success The callback function to be called on case of success No Function None
fail The callback function to be called on case of failure. If a success callback was not given this argument will be ignored. In that case the returned Promise should be used to handle the failures. No Function None
Returns

If the success callback is omitted (and wasn't defined one yet) this function will return a Promise

Example

All the ways of using this method:

// Defining callbacks as function arguments
tomtom.fuzzySearch()
  .query("pizza")
  .go(successCallback, failureCallback);

// Defining callbacks using setters methods
tomtom.fuzzySearch()
  .query("pizza")
  .callback(successCallback)
  .fail(failureCallback)
  .go();

// Using the returned Promise
tomtom.fuzzySearch()
  .query("pizza")
  .go()
  .then(successCallback)
  .catch(failureCallback);

The SDK provides a Promise polyfill for browsers (IE<9) without native ECMAScript 6 support.

key([newValue]): String Chainable

Sets or returns the API key to be used in calls made by this service instance.

Setting a key for each instance of this class is not needed if the key was already setted globally using the tomtom.searchKey() function.

A valid API key is required to make use of the Search API services. It can be issued from TomTom's Developer Portal.

Parameters
Name Description Required Type/Values Default
newValue key API Key valid for requested service No String None
Throws

If the given argument cannot be converted to a valid value

Returns

The same service instance or the current option value if no argument was given

openLr(openLr): String Chainable

Parameters
Name Description Required Type/Values Default
openLr Specifies if response include OpenLR code. Yes Boolean None
Throws

Returns

The same service instance or the current option value if no argument was given

point(point): String Chainable

Parameters
Name Description Required Type/Values Default
point Coordinates of the point close to the road segment. They have to be comma-separated and calculated using EPSG4326 projection. Yes String None
Throws

Returns

The same service instance or the current option value if no argument was given

style(style): String Chainable

Parameters
Name Description Required Type/Values Default
style The type of flow data to be displayed on the tile. Available options: absolute, relative, relative-delay. Yes String None
Throws

Returns

The same service instance or the current option value if no argument was given

thickness(thickness): String Chainable

Parameters
Name Description Required Type/Values Default
thickness Segment width multiplier. Value should be in range from 1 to 20. Yes Integer None
Throws

Returns

The same service instance or the current option value if no argument was given

unit(unit): String Chainable

Parameters
Name Description Required Type/Values Default
unit Unit of speed. Avilable values: KMPH, MPH. Yes String None
Throws

Returns

The same service instance or the current option value if no argument was given

zoom(zoom): String Chainable

Parameters
Name Description Required Type/Values Default
zoom Zoom level. This will affect traffic incident coordinates to present both road sides separately. Should be in range from 0 to 18. Yes Integer None
Throws

Returns

The same service instance or the current option value if no argument was given