multiRouter.MultiRoute
Extends IGeoObject.
Multi-route on the map. Displays the route on the map along with one or more alternatives. Provides the interface for selecting the active route.
Constructor | Fields | Events | Methods
Constructor
multiRouter.MultiRoute(model[, options])
Creates a multi-route on the map.
Parameters:
Parameter |
Default value |
Description |
— |
Type: multiRouter.MultiRouteModel|IMultiRouteModelJson The data model of a multi-route, or the model description object. If you pass a description object, the model (which is based on it) is created automatically. |
|
— |
Type: Object Multi-route options. To define options for the parts of a multi-route, use the following prefixes:
|
|
true |
Type: Boolean After the data is refreshed, automatically use the route with the shortest travel time as the active route. |
|
false |
Type: Boolean When adding a multi-route to the map, you can automatically set the center and the zoom level so that the multi-route is entirely visible. |
|
— |
Type: String|Number Time interval of rebuilding the route while reference points are being dragged. Can be set in milliseconds, or the optimal value can be calculated automatically. The value of this option is translated to the IMultiRouteParams.requestSendInterval parameter of the multi-route. |
|
false |
Type: Boolean Allows to disable the route update while reference points are being dragged. |
|
true |
Type: Boolean Whether to account for map margins map.margin.Manager. |
|
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" option 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.
// Creating a multi-route and adding it to the map.
var multiRoute = new ymaps.multiRouter.MultiRoute({
referencePoints: ['Moscow, Leninsky Prospekt', 'Moscow, Kulakov pereulok'],
}, {
editorDrawOver: false,
wayPointDraggable: true,
viaPointDraggable: true,
// Setting a custom design for multi-route lines.
routeStrokeColor: "000088",
routeActiveStrokeColor: "ff0000",
pinIconFillColor: "ff0000",
boundsAutoApply: true,
zoomMargin: 30
});
myMap.geoObjects.add(multiRoute);
2.
// Creating a multi-route and adding it to the map.
var multiRoute = new ymaps.multiRouter.MultiRoute({
referencePoints: ['Moscow, Leninsky Prospekt', 'Moscow, Kulakov pereulok', 'Zelenograd'],
});
myMap.geoObjects.add(multiRoute);
// Once multi-route is loaded.
multiRoute.events.once('update', function () {
// Set first non-blocked route as active and open it's balloon.
var routes = multiRoute.getRoutes();
for (var i = 0, l = routes.getLength(); i < l; i++) {
var route = routes.get(i);
if (!route.properties.get('blocked')) {
multiRoute.setActiveRoute(route);
route.balloon.open();
break;
}
}
});
Fields
Name |
Type |
Description |
Multiroute editor. |
||
Event manager. Inherited from IDomEventEmitter. |
||
IGeometry|null |
Geo object geometry. Inherited from IGeoObject. |
|
The data model of a multi-route. |
||
Options manager. Inherited from ICustomizable. |
||
Geo object data. Inherited from IGeoObject. |
||
State of the geo object. Inherited from IGeoObject. |
Events
Name |
Description |
|
Change to the active route. Instance of the Event class. Names of fields that are available via the Event.get method:
|
||
Closing the balloon. Names of fields that are available via the Event.get method:
|
multiRouter.masstransit.Route|null - route on which balloon was closed. |
|
Opening the balloon. Names of fields that are available via the Event.get method:
|
multiRouter.driving.Route|multiRouter.masstransit.Route|null - route on which balloon was opened. |
|
The event occurs at the time of setting the map center and its zoom level for optimal display of the multi-route. Also see the description of the boundsAutoApply option. Instance of the Event class. |
||
Changing coordinates of the geographical area covering the multi-route. Instance of the Event class. |
||
Single left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Calls the element's context menu. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Double left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Change to the geo object geometry. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
||
Map reference changed. Data fields:
Inherited from IParentOnMap. |
||
Pressing the mouse button over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Pointing the cursor at the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Moving the cursor off of the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Moving the cursor over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
Letting go of the mouse button over an object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
||
End of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface. Inherited from IDomEventEmitter. |
||
Repeating event during multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:
Inherited from IDomEventEmitter. |
||
Start of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:
Inherited from IDomEventEmitter. |
||
Change to the object options. Inherited from ICustomizable. |
||
Change to the geo object overlay. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
||
The parent object reference changed. Data fields:
Inherited from IChild. |
||
Changing pixel coordinates of the area covering the multi-route. Instance of the Event class. |
||
Change to the geo object data. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
||
Updating the multi-route. Instance of the Event class. |
||
Mouse wheel scrolling. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
Methods
Name |
Returns |
Description |
multiRouter.driving.Route|multiRouter.masstransit.Route|null |
Returns active route. |
|
Number[][]|null |
Returns the geographical coordinates of the area covering the multi-route. |
|
getMap() |
Returns reference to the map. Inherited from IParentOnMap. |
|
Returns the promise object, which is confirmed by the overlay object at the time it is actually created, or is rejected with an appropriate error message. Inherited from IGeoObject. |
||
IOverlay|null |
The method provides synchronous access to the overlay. Inherited from IGeoObject. |
|
IParentOnMap|null |
Returns link to the parent object, or null if the parent element was not set. Inherited from IChildOnMap. |
|
Number[][]|null |
Returns the global pixel coordinates of the area covering the multi-route. |
|
Returns child collection of individual routes on the multi-route. |
||
Returns child collection of throughpoints for the multi-route. |
||
Returns child collection of waypoints for the multi-route. |
||
Sets the active route. The previous active route is deactivated and the multiRouter.MultiRoute.event:activeroutechange event is generated. |
||
Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object. Inherited from IChildOnMap. |
Fields details
editor
{multiRouter.EditorAddon} editor
Multiroute editor.
Example:
// Start of route editing.
ymaps.route(['Moscow', 'Petersburg'], { multiRoute: true })
.done(function (multiRoute) {
myMap.geoObjects.add(multiRoute);
multiRoute.editor.start({
addWayPoints: true,
removeWayPoints: true
});
// ...
// End of route editing.
multiRoute.editor.stop();
});
model
{multiRouter.MultiRouteModel} model
The data model of a multi-route.
Events details
activeroutechange
Change to the active route. Instance of the Event class. Names of fields that are available via the Event.get method:
- oldActiveRoute: multiRouter.driving.Route|multiRouter.masstransit.Route|null - previous active route.
balloonclose
Closing the balloon. Names of fields that are available via the Event.get method:
- originalTarget: multiRouter.pedestrian.Route|multiRouter.driving.Route|multiRouter.masstransit.Route|null - route on which balloon was closed.
balloonopen
Opening the balloon. Names of fields that are available via the Event.get method:
- originalTarget: multiRouter.pedestrian.Route|multiRouter.driving.Route|multiRouter.masstransit.Route|null - route on which balloon was opened.
boundsautoapply
The event occurs at the time of setting the map center and its zoom level for optimal display of the multi-route. Also see the description of the boundsAutoApply option. Instance of the Event class.
boundschange
Changing coordinates of the geographical area covering the multi-route. Instance of the Event class.
pixelboundschange
Changing pixel coordinates of the area covering the multi-route. Instance of the Event class.
update
Updating the multi-route. Instance of the Event class.
Methods details
getActiveRoute
{multiRouter.driving.Route|multiRouter.masstransit.Route|null} getActiveRoute()
Returns active route.
getBounds
{Number[][]|null} getBounds()
Returns the geographical coordinates of the area covering the multi-route.
getPixelBounds
{Number[][]|null} getPixelBounds()
Returns the global pixel coordinates of the area covering the multi-route.
getRoutes
{GeoObjectCollection} getRoutes()
Returns child collection of individual routes on the multi-route.
getViaPoints
{GeoObjectCollection} getViaPoints()
Returns child collection of throughpoints for the multi-route.
getWayPoints
{GeoObjectCollection} getWayPoints()
Returns child collection of waypoints for the multi-route.
setActiveRoute
{} setActiveRoute(route)
Sets the active route. The previous active route is deactivated and the multiRouter.MultiRoute.event:activeroutechange event is generated.
Parameters:
Parameter |
Default value |
Description |
— |
Type: multiRouter.driving.Route|multiRouter.masstransit.Route|null Route to activate. |
* Mandatory parameter/option.
Mandatory parameter/option.