Skip to content
import FeaturesViewModel from "@arcgis/core/widgets/Features/FeaturesViewModel.js";
Inheritance:
FeaturesViewModelAccessor
Subclasses:
PopupViewModel
Since
ArcGIS Maps SDK for JavaScript 4.27

Provides the logic for the Features widget and component.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
PropertyTypeClass
active
readonly
allActions
readonly
declaredClass
readonly inherited
defaultActions
readonly
featureCount
readonly
goToOverride
inherited
map
promiseCount
readonly
screenLocation
readonly
selectedFeature
readonly
state
readonly
waitingForResult
readonly

actions

autocast Property
Type
Collection<PopupAction>

Collection of action or action toggle objects. Each action may be executed by clicking the icon or image symbolizing them. By default, every popup and Features widget has a Zoom To action styled with a magnifying glass icon popupTemplate-zoom-action. When this icon is clicked, the view zooms in four LODs and centers on the selected feature.

You may remove this default action by setting includeDefaultActions to false, or by setting the PopupTemplate.overwriteActions property to true in a PopupTemplate. The order of each action is the order in which they appear in the actions Collection.

The @trigger-action event fires each time an action is clicked.

Actions are defined with the properties listed in the ActionButton or ActionToggle class.

See also
Example
// Defines an action button to zoom out from the selected feature
const zoomOutAction = {
type: "button",
// This text is displayed as a tooltip
title: "Zoom out",
// The ID by which to reference the action in the event handler
id: "zoom-out",
// Sets the icon used to style the action button
icon: "magnifying-glass-minus"
};
// Adds the custom action to the popup.
view.popup.viewModel.actions.push(zoomOutAction);
// Adds the custom action to the Features widget
featuresWidget.viewModel.actions.push(zoomOutAction);

active

readonly Property
Type
boolean

Indicates if the view model is active when it is visible and is not waiting for results.

See also

activeFeature

Property
Type
Graphic | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.32

The highlighted feature on the map that is either hovered over or in focus within the feature menu.

allActions

readonly Property
Type
Collection<PopupAction>

A collection of actions or action toggles.

autoCloseEnabled

Property
Type
boolean

This closes the container when the View camera or Viewpoint changes.

Default value
false

browseClusterEnabled

Property
Type
boolean

Indicates if the "Browse features" experience is active in a cluster popup. This value becomes true when the user enables feature browsing with the "Browse features" cluster action button. It becomes false when the view scale changes, when the widget is closed, or when the user disables the "Browse features" action. This should only be set programmatically when the selectedFeature is an aggregate graphic and represents a cluster.

Default value
false
Example
// open the browse features experience for a cluster graphic
featuresWidget.viewModel.browseClusterEnabled = featuresWidget.viewModel.selectedFeature?.isAggregate;
view.popup.viewModel.browseClusterEnabled = view.popup.viewModel.selectedFeature?.isAggregate;

content

Property
Type
string | HTMLElement | Widget | null | undefined

The information to display. When this property is set, this content may only be static and cannot use fields to set content templates. To set a template for the content based on field or attribute names, see PopupTemplate.content.

See also
Example
// This sets generic instructions in the popup that will always be displayed
// unless it is overridden by a PopupTemplate.
// This can be set on the Features widget view model
featuresWidget.viewModel.content = "Click a feature on the map to view its attributes";
// Or set on the Popup widget view model.
view.popup.viewModel.content = "Click a feature on the map to view its attributes";

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

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

defaultActions

readonly Property
Type
Collection<PopupAction>

A read-only property that specifies a Collection of action buttons and/or toggles. By default, there is a "Zoom to" action that allows users to zoom to the selected feature.

In order to disable any default actions, it is necessary to set includeDefaultActions to false.

defaultPopupTemplateEnabled

Property
Type
boolean

Enables automatic creation of a popup template for layers that have popups enabled but no popupTemplate defined. Automatic popup templates are supported for layers that support the createPopupTemplate method. (Supported for FeatureLayer, GeoJSONLayer, OGCFeatureLayer, SceneLayer, CSVLayer, PointCloudLayer, StreamLayer, and ImageryLayer).

Default value
false

featureCount

readonly Property
Type
number

The number of selected features available.

Default value
0

featureMenuOpen

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.32

This property enables showing the list of features. Setting this to true allows the user to scroll through the list of features. This value will only be honored if initialDisplayMode is set to feature.

Default value
false

featureMenuTitle

Property
Type
string | null | undefined

The title to display on the widget while viewing the feature menu.

featurePage

Property
Type
number | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.32

The current page number in the feature browsing menu. If the feature menu is not open, this value is null. This value is dependent on the featuresPerPage.

features

Property
Type
Graphic[]

An array of features. Each graphic in this array must have a valid PopupTemplate set. They may share the same PopupTemplate or have unique PopupTemplates depending on their attributes. The content and title properties are set based on the content and title properties of each graphic's respective PopupTemplate.

When more than one graphic exists in this array, the current content of the Popup is set based on the value of the selected feature.

This value is null if there are no features associated with the view model.

Example
// When setting the features property, the graphics pushed to this property
// must have a PopupTemplate set.
let g1 = new Graphic();
g1.popupTemplate = new PopupTemplate({
title: "Results title",
content: "Results: {ATTRIBUTE_NAME}"
});
// Create an array of graphics and set this to the features property. The content and title of
// will be set depending on the PopupTemplate of the graphics.
// Each graphic may share the same PopupTemplate or have a unique PopupTemplate.
let graphics = [g1, g2, g3, g4, g5];
// This value can be set on the popup or Features view model.
view.popup.viewModel.features = graphics;
featuresWidget.viewModel.features = graphics;

featuresPerPage

Property
Type
number

The number of features to fetch at one time.

Default value
20

featureViewModelAbilities

Property
Type
FeatureViewModelAbilities | null | undefined

Defines the specific Abilities that can be used when querying and displaying content.

featureViewModels

readonly Property
Type
FeatureViewModel[]

An array of feature view model(s).

goToOverride

inherited Property
Type
GoToOverride | null | undefined
Inherited from: GoTo

This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.

See also
Example
// The following snippet uses Search but can be applied to any
// widgets that support the goToOverride property.
search.goToOverride = function(view, goToParams) {
goToParams.options = {
duration: updatedDuration
};
return view.goTo(goToParams.target, goToParams.options);
};

highlightEnabled

Property
Type
boolean

Highlight the selected feature using one of the HighlightOptions defined in the view's View.highlights collection.

Default value
true

includeDefaultActions

Property
Type
boolean

Indicates whether or not to include defaultActions.

In order to disable any default actions, it is necessary to set includeDefaultActions to false.

Default value
true
Example
// Removes the default actions
viewModel.includeDefaultActions = false;

initialDisplayMode

Property
Type
InitialDisplayOptions
Since
ArcGIS Maps SDK for JavaScript 4.32

Indicates whether to initially display a list of features, or the content for one feature.

Default value
"feature"

location

autocast Property
Type
Point | null | undefined

Geometry used to show the location of the feature. This is automatically set when selecting a feature. If displaying content not related to features in the map, such as the results from a task, then you must set this property before making the widget visible to the user.

See also
Examples
// Sets the location of the popup to the center of the view
view.popup.viewModel.location = view.center;
// Displays the popup
view.popup.visible = true;
// Display a popup when and where the user clicks the view.
reactiveUtils.on(()=>view, "click", ({ mapPoint })=>{
view.popup.viewModel.location = mapPoint;
view.popup.visible = true;
});

map

Property
Type
EsriMap | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.30

A map is required when the input features have a popupTemplate that contains Arcade expressions in ExpressionInfo or ExpressionContent that may use the $map profile variable to access data from layers within a map. Without a map, expressions that use $map will throw an error.

Alternatively, the view property can be used to provide the map instance for this property.

See also
Example
// The building footprints represent the buildings that intersect a clicked parcel
let buildingFootprints = Intersects($feature, FeatureSetByName($map, "Building Footprints"));

pendingPromisesCount

readonly Property
Type
number

The number of promises remaining to be resolved.

See also
Default value
0

promiseCount

readonly Property
Type
number

The number of selected promises available.

Default value
0

promises

Property
Type
Promise<Graphic[]>[]

An array of pending Promises that have not yet been fulfilled. If there are no pending Promises, the value is null. When the pending Promises are resolved they are removed from this array and the features they return are pushed into the features array.

screenLocation

readonly Property
Type
ScreenPoint | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.32

The screen location of the selected feature.

screenLocationEnabled

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.32

Determines whether screen point tracking is active for positioning.

Default value
false

selectedClusterBoundaryFeature

readonly Property
Type
Graphic

The graphic used to represent the cluster extent when the Browse features action is active. Only applies when a PopupTemplate is set on a FeatureReductionCluster instance.

selectedFeature

readonly Property
Type
Graphic | null

The selected feature accessed. The content is determined based on the PopupTemplate assigned to this feature.

selectedFeatureIndex

Property
Type
number

Index of the feature that is selected. When features are set, the first index is automatically selected.

selectedFeatureViewModel

readonly Property
Type
FeatureViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

The view model of the selected feature.

spatialReference

autocast Property
Type
SpatialReference | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.30

The spatial reference used for Arcade operations. This property should be set if Arcade expressions are executed that contain geometry functions.

Alternatively, the view property can be used to provide the spatial reference instance for this property.

See also

state

readonly Property
Type
State

The view model's state.

Default value
"disabled"

timeZone

autocast Property
Type
TimeZone
Since
ArcGIS Maps SDK for JavaScript 4.30

Dates and times will be displayed in this time zone. By default this time zone is inherited from MapView.timeZone if the view property is set. When a MapView is not associated with the widget view model, then the property will fallback to the system time zone.

Possible Values

ValueDescription
systemDates and times will be displayed in the timezone of the device or browser.
unknownDates and time are not adjusted for any timezone.
Specified IANA timezoneDates and times will be displayed in the specified IANA time zone. See wikipedia - List of tz database time zones.

title

Property
Type
string | null | undefined

The title of the widget. This can be set to any string value no matter the features that are selected. If the selected feature has a PopupTemplate, then the title set in the corresponding template is used here.

Example
// This title will display in the popup unless a selected feature's
// PopupTemplate overrides it.
view.popup.viewModel.title = "Population by zip codes in Southern California";

updateLocationEnabled

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.32

Indicates whether to update the location when the selectedFeatureIndex changes.

Default value
false

view

Property
Type
MapViewOrSceneView | null | undefined

A reference to the MapView or SceneView.

The FeaturesViewModel requires a view if the user expects it to display content in any of the following situations:

visible

Property
Type
boolean

Indicates whether the widget is visible. This property is true when the widget is querying for results, even if it is not open in the view. Use the active property to check if the widget is visible and is not waiting for results.

See also
Default value
false

waitingForContents

readonly Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.32

Indicates whether the widget is waiting for content to be resolved.

waitingForResult

readonly Property
Type
boolean

Indicates whether a feature was found while resolving promises.

See also
Default value
false

zoomFactor

Property
Type
number
Since
ArcGIS Maps SDK for JavaScript 4.34

Number of levels of detail (LOD) to zoom in on the selected feature.

Default value
4
Example
// Restricts the zooming to two LODS when the zoom in action is clicked.
features.viewModel.zoomFactor = 2;

Methods

MethodSignatureClass
clear(): void
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
fetchFeatures(screenPoint: ScreenPoint | null | undefined, options?: FetchFeaturesOptions): Promise<FetchPopupFeaturesResult>
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
next(): FeaturesViewModel
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
open(options?: PopupOpenOptions): void
previous(): FeaturesViewModel
triggerAction(actionIndex: number): void
zoomTo(params: GoToParameters): Promise<void>

clear

Method
Signature
clear (): void

Removes all promises, features, content, and title.

Returns
void

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

fetchFeatures

Method
Signature
fetchFeatures (screenPoint: ScreenPoint | null | undefined, options?: FetchFeaturesOptions): Promise<FetchPopupFeaturesResult>

Use this method to return feature(s) at a given screen location. These features are fetched from all of the LayerViews in the View. In order to use this, a layer must already have an associated PopupTemplate and have its FeatureLayer.popupEnabled. These features can then be used within a custom Popup, Features, or Feature widget experience. One example could be a custom side panel that displays feature-specific information based on an end user's click location. This method allows a developer the ability to control how the input location is handled, and then subsequently, what to do with the results.

Parameters
ParameterTypeDescriptionRequired
screenPoint

An object representing a point on the screen. This point can be in either the ScreenPoint or ScreenPoint.

options

The options to pass into the fetchFeatures method.

Returns
Promise<FetchPopupFeaturesResult>

Resolves with the selected hitTest location. In addition, it also returns an array of graphics if the hitTest is performed directly on the View, a single Promise containing an array of all resulting graphics, or an array of objects containing this array of resulting graphics in addition to its associated LayerView.

Most commonly if accessing all features, use the single promise returned in the result's allGraphicsPromise and call .then() as seen in the example snippet.

Example
// Get view's click event
reactiveUtils.on(()=>view, "click", (event) => {
// Call fetchFeatures and pass in the click event screenPoint
viewModel.fetchFeatures(event.screenPoint).then((response) => {
// Access the response from fetchFeatures
response.allGraphicsPromise.then((graphics) => {
// Do something with the returned graphic from fetchFeatures such as setting this to the
// Features widget graphic property.
featureWidget.graphic = graphics[0];
});
});
});

hasEventListener

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

next

Method
Signature
next (): FeaturesViewModel

Selects the feature at the next index in relation to the selected feature.

See also
Returns
FeaturesViewModel

Returns an instance of the popup's view model.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});

open

Method
Signature
open (options?: PopupOpenOptions): void

Opens the widget at the given location with content defined either explicitly with content or driven from the PopupTemplate of input features. This method sets the visible property to true. Users can alternatively set the visible property to true.

See also
Parameters
ParameterTypeDescriptionRequired
options

Defines the location and content of the popup when opened.

Returns
void
Examples
// Manually opens the corresponding widget.
reactiveUtils.on(()=>view, "click", (event)=>{
viewModel.open({
location: event.mapPoint,
title: "You clicked here",
content: "This is a point of interest"
});
});
// Displays the content for the selected feature if a popupTemplate is defined at the view
// click event location.
reactiveUtils.on(()=>view, "click", (event)=>{
view.popup.viewModel.open({
location: event.mapPoint,
fetchFeatures: true
});
});
// Opens the corresponding widget with the specified title and content and updates
// the location of the popup based on the selected feature's geometry.
view.popup.viewModel.open({
title: "You clicked here",
content: "This is a point of interest",
updateLocationEnabled: true
});
// Opens the Features widget with the specified graphics.
// This will only work if the array of graphics have a popup template defined.
featuresWidget.viewModel.open({
features: graphics
});

previous

Method
Signature
previous (): FeaturesViewModel

Selects the feature at the previous index in relation to the selected feature.

See also
Returns
FeaturesViewModel

Returns an instance of the popup's view model.

triggerAction

Method
Signature
triggerAction (actionIndex: number): void

Triggers the @trigger-action event and executes the action at the specified index in the actions array.

Parameters
ParameterTypeDescriptionRequired
actionIndex

The index of the action to execute.

Returns
void

zoomTo

Method
Signature
zoomTo (params: GoToParameters): Promise<void>
Since
ArcGIS Maps SDK for JavaScript 4.32

Sets the view to a given target. If goToOverride is set, goToOverride() will be called with the current view and specified params. Otherwise, the view will be set using the provided params.

See also
Parameters
ParameterTypeDescriptionRequired
params

The parameters to pass to the zoomTo() method.

Returns
Promise<void>

A promise that resolves when the view's extent updates to the value defined in params.target.

Events

trigger-action

Event
trigger-action: CustomEvent<ActionEvent>

Fires after the user clicks on an action or action toggle in the action bar. This event may be used to define a custom function to execute when particular actions are clicked. See the example below for details of how this works.

See also
bubbles composed cancelable
Examples
featuresWidget.open({
location: event.mapPoint,
fetchFeatures: true,
featureMenuOpen: true,
actions: [{
// This text is displayed as a tooltip
title: "Zoom out",
// The ID used to reference this action in the event handler
id: "zoom-out",
// Sets the icon font used to style the action button
className: "esri-icon-zoom-out-magnifying-glass"
},
{
title: "Delete Feature",
id: "delete-feature-action",
icon: "trash"
}]
});
// Fires each time an action is clicked
reactiveUtils.on(()=> featuresWidget, "trigger-action", (event)=>{
// If the zoom-out action is clicked, execute the following code
if(event.action.id === "zoom-out"){
// Zoom out two levels (LODs)
view.goTo({
center: view.center,
zoom: view.zoom - 2
});
}
});
// Defines an action button to zoom out from the selected feature
const zoomOutAction = {
type: "button",
// This text is displayed as a tooltip
title: "Zoom out",
// The ID by which to reference the action in the event handler
id: "zoom-out",
// Sets the icon used to style the action button
icon: "magnifying-glass-minus"
};
// Adds the custom action to the popup.
view.popup.actions.push(zoomOutAction);
// This event fires for each click on any action
reactiveUtils.on(()=>view.popup?.viewModel, "trigger-action", (event)=>{
// If the zoom-out action is clicked, fire the zoomOut() function
if(event.action.id === "zoom-out"){
// in this case the view zooms out two LODs on each click
view.goTo({
center: view.center,
zoom: view.zoom - 2
});
}
});
// Defines an action button to zoom out from the selected feature
const zoomOutAction = {
type: "button",
// This text is displayed as a tooltip
title: "Zoom out",
// The ID by which to reference the action in the event handler
id: "zoom-out",
// Sets the icon used to style the action button
icon: "magnifying-glass-minus"
};
// Adds the custom action to the popup.
view.popup.actions.push(zoomOutAction);
// This event fires for each click on any action
reactiveUtils.on(()=>view.popup?.popupViewModel, "trigger-action", (event)=>{
// If the zoom-out action is clicked, fire the zoomOut() function
if(event.action.id === "zoom-out"){
// in this case the view zooms out two LODs on each click
view.goTo({
center: view.center,
zoom: view.zoom - 2
});
}
});

Type definitions