Skip to content
import PopupViewModel from "@arcgis/core/widgets/Popup/PopupViewModel.js";
Inheritance:
PopupViewModelFeaturesViewModelAccessor
Since
ArcGIS Maps SDK for JavaScript 4.0

Provides the logic for the Popup widget and component, which allows users to view content from feature attributes. Popups enhance web applications by providing users with a simple way to interact with and view attributes in a layer. They play an important role in relaying information to the user, which improves the storytelling capabilities of the application.

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
actions
inherited
active
readonly inherited
activeFeature
inherited
allActions
readonly inherited
autoCloseEnabled
inherited
content
inherited
declaredClass
readonly inherited
defaultActions
readonly inherited
featureCount
readonly inherited
featureMenuOpen
inherited
featureMenuTitle
inherited
featurePage
inherited
features
inherited
featuresPerPage
inherited
featureViewModels
readonly inherited
goToOverride
inherited
highlightEnabled
inherited
initialDisplayMode
inherited
location
inherited
map
inherited
pendingPromisesCount
readonly inherited
promiseCount
readonly inherited
promises
inherited
screenLocation
readonly inherited
selectedClusterBoundaryFeature
readonly inherited
selectedFeature
readonly inherited
selectedFeatureViewModel
readonly inherited
spatialReference
inherited
state
readonly inherited
timeZone
inherited
title
inherited
view
inherited
visible
inherited
waitingForContents
readonly inherited
waitingForResult
readonly inherited
zoomFactor
inherited

actions

autocast inherited Property
Type
Collection<PopupAction>
Inherited from: FeaturesViewModel

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

readonlyinherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

See also

activeFeature

inherited Property
Type
Graphic | null | undefined
Inherited from: FeaturesViewModel
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

readonlyinherited Property
Type
Collection<PopupAction>
Inherited from: FeaturesViewModel

A collection of actions or action toggles.

autoCloseEnabled

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

Default value
false

browseClusterEnabled

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

inherited Property
Type
string | HTMLElement | Widget | null | undefined
Inherited from: FeaturesViewModel

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
Since
ArcGIS Maps SDK for JavaScript 4.7

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

defaultActions

readonlyinherited Property
Type
Collection<PopupAction>
Inherited from: FeaturesViewModel

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

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

readonlyinherited Property
Type
number
Inherited from: FeaturesViewModel

The number of selected features available.

Default value
0

featureMenuOpen

inherited Property
Type
boolean
Inherited from: FeaturesViewModel
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

inherited Property
Type
string | null | undefined
Inherited from: FeaturesViewModel

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

featurePage

inherited Property
Type
number | null | undefined
Inherited from: FeaturesViewModel
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

inherited Property
Type
Graphic[]
Inherited from: FeaturesViewModel

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

inherited Property
Type
number
Inherited from: FeaturesViewModel

The number of features to fetch at one time.

Default value
20

featureViewModelAbilities

inherited Property
Type
FeatureViewModelAbilities | null | undefined
Inherited from: FeaturesViewModel

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

featureViewModels

readonlyinherited Property
Type
FeatureViewModel[]
Inherited from: FeaturesViewModel

An array of feature view model(s).

goToOverride

inherited Property
Type
GoToOverride | null | undefined
Inherited from: GoTo
Since
ArcGIS Maps SDK for JavaScript 4.8

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

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

Default value
true

includeDefaultActions

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

inherited Property
Type
InitialDisplayOptions
Inherited from: FeaturesViewModel
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 inherited Property
Type
Point | null | undefined
Inherited from: FeaturesViewModel

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

inherited Property
Type
EsriMap | null | undefined
Inherited from: FeaturesViewModel
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

readonlyinherited Property
Type
number
Inherited from: FeaturesViewModel

The number of promises remaining to be resolved.

See also
Default value
0

promiseCount

readonlyinherited Property
Type
number
Inherited from: FeaturesViewModel

The number of selected promises available.

Default value
0

promises

inherited Property
Type
Promise<Graphic[]>[]
Inherited from: FeaturesViewModel

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

readonlyinherited Property
Type
ScreenPoint | null | undefined
Inherited from: FeaturesViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

The screen location of the selected feature.

screenLocationEnabled

inherited Property
Type
boolean
Inherited from: FeaturesViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

Determines whether screen point tracking is active for positioning.

Default value
false

selectedClusterBoundaryFeature

readonlyinherited Property
Type
Graphic
Inherited from: FeaturesViewModel

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

readonlyinherited Property
Type
Graphic | null
Inherited from: FeaturesViewModel

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

selectedFeatureIndex

inherited Property
Type
number
Inherited from: FeaturesViewModel

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

selectedFeatureViewModel

readonlyinherited Property
Type
FeatureViewModel
Inherited from: FeaturesViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

The view model of the selected feature.

spatialReference

autocast inherited Property
Type
SpatialReference | null | undefined
Inherited from: FeaturesViewModel
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

readonlyinherited Property
Type
State
Inherited from: FeaturesViewModel

The view model's state.

Default value
"disabled"

timeZone

autocast inherited Property
Type
TimeZone
Inherited from: FeaturesViewModel
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

inherited Property
Type
string | null | undefined
Inherited from: FeaturesViewModel

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

inherited Property
Type
boolean
Inherited from: FeaturesViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

Indicates whether to update the location when the selectedFeatureIndex changes.

Default value
false

view

inherited Property
Type
MapViewOrSceneView | null | undefined
Inherited from: FeaturesViewModel

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

inherited Property
Type
boolean
Inherited from: FeaturesViewModel

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

readonlyinherited Property
Type
boolean
Inherited from: FeaturesViewModel
Since
ArcGIS Maps SDK for JavaScript 4.32

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

waitingForResult

readonlyinherited Property
Type
boolean
Inherited from: FeaturesViewModel

Indicates whether a feature was found while resolving promises.

See also
Default value
false

zoomFactor

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

clear

inherited Method
Signature
clear (): void
Inherited from: FeaturesViewModel

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
Since
ArcGIS Maps SDK for JavaScript 4.5

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

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

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

inherited Method
Signature
next (): FeaturesViewModel
Inherited from: 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

inherited Method
Signature
open (options?: PopupOpenOptions): void
Inherited from: FeaturesViewModel

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

inherited Method
Signature
previous (): FeaturesViewModel
Inherited from: 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

inherited Method
Signature
triggerAction (actionIndex: number): void
Inherited from: FeaturesViewModel

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

inherited Method
Signature
zoomTo (params: GoToParameters): Promise<void>
Inherited from: FeaturesViewModel
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

NameType
trigger-action
inherited

trigger-action

inherited Event
trigger-action: CustomEvent<ActionEvent>
Inherited from: FeaturesViewModel

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
});
}
});