require(["esri/widgets/Popup/PopupViewModel"], function(PopupVM) { /* code goes here */ });
Class: esri/widgets/Popup/PopupViewModel
Inheritance: PopupViewModel Accessor
Since: ArcGIS API 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.
NameTypeSummaryClass
Collection<(ActionButton|ActionToggle)>

Collection of action or action toggle objects.

more details
more detailsPopupViewModel
Collection<(ActionButton|ActionToggle)>

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

more details
more detailsPopupViewModel
Boolean

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

more details
more detailsPopupViewModel
String | HTMLElement | Widget

The content of the popup.

more details
more detailsPopupViewModel
String

The name of the class.

more details
more detailsAccessor
Number

The number of selected features available to the popup.

more details
more detailsPopupViewModel
Graphic[]

An array of features associated with the popup.

more details
more detailsPopupViewModel
GoToOverride

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

more details
more detailsPopupViewModel
Boolean

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

more details
more detailsPopupViewModel
Point

Geometry used to position the popup.

more details
more detailsPopupViewModel
Number

The number of promises remaining to be resolved.

more details
more detailsPopupViewModel
Number

The number of selected promises available to the popup.

more details
more detailsPopupViewModel
Promise[]

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

more details
more detailsPopupViewModel
Graphic

The selected feature accessed by the popup.

more details
more detailsPopupViewModel
Number

Index of the feature that is selected.

more details
more detailsPopupViewModel
String

The view model's state.

more details
more detailsPopupViewModel
String

The title of the popup.

more details
more detailsPopupViewModel
MapView | SceneView

The view associated with the Popup instance.

more details
more detailsPopupViewModel
Boolean

Indicates whether the popup is visible.

more details
more detailsPopupViewModel

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 override this action by removing it from the actions Collection 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
var 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();
  }
});
allActionsCollection<(ActionButton|ActionToggle)>readonly
Since: ArcGIS API for JavaScript 4.8

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

autoCloseEnabledBoolean
Since: ArcGIS API for JavaScript 4.5

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

Default Value:false

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";
declaredClassStringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

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

featureCountNumberreadonly

The number of selected features available to the popup.

Default Value:0
featuresGraphic[]

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 poup 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.
var 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
var graphics = [g1, g2, g3, g4, g5];
view.popup.viewModel.features = graphics;
goToOverrideGoToOverride
Since: ArcGIS API 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);
};
highlightEnabledBoolean
Since: ArcGIS API 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
locationPoint

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.set("visible", true);
});
pendingPromisesCountNumberreadonly

The number of promises remaining to be resolved.

Default Value:0
See also:
promiseCountNumberreadonly

The number of selected promises available to the popup.

Default Value:0
promisesPromise[]

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.

selectedFeatureGraphicreadonly

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

selectedFeatureIndexNumber

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

stateStringreadonly

The view model's state.

Possible Values: ready | disabled

Default Value:disabled
titleString

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.

visibleBoolean

Indicates whether the popup is visible.

Method Overview

NameReturn TypeSummaryClass

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

more details
more detailsPopupViewModel

Emits an event on the instance.

more details
more detailsPopupViewModel
Boolean

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

more details
more detailsPopupViewModel
PopupViewModel

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

more details
more detailsPopupViewModel
Object

Registers an event handler on the instance.

more details
more detailsPopupViewModel
PopupViewModel

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

more details
more detailsPopupViewModel

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

more details
more detailsPopupViewModel

Method Details

clear()

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

emit(type, event)
Since: ArcGIS API 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

The event payload.

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:
TypeDescription
BooleanReturns true if the class supports the input event.

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

Returns:
TypeDescription
PopupViewModelReturns 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:
type String

The name of event to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event.
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
See also:
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});

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

Returns:
TypeDescription
PopupViewModelReturns an instance of the popup's view model.
See also:
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

NameTypeSummaryClass
{action: ActionButtonActionToggle}

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

more details
more detailsPopupViewModel

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

API Reference search results

NameTypeModule
Loading...