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

model*

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.

options

Type: Object

Multi-route options. To define options for the parts of a multi-route, use the following prefixes:

  • wayPoint - Waypoint options.
  • wayPointStart - Display options for the starting waypoint.
  • wayPointFinish - Display options for the end waypoint.
  • viaPoint - Throughpoint options.
  • pin - Options for point markers on the route.
  • editor - Options for the multi-route editor (see multiRouter.Editor).
    To define options for individual routes within a multi-route, use the following prefixes:
  • route - Options for routes, including inactive ones.
  • routeActive - Options for the active route.
    Note that options specified with the "routeActive" prefix have a higher priority than the options with the "route" prefix. To define options for segments of public transport routes, use the following prefixes:
  • routeMarker - Options for route segment markers.
  • routeWalkMarker - Options for markers of walking segments on the route.
  • routeTransferMarker - Options for transfer segment markers.
  • routeTransportMarker - Options for transit segment markers on the route.
  • routeWalkSegment - Options for walking segment lines on the route.
  • routeTransferSegment - Options for transfer segment lines.
  • routeTransportSegment - Options for transit segment lines on the route.
  • routePedestrianSegment - Options for pedestrian route segment lines.
    These prefixes are also available in the "routeActive*" version.

options.activeRouteAutoSelection

true

Type: Boolean

After the data is refreshed, automatically use the route with the shortest travel time as the active route.

options.boundsAutoApply

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.

options.dragUpdateInterval

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.

options.preventDragUpdate

false

Type: Boolean

Allows to disable the route update while reference points are being dragged.

options.useMapMargin

true

Type: Boolean

Whether to account for map margins map.margin.Manager.

options.zoomMargin

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

editor

multiRouter.EditorAddon

Multiroute editor.

events

IEventManager

Event manager.

Inherited from IDomEventEmitter.

geometry

IGeometry|null

Geo object geometry.

Inherited from IGeoObject.

model

multiRouter.MultiRouteModel

The data model of a multi-route.

options

IOptionManager

Options manager.

Inherited from ICustomizable.

properties

IDataManager

Geo object data.

Inherited from IGeoObject.

state

IDataManager

State of the geo object.

Inherited from IGeoObject.

Events

Name

Description

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.

click

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.

contextmenu

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.

dblclick

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.

geometrychange

Change to the geo object geometry. Instance of the Event class. Names of fields that are available via the Event.get method:

  • originalEvent: IEvent - Original event of the geometry.

Inherited from IGeoObject.

mapchange

Map reference changed. Data fields:

  • oldMap - Old map.
  • newMap - New map.

Inherited from IParentOnMap.

mousedown

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.

mouseenter

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.

mouseleave

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.

mousemove

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.

mouseup

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.

multitouchend

End of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface.

Inherited from IDomEventEmitter.

multitouchmove

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:

  • clientX - X coordinate of the touch relative to the viewable area of the browser.
  • clientY - Y coordinate of the touch relative to the viewable area of the browser.
  • pageX - X coordinate of the touch relative to the beginning of the document.
  • pageY - Y coordinate of the touch relative to the beginning of the document.

Inherited from IDomEventEmitter.

multitouchstart

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:

  • clientX - X coordinate of the touch relative to the viewable area of the browser.
  • clientY - Y coordinate of the touch relative to the viewable area of the browser.
  • pageX - X coordinate of the touch relative to the beginning of the document.
  • pageY - Y coordinate of the touch relative to the beginning of the document.

Inherited from IDomEventEmitter.

optionschange

Change to the object options.

Inherited from ICustomizable.

overlaychange

Change to the geo object overlay. Instance of the Event class. Names of fields that are available via the Event.get method:

  • overlay: IOverlay|null - Reference to the overlay.
  • oldOverlay: IOverlay|null - Previous overlay of the geo object.

Inherited from IGeoObject.

parentchange

The parent object reference changed.

Data fields:

  • oldParent - Old parent.
  • newParent - New parent.

Inherited from IChild.

pixelboundschange

Changing pixel coordinates of the area covering the multi-route. Instance of the Event class.

propertieschange

Change to the geo object data. Instance of the Event class. Names of fields that are available via the Event.get method:

  • originalEvent: IEvent - Original event of the data manager.

Inherited from IGeoObject.

update

Updating the multi-route. Instance of the Event class.

wheel

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

getActiveRoute()

multiRouter.driving.Route|multiRouter.masstransit.Route|null

Returns active route.

getBounds()

Number[][]|null

Returns the geographical coordinates of the area covering the multi-route.

getMap()

Map

Returns reference to the map.

Inherited from IParentOnMap.

getOverlay()

vow.Promise

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.

getOverlaySync()

IOverlay|null

The method provides synchronous access to the overlay.

Inherited from IGeoObject.

getParent()

IParentOnMap|null

Returns link to the parent object, or null if the parent element was not set.

Inherited from IChildOnMap.

getPixelBounds()

Number[][]|null

Returns the global pixel coordinates of the area covering the multi-route.

getRoutes()

GeoObjectCollection

Returns child collection of individual routes on the multi-route.

getViaPoints()

GeoObjectCollection

Returns child collection of throughpoints for the multi-route.

getWayPoints()

GeoObjectCollection

Returns child collection of waypoints for the multi-route.

setActiveRoute(route)

Sets the active route. The previous active route is deactivated and the multiRouter.MultiRoute.event:activeroutechange event is generated.

setParent(parent)

IChildOnMap

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

route*

Type: multiRouter.driving.Route|multiRouter.masstransit.Route|null

Route to activate.

* Mandatory parameter/option.