Maps SDK for Web

Class StaticMapImage

This class makes it easy to generate URL string to request a static map image using the TomTom's Maps API - Static Image.

Parameters can be passed to the constructor or provided via convenient methods that can be chained until the method go generates the URL string.

Constructor

StaticMapImage([options])

Parameters
Name Description Required Type/Values Default
options No Object None
options.layer The base map's layer to be used No "basic" | "hybrid" | "labels" "basic"
options.style The base map style to be used. No "main" | "night" "main"
options.format The format of the image to be requested No "png" | "jpg" | "jpeg" "png"
options.key API key that can be obtained from TomTom's developer portal. No String None
options.zoom Positive integer between 0 and 20 No Number 12
options.center Coordinates to the center of the view No L.LatLng None
options.width Width of the image in pixels No Number None
options.height Height of the image in pixels No Number None
options.bbox Bounding box No L.LatLngBounds None
options.view Geopolitical view No String "Unified"
options.language Language to use for the labels. You can found the list of supported languages here. No String "NGT"
options.callback Callback function to use in case of success No Function None
options.fail Callback function to use in case of failure No Function default
Example
// Using chainable methods
function callbackFn(urlString) {
  console.log(urlString);
}
var sMap = tomtom.staticMapImage();
sMap.key('abdcef123456')
  .zoom(15)
  .center(L.latLng(50.5, 30.5))
  .width(600)
  .height(400)
  .format('jpg')
  .go()
  .then(callbackFn);
// Passing a object with all the configuration
function callbackFn(urlString) {
  console.log(urlString);
}
tomtom.staticMapImage({
  key: 'abdcef123456',
  zoom: 15,
  bbox: L.latLngBounds([
    [40.712, -74.227],
    [40.774, -74.125]
  ]),
}).go(callbackFn);

Methods

bbox([newValue]): Object Chainable

Getter and setter for the option bbox.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No L.LatLngBounds None
Returns

When is used as setter this method is chainable

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();

center([newValue]): String Chainable

Getter and setter for the option center.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No L.LatLng None
Returns

When is used as setter this method is chainable

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();

format([newValue]): String Chainable

Getter and setter for the option format.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No "png" | "jpg" | "jpeg" None
Returns

When is used as setter this method is chainable

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.

height([newValue]): String Chainable

Getter and setter for the option height.

Parameters
Name Description Required Type/Values Default
newValue New integer value to be set No Number None
Returns

When is used as setter this method is chainable

key([newValue]): String Chainable

Getter and setter for the option key.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No String None
Returns

When is used as setter this method is chainable

language([newValue]): String Chainable

Getter and setter for the option language.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No String None
Returns

When is used as setter this method is chainable

layer([newValue]): String Chainable

Getter and setter for the option layer.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No "basic" | "hybrid" | "labels" None
Returns

When is used as setter this method is chainable

style([newValue]): String Chainable

Getter and setter for the option style.

Parameters
Name Description Required Type/Values Default
newValue New value to be set No "main" | "night" None
Returns

When is used as setter this method is chainable

view([newValue]): String Chainable

Sets or returns the view option value to be used in the calls.

Can be one of "Unified", "IN", "PK", "IL and "MA" Legend: Unifies - International view IN - India PK - Pakistan IL - Israel MA - Morocco

Parameters
Name Description Required Type/Values Default
newValue New value to be set No String None
Returns

When is used as setter this method is chainable

width([newValue]): String Chainable

Getter and setter for the option width.

Parameters
Name Description Required Type/Values Default
newValue New integer value to be set No Number None
Returns

When is used as setter this method is chainable

zoom([newValue]): String Chainable

Getter and setter for the option zoom.

Parameters
Name Description Required Type/Values Default
newValue New integer value to be set No Number None
Returns

When is used as setter this method is chainable