route
Static function.
Plots a route through the specified points.
Returns a promise object that is confirmed by the route object router.Route, or the multiroute object multiRouter.MultiRoute, depending on the value of the multiRoute parameter. If an error occurs, the promise object is rejected.
{ vow.Promise } route(points[, params])
Parameters:
Parameter |
Default value |
Description |
— |
Type: Object[] Array of points that the route should go through. Each point can be set by a string containing the address, an array of the coordinates, and a JSON object with the following fields:
|
|
— |
Type: Object Routing options. |
|
false |
Type: Boolean Enables constructing a route with consideration for traffic. When using the options, keep in mind that it is not always possible to detour around traffic jams. |
|
— |
Type: Number[][] Area on the map where the objects being searched for are presumably located. This is used if the route points are set using the mailing address instead of coordinates. |
|
false |
Type: Boolean Flag that allows to automatically set the center and map zoom so that the route will be entirely visible. |
|
false |
Type: Boolean Allows to construct multiroutes. |
|
false |
Type: Boolean Whether to use reverse geocoding for points specified as coordinates. |
|
"auto" |
Type: String Routing type. Accepts one of three string values:
|
|
— |
Type: String Defines how to interpret the coordinates in the request. This is used if the route points are set using coordinates, and not the mailing address. |
|
false |
Type: Boolean Search only inside the area defined by the "boundedBy" option. |
|
true |
Type: Boolean Whether to account for map margins map.margin.Manager. |
|
[] |
Type: Integer[] Indexes of the multiroute throughpoints. |
|
0 |
Type: Number|Number[] Offset from the map viewport borders when changing the zoom level. If a single number is set, it is applied to each side. If two numbers are set, they are the horizontal and vertical margins, respectively. If an array of four numbers is set, they are the top, right, bottom, and left margins. When the "useMapMargin" parameter is enabled, the "zoomMargin" value is combined with the values that were calculated in the margins manager map.margin.Manager. |
* Mandatory parameter/option.
Examples:
1.
// Building the route from Korolev to Krasnogorsk via Khimki and Mytischi,
// where Mytischi is a throughpoint. Setting coordinates for Krasnogorsk.
ymaps.route([
'Korolev',
{ type: 'viaPoint', point: 'Mytischi' },
'Himki',
{ type: 'wayPoint', point: [55.811511, 37.312518] }
], {
mapStateAutoApply: true
}).then(function (route) {
route.getPaths().options.set({
// the balloon only shows information about the travel time with traffic
balloonContentLayout: ymaps.templateLayoutFactory.createClass('{{ properties.humanJamsTime }}'),
// you can make settings for route graphics
strokeColor: '0000ffff',
opacity: 0.9
});
// adding the route to the map
map.geoObjects.add(route);
});
2.
// Building a multiroute and adding it to the map using autoscaling.
ymaps.route(['Southern Butovo', 'Moscow, metro Park Kultury'], {
multiRoute: true
}).done(function (route) {
route.options.set("mapStateAutoApply", true);
myMap.geoObjects.add(route);
}, function (err) {
throw err;
}, this);
Mandatory parameter/option.