multiRouter.MultiRouteModel

Extends IEventEmitter.

The data model of a multiroute.

Constructor | Fields | Events | Methods

Constructor

multiRouter.MultiRouteModel(referencePoints[, params])

Creates the data model of a multiroute.

Parameters:

Parameter

Default value

Description

referencePoints*

Type: IMultiRouteReferencePoint[]

The description of the reference points on the multiroute.

params

Type: IMultiRouteParams

Routing options.

* Mandatory parameter/option.

Example:

// Creating a model of the multiroute.
var multiRouteModel = new ymaps.multiRouter.MultiRouteModel(['Moscow', 'Tver', 'Peterburg'], {
    avoidTrafficJams: true,
    viaIndexes: [1]
});

// Creating a representation of a multiroute based on the model.
var multiRouteView = new ymaps.multiRouter.MultiRoute(multiRouteModel);
myMap.geoObjects.add(multiRouteView);

// Subscribing to the events of the multiroute model.
multiRouteView.model.events
    .add("requestsuccess", function (event) {
        var routes = event.get("target").getRoutes();
        console.log("Found routes: " + routes.length);
        for (var i = 0, l = routes.length; i < l; i++) {
            console.log("Route length " + (i + 1) + ": " + routes[i].properties.get("distance").text);
        }
    })
    .add("requestfail", function (event) {
        console.log("Error: " + event.get("error").message);
    });

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

properties

data.Manager

Multiroute data.

Events

Name

Description

requestcancel

The data request has been canceled. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing options.

requestchange

The reference data model of a multiroute (anchor points or routing options) has been changed. The result is a new data request to the routing service. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing parameters.
  • oldReferencePoints: Object[] - Array describing the previous array of reference points.
  • oldParams: Object - Previous routing options.

requestfail

The request for data has failed. Instance of the Event class. Names of fields that are available via the Event.get method:

  • error: Error - error object.

requestsend

A new request for the multiroute data model has been sent. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing options.

requestsuccess

The request for data has completed successfully and the data model has been updated. Instance of the Event class. Names of fields that are available via the Event.get method:

  • init: Boolean - Indicates an initialization request.
  • rough: Boolean - Indicates whether it is an intermediate request (used to optimize the size of the server response when editing a route).
  • wayPointsChange: Boolean - Indicates whether the set of waypoints changed.
  • viaPointsChange: Boolean - Indicates whether the set of throughpoints changed.
  • routesChange: Boolean - Indicates whether the set of routes changed.

Methods

Name

Returns

Description

destroy()

Destroys a model.

getAllPoints()

(multiRouter.WayPointModel|multiRouter.ViaPointModel)[]

Returns the combined array of models of throughpoints and waypoints, in the same order as the corresponding reference points.

getJson()

Object

Returns JSON data for the multiroute model.

getParams()

IMultiRouteParams

Returns the object with the current values of routing options.

getPoints()

(multiRouter.WayPointModel|multiRouter.ViaPointModel)[]

Deprecated name of the multiRouter.MultiRouteModel.getAllPoints method. Not recommended for use.

getReferencePointIndexes()

Object

Returns an object containing the following data fields:

  • way: Integer[] - Indexes of reference points corresponding to the set of the model's waypoints.
  • via: Integer[] - Indexes of reference points corresponding to the set of the model's throughpoints.

getReferencePoints()

IMultiRouteReferencePoint[]

Returns array of reference points on the multiroute.

getRoutes()

multiRouter.driving.RouteModel[]|multiRouter.masstransit.RouteModel[]

Returns an array of models for child routes.

getViaPoints()

multiRouter.ViaPointModel[]

Returns an array of models for child throughpoints.

getWayPoints()

multiRouter.WayPointModel[]

Returns an array of models for child waypoints.

setParams(params[, extend[, clearRequests]])

Sets routing options.

setReferencePoints(referencePoints[, viaIndexes[, clearRequests]])

Sets the reference points on the multiroute.

Fields details

properties

{data.Manager} properties

Multiroute data.

Events details

requestcancel

The data request has been canceled. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing options.

requestchange

The reference data model of a multiroute (anchor points or routing options) has been changed. The result is a new data request to the routing service. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing parameters.
  • oldReferencePoints: Object[] - Array describing the previous array of reference points.
  • oldParams: Object - Previous routing options.

requestfail

The request for data has failed. Instance of the Event class. Names of fields that are available via the Event.get method:

  • error: Error - error object.

requestsend

A new request for the multiroute data model has been sent. Instance of the Event class. Names of fields that are available via the Event.get method:

  • referencePoints: Object[] - Array describing the set of reference points.
  • params: Object - Routing options.

requestsuccess

The request for data has completed successfully and the data model has been updated. Instance of the Event class. Names of fields that are available via the Event.get method:

  • init: Boolean - Indicates an initialization request.
  • rough: Boolean - Indicates whether it is an intermediate request (used to optimize the size of the server response when editing a route).
  • wayPointsChange: Boolean - Indicates whether the set of waypoints changed.
  • viaPointsChange: Boolean - Indicates whether the set of throughpoints changed.
  • routesChange: Boolean - Indicates whether the set of routes changed.

Methods details

destroy

{} destroy()

Destroys a model.

getAllPoints

{(multiRouter.WayPointModel|multiRouter.ViaPointModel)[]} getAllPoints()

Returns the combined array of models of throughpoints and waypoints, in the same order as the corresponding reference points.

getJson

{Object} getJson()

Returns JSON data for the multiroute model.

getParams

{IMultiRouteParams} getParams()

Returns the object with the current values of routing options.

getPoints

{(multiRouter.WayPointModel|multiRouter.ViaPointModel)[]} getPoints()

Deprecated name of the multiRouter.MultiRouteModel.getAllPoints method. Not recommended for use.

Returns the combined array of models of throughpoints and waypoints, in the same order as the corresponding reference points.

getReferencePointIndexes

{Object} getReferencePointIndexes()

Returns an object containing the following data fields:

  • way: Integer[] - Indexes of reference points corresponding to the set of the model's waypoints.
  • via: Integer[] - Indexes of reference points corresponding to the set of the model's throughpoints.

getReferencePoints

{IMultiRouteReferencePoint[]} getReferencePoints()

Returns array of reference points on the multiroute.

getRoutes

{multiRouter.driving.RouteModel[]|multiRouter.masstransit.RouteModel[]} getRoutes()

Returns an array of models for child routes.

getViaPoints

{multiRouter.ViaPointModel[]} getViaPoints()

Returns an array of models for child throughpoints.

getWayPoints

{multiRouter.WayPointModel[]} getWayPoints()

Returns an array of models for child waypoints.

setParams

{} setParams(params[, extend[, clearRequests]])

Sets routing options.

Parameters:

Parameter

Default value

Description

params*

Type: IMultiRouteParams

Routing options.

extend

false

Type: Boolean

Allows you to change only the specified set of parameters keeping all the rest of the values the same.

clearRequests

false

Type: Boolean

Allows you to clear the queue of previous requests to the server.

* Mandatory parameter/option.

setReferencePoints

{} setReferencePoints(referencePoints[, viaIndexes[, clearRequests]])

Sets the reference points on the multiroute.

Parameters:

Parameter

Default value

Description

referencePoints*

Type: IMultiRouteReferencePoint[]

Array of reference points.

viaIndexes

Type: Integer[]

Indexes of throughpoints in the array of reference points.

clearRequests

false

Type: Boolean

Allows you to clear the queue of previous requests to the server.

* Mandatory parameter/option.