---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md
  - https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/behavior.RouteEditor.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/jsapi-v2-1/doc/en/llms.txt

# behavior.RouteEditor

Extends [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md).

"Route editor" behavior.

[Constructor](#constructor-summary) | [Fields](#properties-summary) | [Events](#events-summary) | [Methods](#methods-summary)

## Constructor {#constructor-summary}

```javascript
behavior.RouteEditor()
```

## Fields {#properties-summary}

#|
|| **Name** | **Type** | **Description** ||
|| [events](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events) | [IEventManager](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventManager.md)| Event manager.

Inherited from [IEventEmitter](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events). ||
|| [options](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options) | [IOptionManager](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IOptionManager.md)| Options manager.

Inherited from [ICustomizable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options). ||
|#

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [disable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#event-disable)| Disabling behaviors.

Inherited from [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#event-disable). ||
|| [enable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#event-enable)| Enabling behaviors.

Inherited from [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#event-enable). ||
|| [optionschange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange)| Change to the object options.

Inherited from [ICustomizable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange). ||
|| [parentchange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange)| The parent object reference changed.

Data fields:

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

Inherited from [IChild](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange). ||
|| [routechange](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md#event-routechange)| A changed route event resulting from calling the setState method or enabling/disabling behaviors. You can get the old and new routes from the properties of the "oldRoute" and "newRoute" events, respectively. ||
|#

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [disable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#disable)() | | Disables the behavior.

Inherited from [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#disable). ||
|| [enable](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#enable)() | | Enables the behavior.

Inherited from [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#enable). ||
|| [getParent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md#getParent)() | [IParentOnMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md)\|null
| Returns link to the parent object, or null if the parent element was not set.

Inherited from [IChildOnMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md#getParent). ||
|| [getRoute](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md#getRoute)() | [router.Route](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/router.Route.md)
| Returns route. ||
|| [getState](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md#getState)() | String
| Returns the current state of the route editor in encoded format. ||
|| [isEnabled](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#isEnabled)() | Boolean
| Checks whether the behavior is enabled.

Inherited from [IBehavior](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IBehavior.md#isEnabled). ||
|| [setParent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md#setParent)([parent](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md#setParent-param-parent)) | [IChildOnMap](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md)
| 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](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md#setParent). ||
|| [setState](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md#setState)([state](https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/behavior.RouteEditor.md#setState-param-state)) | | Restores the state of the route editor from the encoded string. When setting a new route, the "routechange" event is called. ||
|#

## Events details {#event_detail}

### routechange {#routechange}

A changed route event resulting from calling the setState method or enabling/disabling behaviors. You can get the old and new routes from the properties of the "oldRoute" and "newRoute" events, respectively.

## Methods details {#method_detail}

### getRoute {#getRoute}

```javascript
{router.Route} getRoute()
```

**Returns** route.

### getState {#getState}

```javascript
{String} getState()
```

**Returns** the current state of the route editor in encoded format.

### setState {#setState}

```javascript
{} setState(state)
```

Restores the state of the route editor from the encoded string. When setting a new route, the "routechange" event is called.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`state`](#setState-param-state)[*](*star) | — | Type: String\|null

Encoded state of the route editor. The state is set in the following format: rt=point1~point2~point3~point4...&via=via-point-indexes For example, if the encoded string looks like this: "rt=50,30~42,35~45,32~40,30&via=1,2", it means the waypoints on the route should be "50,30" and "40,30", and the midpoints are "42,35" and "45,32". If the "via" parameter is omitted, the route will consist solely of waypoints. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
var behavior = map.behaviors.get('routeEditor');
behavior.events.add('routechange', function (e) {
   var newRoute = e.get('newRoute');
   alert(newRoute.getLength()); // length of the new route
   setTimeout(function () {
       // deleting the route
       behavior.setState(null);
   })
});
behavior.setState('rt=55.874872,37.562677~55.92517867214157,37.62725433916199~55.920011490602526,37.6629269628905&via=1');
```

[*star]: Mandatory parameter/option.