PopupViewModel

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

Provides the logic for the Popup widget, 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.

All Views contain a default popup. This popup can display generic content, which is set in its title and content properties. When content is set directly on the Popup instance it is not tied to a specific feature or layer.

Popups can also contain actions that act like buttons, which when clicked execute a function defined by the developer. By default, every popup has a "Zoom to" action popupTemplate-zoom-action that allows users to zoom to the selected feature. See the actions property for information about adding custom actions to a popup.

See also

Constructors

new PopupViewModel(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
Collection<(ActionButton|ActionToggle)>

Collection of action or action toggle objects.

more details
PopupViewModel
Boolean

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

more details
PopupViewModel
Collection<(ActionButton|ActionToggle)>

A collection of actions or action toggles used within the Popup.

more details
PopupViewModel
Boolean

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

more details
PopupViewModel
Boolean

This property indicates to the Popup that it needs to allow or disallow the click event propagation.

more details
PopupViewModel
Boolean

Indicates if the "Browse features" experience is active in a cluster popup.

more details
PopupViewModel
String|HTMLElement|Widget

The content of the popup.

more details
PopupViewModel
String

The name of the class.

more details
Accessor
Collection<(ActionButton|ActionToggle)>

A read-only property that specifies a Collection of action buttons and/or toggles within the popup.

more details
PopupViewModel
Boolean

Enables automatic creation of a popup template for layers that have popups enabled but no popupTemplate defined.

more details
PopupViewModel
Number

The number of selected features available to the popup.

more details
PopupViewModel
Graphic[]

An array of features associated with the popup.

more details
PopupViewModel
Number

The number of features to fetch at one time.

more details
PopupViewModel
Abilities

Defines the specific abilities that the Popup widget should use when querying and displaying its content.

more details
PopupViewModel
FeatureViewModel[]

An array of feature view model(s) used by the Popup widget.

more details
PopupViewModel
GoToOverride

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

more details
PopupViewModel
Boolean

Highlight the selected popup feature using the highlightOptions set on the MapView or the highlightOptions set on the SceneView.

more details
PopupViewModel
Boolean

Indicates whether or not to include defaultActions in the Popup's UI.

more details
PopupViewModel
Point

Geometry used to position the popup.

more details
PopupViewModel
Number

The number of promises remaining to be resolved.

more details
PopupViewModel
Number

The number of selected promises available to the popup.

more details
PopupViewModel
Promise[]

An array of pending Promises that have not yet been fulfilled.

more details
PopupViewModel
Graphic

The graphic used to represent the cluster extent when the Browse features action is active in a cluster popup.

more details
PopupViewModel
Graphic

The selected feature accessed by the popup.

more details
PopupViewModel
Number

Index of the feature that is selected.

more details
PopupViewModel
String

The view model's state.

more details
PopupViewModel
String

The title of the popup.

more details
PopupViewModel
MapView|SceneView

The view associated with the Popup instance.

more details
PopupViewModel
Boolean

Indicates whether the popup is visible.

more details
PopupViewModel
Boolean

Indicates whether the popup has found a feature while resolving promises.

more details
PopupViewModel

Property Details

Autocasts from Object[]

Collection of action or action toggle objects. Each action may be executed by clicking the icon or image symbolizing them in the popup. By default, every popup 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 action from the default popup actions by setting includeDefaultActions to false, or by setting the overwriteActions property to true in a PopupTemplate. The order of each action in the popup is the order in which they appear in the actions Collection.

The trigger-action event fires each time an action in the popup is clicked. This event should be used to execute custom code for each action clicked. For example, if you would like to add a zoom-out action to the popup that zooms the view out several LODs, you would define the zoom-out code in a separate function. Then you would call the custom zoom-out function in the trigger-action event handler. See the sample code snippet below for more details on how this works.

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

See also
Example
// Defines an action to zoom out from the selected feature
let zoomOutAction = {
  // 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 font used to style the action button
  className: "esri-icon-zoom-out-magnifying-glass"
};
// Adds the custom action to the popup.
view.popup.viewModel.actions.push(zoomOutAction);

// The function to execute when the zoom-out action is clicked
function zoomOut() {
  // Zoom out two levels (LODs)
  view.goTo({
    center: view.center,
    zoom: view.zoom - 2
  });
}

// This event fires for each click on any action
view.popup.viewModel.on("trigger-action", function(event){
  // If the zoom-out action is clicked, fire the zoomOut() function
  if(event.action.id === "zoom-out"){
    zoomOut();
  }
});
active Booleanreadonly
Since: ArcGIS Maps SDK for JavaScript 4.17

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

See also
allActions Collection<(ActionButton|ActionToggle)>readonly
Since: ArcGIS Maps SDK for JavaScript 4.8

A collection of actions or action toggles used within the Popup.

autoCloseEnabled Boolean
Since: ArcGIS Maps SDK for JavaScript 4.5

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

Default Value:false
autoOpenEnabled Boolean
Since: ArcGIS Maps SDK for JavaScript 4.10

This property indicates to the Popup that it needs to allow or disallow the click event propagation.

Use view.popup.autoOpenEnabled = false; when needing to stop the click event propagation.

Default Value:true
Example
view.popup.viewModel.autoOpenEnabled = false;
view.on("click", function(event) {
  view.popup.open({
    // Set the popup
  });
});
browseClusterEnabled Boolean
Since: ArcGIS Maps SDK for JavaScript 4.24

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 popup action. It becomes false when the view scale changes, when the popup 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
view.popup.viewModel.browseClusterEnabled = view.popup.viewModel.selectedFeature?.isAggregate;

The content of the popup. When set directly on the Popup, 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
view.popup.viewModel.content = "Click a feature on the map to view its attributes";
declaredClass Stringreadonly inherited
Since: ArcGIS Maps SDK for JavaScript 4.7

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

defaultActions Collection<(ActionButton|ActionToggle)>readonly
Since: ArcGIS Maps SDK for JavaScript 4.19

A read-only property that specifies a Collection of action buttons and/or toggles within the popup. By default, every popup has 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 Boolean
Since: ArcGIS Maps SDK for JavaScript 4.11

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 Numberreadonly

The number of selected features available to the popup.

Default Value:0
features Graphic[]

An array of features associated with the popup. 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 of the popup is 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 no features are associated with the popup.

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}"
});
// Set the graphics as an array to the popup instance. The content and title of
// the popup 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];
view.popup.viewModel.features = graphics;
featuresPerPage Number

The number of features to fetch at one time.

Default Value:20
featureViewModelAbilities Abilitiesautocast
Since: ArcGIS Maps SDK for JavaScript 4.21

Defines the specific abilities that the Popup widget should use when querying and displaying its content.

featureViewModels FeatureViewModel[]readonly
Since: ArcGIS Maps SDK for JavaScript 4.21

An array of feature view model(s) used by the Popup widget.

goToOverride GoToOverride
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 the Search widget 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 Boolean
Since: ArcGIS Maps SDK for JavaScript 4.4

Highlight the selected popup feature using the highlightOptions set on the MapView or the highlightOptions set on the SceneView.

Default Value:true
includeDefaultActions Boolean
Since: ArcGIS Maps SDK for JavaScript 4.19

Indicates whether or not to include defaultActions in the Popup's UI.

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

Default Value:true
Example
// Removes the default actions from the popup
view.popup.viewModel.includeDefaultActions = false;
location Point

Geometry used to position the popup. This is automatically set when viewing the popup by selecting a feature. If using the Popup to display content not related to features in the map, such as the results from a task, then you must set this property before making the popup visible to the user.

See also
Examples
// Sets the location of the popup to the center of the view
view.popup.location = view.center;
// Displays the popup
view.popup.set("visible", true);
// Sets the location of the popup to the location of a click on the view
view.on("click", function(event){
  view.popup.viewModel.location = event.mapPoint;
  // Displays the popup
  view.popup.viewModel.set("visible", true);
});
pendingPromisesCount Numberreadonly

The number of promises remaining to be resolved.

Default Value:0
See also
promiseCount Numberreadonly

The number of selected promises available to the popup.

Default Value:0
promises Promise[]

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.

selectedClusterBoundaryFeature Graphicreadonly
Since: ArcGIS Maps SDK for JavaScript 4.19

The graphic used to represent the cluster extent when the Browse features action is active in a cluster popup. Only applies when a PopupTemplate is set on a FeatureReductionCluster instance. Use this property to override the default symbol of the displayed cluster extent.

See also
Examples
view.popup.viewModel.selectedClusterBoundaryFeature.symbol.outline.color = "yellow"
view.popup.viewModel.selectedClusterBoundaryFeature.symbol = {
  type: "simple-fill",
  style: "diagonal-cross",
  color: "green",
  outline: {
    width: 3,
    color: "green"
  }
}
selectedFeature Graphicreadonly

The selected feature accessed by the popup. The content of the Popup is determined based on the PopupTemplate assigned to this feature.

selectedFeatureIndex Number

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

state Stringreadonly

The view model's state.

Possible Values:"ready"|"disabled"

Default Value:disabled
title String

The title of the popup. This can be set generically on the popup 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";

The view associated with the Popup instance.

visible Boolean

Indicates whether the popup is visible.

Default Value:false
waitingForResult Booleanreadonly
Since: ArcGIS Maps SDK for JavaScript 4.17

Indicates whether the popup has found a feature while resolving promises.

Default Value:false
See also

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.

more details
Accessor

Removes promises, features, content, title and location from the Popup.

more details
PopupViewModel
Boolean

Emits an event on the instance.

more details
PopupViewModel
Promise<FetchPopupFeaturesResult>

Use this method to return feature(s) at a given screen location.

more details
PopupViewModel
Boolean

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

more details
PopupViewModel
Boolean

Returns true if a named group of handles exist.

more details
Accessor
PopupViewModel

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

more details
PopupViewModel
Object

Registers an event handler on the instance.

more details
PopupViewModel

Opens the popup at the given location with content defined either explicitly with content or driven from the PopupTemplate of input features.

more details
PopupViewModel
PopupViewModel

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

more details
PopupViewModel

Removes a group of handles owned by the object.

more details
Accessor

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

more details
PopupViewModel

Method Details

addHandles(handleOrHandles, groupKey)inherited
Since: ArcGIS Maps SDK for JavaScript 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.

clear()

Removes promises, features, content, title and location from the Popup.

emit(type, event){Boolean}
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
type String

The name of the event.

event Object
optional

The event payload.

Returns
Type Description
Boolean true if a listener was notified
fetchFeatures(screenPoint, options){Promise<FetchPopupFeaturesResult>}
Since: ArcGIS Maps SDK for JavaScript 4.15

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 popupEnabled. These features can then be used within a custom Popup 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
screenPoint Object

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

Specification
x Number

The x coordinate.

y Number

The y coordinate.

optional

The options to pass into the fetchFeatures method.

Returns
Type Description
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.
See also
Example
// Add Feature widget to UI
view.ui.add(featureWidget, "top-right");

// Get view's click event
view.on("click", function(event) {
  // Call fetchFeatures and pass in the click event screenPoint
  view.popup.fetchFeatures(event.screenPoint).then(function(response) {
    // Access the response from fetchFeatures
    response.allGraphicsPromise.then(function(graphics) {
      // Set the feature widget's graphic to the returned graphic from fetchFeatures
      featureWidget.graphic = graphics[0];
    });
  });
});
hasEventListener(type){Boolean}

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

Parameter
type String

The name of the event.

Returns
Type Description
Boolean Returns true if the class supports the input event.
hasHandles(groupKey){Boolean}inherited
Since: ArcGIS Maps SDK for JavaScript 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");
}

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

Returns
Type Description
PopupViewModel Returns an instance of the popup's view model.
See also
on(type, listener){Object}

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

Parameters

An event or an array of events to listen for.

listener Function

The function to call when the event fires.

Returns
Type Description
Object Returns an event handler with a remove() method that should be called to stop listening for the event(s).
Property Type Description
remove Function When 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(options)

Opens the popup at the given location with content defined either explicitly with content or driven from the PopupTemplate of input features. This method sets the popup's visible property to true. Users can alternatively open the popup by directly setting the visible property to true. The popup will only display if the view's size constraints in dockOptions are met or the location property is set to a geometry.

Parameters
Specification
options Object
optional

Defines the location and content of the popup when opened.

Specification
title String
optional

Sets the title of the popup.

content String
optional

Sets the content of the popup.

fetchFeatures Boolean
optional
Default Value: false

Since: 4.12

When true, indicates the popup should fetch the content of this feature and display it. If no PopupTemplate exists, a default template is created for the layer if defaultPopupTemplateEnabled = true. In order for this option to work, there must be a valid view and location set.

location Geometry
optional

Sets the popup's location, which is the geometry used to position the popup.

features Graphic[]
optional

Sets the popup's features, which populate the title and content of the popup based on each graphic's PopupTemplate.

promises Promise[]
optional

Sets pending promises on the popup. The popup will display once the promises resolve. Each promise must resolve to an array of Graphics. allows the user to scroll through the list of features returned from the query and choose the selection they want to display within the popup.

updateLocationEnabled Boolean
optional
Default Value: false

When true, indicates the popup should update its location for each paginated feature based on the selected feature's geometry.

When true, indicates that only the popup header will display.

See also
Examples
view.on("click", function(event){
  view.popup.open({
   location: event.mapPoint,  // location of the click on the view
   title: "You clicked here",  // title displayed in the popup
   content: "This is a point of interest"  // content displayed in the popup
  });
});
view.on("click", function(event){
   view.popup.open({
     location: event.mapPoint,  // location of the click on the view
     fetchFeatures: true // display the content for the selected feature if a popupTemplate is defined.
   });
 });
view.popup.open({
  title: "You clicked here",  // title displayed in the popup
  content: "This is a point of interest",  // content displayed in the popup
  updateLocationEnabled: true  // updates the location of popup based on
  // selected feature's geometry
});
view.popup.open({
  features: graphics,  // array of graphics
});

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

Returns
Type Description
PopupViewModel Returns an instance of the popup's view model.
See also
removeHandles(groupKey)inherited
Since: ArcGIS Maps SDK for JavaScript 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");
triggerAction(actionIndex)

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

Parameter
actionIndex Number

The index of the action to execute.

Event Overview

Name Type Summary Class
{action: ActionButton|ActionToggle}

Fires after the user clicks on an action or action toggle inside a popup.

more details
PopupViewModel

Event Details

trigger-action

Fires after the user clicks on an action or action toggle inside a popup. 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.

Property

The action clicked by the user. For a description of this object and a specification of its properties, see the actions property of this class.

See also
Example
// Defines an action to zoom out from the selected feature
let zoomOutAction = {
  // 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"
};
// Adds the custom action to the popup.
view.popup.viewModel.actions.push(zoomOutAction);

// Fires each time an action is clicked
view.popup.viewModel.on("trigger-action", function(event){
  // If the zoom-out action is clicked, then execute the following code
  if(event.action.id === "zoom-out"){
    // The view zooms out two LODs on each click
    view.goTo({
      center: view.center,
      zoom: view.zoom - 2
    });
  }
});

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