EditorViewModel

AMD: require(["esri/widgets/Editor/EditorViewModel"], (EditorVM) => { /* code goes here */ });
ESM: import EditorVM from "@arcgis/core/widgets/Editor/EditorViewModel.js";
Class: esri/widgets/Editor/EditorViewModel
Inheritance: EditorViewModel Accessor
Since: ArcGIS Maps SDK for JavaScript 4.11

Provides the logic for the Editor widget.

See also
Example
const editor = new Editor({
  viewModel: { // autocasts as new EditorViewModel
    layerInfos: [{
      layer: featureLayer,
      deleteEnabled: false // disables deleting features
    }]
  }
});

Constructors

EditorViewModel

Constructor
new EditorViewModel(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
CreateFeaturesWorkflow|UpdateWorkflow

A property indicating the current active workflow.

EditorViewModel
String

An array of string values which specifies what end users are allowed to edit.

EditorViewModel
AttachmentsViewModel

The AttachmentsViewModel for supporting the editor widget.

EditorViewModel
Boolean

Convenience property that indicates at least one layer supports a create-features workflow.

EditorViewModel
Boolean

Convenience property that indicates at least one layer supports a update workflow.

EditorViewModel
String

The name of the class.

Accessor
Collection<EditableItem>

A read-only collection of editable item objects that match the feature being updated.

EditorViewModel
Collection<EditorItem>

A read-only collection of editable item objects that match the feature being updated.

EditorViewModel
Object[]

An array of objects containing information specific to any failed editing operations.

EditorViewModel
FeatureFormViewModel

The FeatureFormViewModel for supporting the editor widget.

EditorViewModel
FeatureTemplatesViewModel

The FeatureTemplatesViewModel for supporting the editor widget.

EditorViewModel
SketchLabelOptions

Options to configure the labels shown next to each segment of the geometry being created or updated.

EditorViewModel
LayerInfo[]

An array of editing configurations for individual layers.

EditorViewModel
SketchViewModel

The SketchViewModel for supporting the editor widget.

EditorViewModel
SnappingOptions

The SnappingOptions for sketching.

EditorViewModel
String

The widget's state.

EditorViewModel
Boolean

Indicates if there is at least one edit request being processed.

EditorViewModel
SketchTooltipOptions

Options to configure the tooltip shown next to the cursor when creating or updating graphics.

EditorViewModel
SketchValueOptions

Options to configure how values are displayed and input when creating or updating graphics.

EditorViewModel
MapView|SceneView

A reference to the MapView or SceneView.

EditorViewModel

Property Details

activeWorkflow

Property
activeWorkflow CreateFeaturesWorkflow|UpdateWorkflowreadonly

A property indicating the current active workflow. This is either CreateFeaturesWorkflow or UpdateWorkflow.

allowedWorkflows

Property
allowedWorkflows String
Deprecated since version 4.29. Use Editor.visibleElements instead.

An array of string values which specifies what end users are allowed to edit.

Possible Value Description
create-features This allows the end user to create either individual or continuous features in the feature service.
update This allows the end user to update and/or delete features in the feature service.

These workflows are only enabled if the feature service allows these operations.

Possible Values:"create-features"|"update"

attachmentsViewModel

Property
attachmentsViewModel AttachmentsViewModel

The AttachmentsViewModel for supporting the editor widget. Attachment editing is enabled by default if the layer has support for it.

canCreate

Property
canCreate Booleanreadonly

Convenience property that indicates at least one layer supports a create-features workflow.

canUpdate

Property
canUpdate Booleanreadonly

Convenience property that indicates at least one layer supports a update workflow. This includes the ability to delete features and modify attachments and/or related records.

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

editableItems

Property
editableItems Collection<EditableItem>readonly
Deprecated
  • Yes

A read-only collection of editable item objects that match the feature being updated.

editorItems

Property
editorItems Collection<EditorItem>readonly

A read-only collection of editable item objects that match the feature being updated.

failures

Property
failures Object[]readonly

An array of objects containing information specific to any failed editing operations. In addition to the error(s), options to retry() or cancel() are provided.

Property
error Error

The read-only error message.

featureFormViewModel

Property
featureFormViewModel FeatureFormViewModel

The FeatureFormViewModel for supporting the editor widget.

featureTemplatesViewModel

Property
featureTemplatesViewModel FeatureTemplatesViewModel

The FeatureTemplatesViewModel for supporting the editor widget.

labelOptions

Property
labelOptions SketchLabelOptionsautocast
Since: ArcGIS Maps SDK for JavaScript 4.24 EditorViewModel since 4.11, labelOptions added at 4.24.

Options to configure the labels shown next to each segment of the geometry being created or updated.

Known Limitation

Sketch labels are currently only supported when working with a SceneView.

layerInfos

Property
layerInfos LayerInfo[]

An array of editing configurations for individual layers.

For example, if you have an editable feature layer but do not want the end user to do any type of editing, you can limit this by setting the enabled property to false.

Example
const editorViewModel = new EditorViewModel({
  layerInfos: [{
    view: view,
    layer: featureLayer, // pass in the feature layer,
    formTemplate:  { // autocasts to FormTemplate
      elements: [
        { // autocasts to FieldElement
          type: "field",
          fieldName: "fulladdr",
          label: "Full Address"
        }
      ]
    },
    enabled: true, // default is true, set to false to disable editing functionality
    addEnabled: true, // default is true, set to false to disable the ability to add a new feature
    updateEnabled: false // default is true, set to false to disable the ability to edit an existing feature
    deleteEnabled: false // default is true, set to false to disable the ability to delete features
  }]
});

sketchViewModel

Property
sketchViewModel SketchViewModel

The SketchViewModel for supporting the editor widget.

snappingOptions

Property
snappingOptions SnappingOptionsautocast
Since: ArcGIS Maps SDK for JavaScript 4.19 EditorViewModel since 4.11, snappingOptions added at 4.19.

The SnappingOptions for sketching. It supports self and feature snapping.

state

Property
state Stringreadonly

The widget's state. Possible values are in the table below.

Value Description
ready Dependencies are met and has valid property values.
disabled Dependencies are missing and cannot provide valid inputs.
editing-existing-feature The Editor is currently editing an existing feature.
awaiting-update-feature-candidate The period when the application is awaiting the user's input after clicking update and multiple features are returned. Specify the feature to update.
awaiting-feature-creation-info This is the first step in the create-features workflow. A CreationInfo is required.
awaiting-feature-to-update This is the first step in the update workflow. A feature is required.
awaiting-feature-to-create The waiting period for when a feature is created before attribute/geometry edits can be performed.
adding-attachment If currently editing-existing-feature and adding an attachment to an existing feature.
editing-attachment If currently editing-existing-feature and updating an existing attachment to an existing feature.
creating-features The Editor is currently creating multiple features.

Possible Values:"adding-attachment"|"awaiting-feature-creation-info"|"awaiting-feature-to-create"|"awaiting-feature-to-update"|"awaiting-update-feature-candidate"|"creating-features"|"disabled"|"editing-attributes"|"editing-attachment"|"editing-existing-feature"|"editing-new-feature"|"awaiting-update-feature-candidate"|"ready"

syncing

Property
syncing Booleanreadonly

Indicates if there is at least one edit request being processed.

tooltipOptions

Property
tooltipOptions SketchTooltipOptionsautocast
Since: ArcGIS Maps SDK for JavaScript 4.24 EditorViewModel since 4.11, tooltipOptions added at 4.24.

Options to configure the tooltip shown next to the cursor when creating or updating graphics.

valueOptions

Property
valueOptions SketchValueOptionsautocast
Since: ArcGIS Maps SDK for JavaScript 4.29 EditorViewModel since 4.11, valueOptions added at 4.29.

Options to configure how values are displayed and input when creating or updating graphics.

view

Property
view MapView|SceneView

A reference to the MapView or SceneView. This view provides the editable layers for the Editor widget and is required when instantiating the widget.

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor
Promise<void>

Cancels any active workflow.

EditorViewModel
Promise<void>

This is applicable if there is an active update workflow with an active child workflow.

EditorViewModel
Boolean

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor
Promise<void>

Initiates the CreateFeaturesWorkflow by displaying the panel where feature creation begins.

EditorViewModel
Promise<void>

This method starts the CreateFeaturesWorkflow at the "creating-features" step with the provided feature.

EditorViewModel
Promise<void>

Initiates the CreateFeaturesWorkflow by displaying the FeatureTemplates panel.

EditorViewModel
Promise<void>

Starts the update workflow at the feature geometry and attribute editing panel.

EditorViewModel
Promise<void>

Starts the update workflow using the current selected feature.

EditorViewModel
Promise<void>

Starts the Editor workflow where it waits for multiple features to be selected.

EditorViewModel

Toggles the UpdateWorkflow.

EditorViewModel

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

cancelWorkflow

Method
cancelWorkflow(){Promise<void>}

Cancels any active workflow.

Returns
Type Description
Promise<void> Resolves once the workflow is canceled.

deleteFeatureFromWorkflow

Method
deleteFeatureFromWorkflow(){Promise<void>}

This is applicable if there is an active update workflow with an active child workflow. In this case, this method deletes the feature associated with the active child workflow.

Returns
Type Description
Promise<void> Resolves once the active UpdateWorkflow is deleted.
See also

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

startCreateFeaturesWorkflowAtFeatureCreation

Method
startCreateFeaturesWorkflowAtFeatureCreation(creationInfo){Promise<void>}
Since: ArcGIS Maps SDK for JavaScript 4.23 EditorViewModel since 4.11, startCreateFeaturesWorkflowAtFeatureCreation added at 4.23.

Initiates the CreateFeaturesWorkflow by displaying the panel where feature creation begins. This method takes a CreationInfo object containing the layer(s) and template(s) to use.

Parameter
creationInfo CreationInfo

An object containing information needed to create a new feature using the Editor widget. This object provides the feature template and layer for creating a new feature.

Returns
Type Description
Promise<void> Resolves when the CreateFeaturesWorkflow initiates and displays the panel where feature creation begins.

startCreateFeaturesWorkflowAtFeatureEdit

Method
startCreateFeaturesWorkflowAtFeatureEdit(params){Promise<void>}
Since: ArcGIS Maps SDK for JavaScript 4.28 EditorViewModel since 4.11, startCreateFeaturesWorkflowAtFeatureEdit added at 4.28.

This method starts the CreateFeaturesWorkflow at the "creating-features" step with the provided feature.

Any CreateFeaturesWorkflow instance generated by this method will only support creating a single feature per operation, (ie. batch creation is disabled).

Parameters
params Object

Parameters object containing an initialFeature to use in the associated CreateFeaturesWorkflow.

Specification
initialFeature Graphic

The initial feature used when you begin creating features.

Returns
Type Description
Promise<void> Resolves once the CreateFeaturesWorkflow initiates and displays the panel where additional edits can be made to the provided feature.

startCreateFeaturesWorkflowAtFeatureTypeSelection

Method
startCreateFeaturesWorkflowAtFeatureTypeSelection(){Promise<void>}
Since: ArcGIS Maps SDK for JavaScript 4.23 EditorViewModel since 4.11, startCreateFeaturesWorkflowAtFeatureTypeSelection added at 4.23.

Initiates the CreateFeaturesWorkflow by displaying the FeatureTemplates panel.

Returns
Type Description
Promise<void> Resolves when the CreateFeaturesWorkflow is initiated and displays the FeatureTemplates panel.

startUpdateWorkflowAtFeatureEdit

Method
startUpdateWorkflowAtFeatureEdit(feature){Promise<void>}

Starts the update workflow at the feature geometry and attribute editing panel.

Parameter
feature Graphic

The feature to be updated.

Returns
Type Description
Promise<void> Resolves once the UpdateWorkflow initiates the feature geometry and attribute editing panel.
See also

startUpdateWorkflowAtFeatureSelection

Method
startUpdateWorkflowAtFeatureSelection(){Promise<void>}

Starts the update workflow using the current selected feature.

Returns
Type Description
Promise<void> Resolves once the UpdateWorkflow is initiated using the current selected feature.
See also

startUpdateWorkflowAtMultipleFeatureSelection

Method
startUpdateWorkflowAtMultipleFeatureSelection(){Promise<void>}

Starts the Editor workflow where it waits for multiple features to be selected.

Returns
Type Description
Promise<void> Resolves once the UpdateWorkflow is initiated as it waits for multiple features to be selected.
See also

toggleUpdateWorkflow

Method
toggleUpdateWorkflow()

Toggles the UpdateWorkflow.

Type Definitions

EditableItem

Type Definition
EditableItem

The editable item available within the map. All the properties returned within it are read-only.

Properties
layer FeatureLayer|SceneLayer|module/esri/layers/support/SubtypeSublayer

The layer associated with the editable item.

supports String

The workflow type that this item supports. Possible values are create, update, or delete.

hasAttachments Boolean

Indicates whether this layer has attachments on it.

geometryUpdatesEnabled Boolean

Indicates whether this layer enables or disables geometry updates.

attributeUpdatesEnabled Boolean

Indicates whether this layer supports attribute editing while in the update workflow.

attachmentsOnCreateEnabled Boolean

Indicates whether this layer supports the ability to work with attachments while creating features.

attachmentsOnUpdateEnabled Boolean

Indicates whether this layer supports the ability to work with attachments while updating or deleting features.

hasInvalidFormTemplate Boolean

Indicates whether this layer's formTemplate is invalid. For example, removing or deleting a field within the layer that is still referenced in its original way and not updating the coinciding template.

EditorItem

Type Definition
EditorItem

The editable item available within the map. All the properties returned within it are read-only.

Property
layer FeatureLayer|SceneLayer|module/esri/layers/support/SubtypeSublayer

The layer associated with the editable item.

Event Overview

Name Type Summary Class
{type: "sketch-create",layer: FeatureLayer|SceneLayer|SubtypeSublayer,detail: Object,detail.graphic: Graphic,detail.state: "start"|"active"|"complete"|"cancel",detail.tool: "point"|"multipoint"|"polyline"|"polygon"|"circle"|"rectangle"|"mesh",detail.toolEventInfo: CreateToolEventInfo,detail.type: "create"}

Fires when a user starts drawing a feature, is actively drawing a feature, and completes drawing a feature.

EditorViewModel
{type: "sketch-update",layer: FeatureLayer|SceneLayer|SubtypeSublayer,detail: Object,detail.aborted: Boolean,detail.graphics: Graphic[],detail.state: "start"|"active"|"complete",detail.tool: "move"|"transform"|"reshape",toolEventInfo: UpdateToolEventInfo,detail.type: "update"}

Fires when a user starts updating a feature's geometry, is actively updating a feature's geometry, and completes updating a feature's geometry.

EditorViewModel

Event Details

sketch-create

Event
sketch-create
Since: ArcGIS Maps SDK for JavaScript 4.29 EditorViewModel since 4.11, sketch-create added at 4.29.

Fires when a user starts drawing a feature, is actively drawing a feature, and completes drawing a feature.

Properties
type String

The value is always "sketch-create".

The layer currently being edited.

detail Object

Detailed information returned within the "sketch-create" event.

Specification
graphic Graphic

The feature being created.

state String

The current state of the event.

Value Description
start State changes to start when the first vertex is created. Not applicable when creating points.
active State is active while feature is being created. Not applicable when creating points.
complete State changes to complete after the complete() method is called, when the user double clicks, presses the Enter key or clicks the first vertex of the polygon while creating a feature. When point is created, the a single sketch-create event is fired with the complete state.
cancel State changes to cancel if the user presses the escape key or the create() or cancel() methods are called during the create operation and before the state changes to complete.

Possible Values:"start"|"active"|"complete"|"cancel"

tool String

Name of the create tool.

Possible Values:"point"|"multipoint"|"polyline"|"polygon"|"circle"|"rectangle"|"mesh"

toolEventInfo CreateToolEventInfo

Returns additional information associated with the create operation.

type String

The value is always "create".

Example
// Listen to EditorViewModel's create event.
editorViewModel.on("sketch-create", function(evt) {
  const { graphic, tool } = evt.detail;

  // Check if the tool used is a 'polyline'
  if (tool === "polyline") {
    // Set the active polyline symbol to white while drawing
    graphic.symbol.color = "#ffffff";
  }
});

sketch-update

Event
sketch-update
Since: ArcGIS Maps SDK for JavaScript 4.29 EditorViewModel since 4.11, sketch-update added at 4.29.

Fires when a user starts updating a feature's geometry, is actively updating a feature's geometry, and completes updating a feature's geometry.

Properties
type String

The value is always "sketch-update".

The layer currently being edited.

detail Object

Detailed information returned within the "sketch-update" event.

Specification
aborted Boolean

Indicates if the update operation was aborted. Returns true if the user pressed the esc key, or when the update(), create() or cancel() method is called before the update event's state changes to complete.

graphics Graphic[]

An array of features that are being updated.

state String

The state of the event.

Value Description
start State changes to start when a feature is selected to update.
active State is active while features are being updated and toolEventInfo parameter is not null.
complete State changes to complete after features are updated.

Possible Values:"start"|"active"|"complete"

tool String

Name of the update operation tool.

Possible Values:"move"|"transform"|"reshape"

toolEventInfo UpdateToolEventInfo

Update operation tool info. Returns additional information associated with the update operation that is taking place for selected feature and what stage it is at. Value of this parameter changes to null when the update event's state changes to complete.

detail.type String

The value is always "update".

Example
// Listen to EditorViewModel's update event.
editorViewModel.on("sketch-update", function(evt) {
  const { tool, graphics } = evt.detail;

// Check if the layer's geometryType is a 'polyline'
  if (evt.layer?.geometryType === "polyline") {
    // For every feature, update the line symbol
    // width to emphasize the feature being updated
    graphics.forEach((graphic) => graphic.symbol.width = 5);
  }
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.