require(["esri/widgets/Popup/PopupViewModel"], (PopupVM) => { /* code goes here */ });
import PopupVM from "@arcgis/core/widgets/Popup/PopupViewModel.js";
esri/widgets/Popup/PopupViewModel
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.
- See also
Constructors
-
new PopupViewModel(properties)
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
Collection<(ActionButton|ActionToggle)> | Collection of action or action toggle objects. more details | FeaturesViewModel | |
Boolean | Indicates if the view model is active when it is visible and is not waiting for results. more details | FeaturesViewModel | |
Collection<(ActionButton|ActionToggle)> | A collection of actions or action toggles. more details | FeaturesViewModel | |
Boolean | This closes the container when the View camera or Viewpoint changes. more details | FeaturesViewModel | |
Boolean | This property indicates to the | PopupViewModel | |
Boolean | Indicates if the "Browse features" experience is active in a cluster popup. more details | FeaturesViewModel | |
String|HTMLElement|Widget | The information to display. more details | FeaturesViewModel | |
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. more details | FeaturesViewModel | |
Boolean | Enables automatic creation of a popup template for layers that have popups enabled but no popupTemplate defined. more details | FeaturesViewModel | |
Number | The number of selected features available. more details | FeaturesViewModel | |
Graphic[] | An array of features. more details | FeaturesViewModel | |
Number | The number of features to fetch at one time. more details | FeaturesViewModel | |
Abilities | Defines the specific abilities that can be used when querying and displaying content. more details | FeaturesViewModel | |
FeatureViewModel[] | An array of feature view model(s). more details | FeaturesViewModel | |
GoToOverride | This function provides the ability to override either the MapView goTo() or SceneView goTo() methods. more details | FeaturesViewModel | |
Boolean | Highlight the selected feature using the highlightOptions set on the MapView or the highlightOptions set on the SceneView. more details | FeaturesViewModel | |
Boolean | Indicates whether or not to include defaultActions. more details | FeaturesViewModel | |
Point | Geometry used to show the location of the feature. more details | FeaturesViewModel | |
Number | The number of promises remaining to be resolved. more details | FeaturesViewModel | |
Number | The number of selected promises available. more details | FeaturesViewModel | |
Promise[] | An array of pending Promises that have not yet been fulfilled. more details | FeaturesViewModel | |
Graphic | The graphic used to represent the cluster extent when the | FeaturesViewModel | |
Graphic | The selected feature accessed. more details | FeaturesViewModel | |
Number | Index of the feature that is selected. more details | FeaturesViewModel | |
String | The view model's state. more details | FeaturesViewModel | |
String | The title of the widget. more details | FeaturesViewModel | |
MapView|SceneView | A reference to the MapView or SceneView. more details | FeaturesViewModel | |
Boolean | Indicates whether the widget is visible. more details | FeaturesViewModel | |
Boolean | Indicates whether a feature was found while resolving promises. more details | FeaturesViewModel |
Property Details
-
-
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. 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 actions by setting includeDefaultActions to
false
, or by setting the overwriteActions property totrue
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. 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 that zooms the view out several LODs, you would define the zoom-out code in a separate function. Then you would call the customzoom-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.
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(); } });
-
Since: ArcGIS Maps SDK for JavaScript 4.17
-
Indicates if the view model is active when it is visible and is not waiting for results.
- See also
-
Since: ArcGIS Maps SDK for JavaScript 4.8
-
A collection of actions or action toggles.
-
Since: ArcGIS Maps SDK for JavaScript 4.5
-
- Default Value:false
-
autoOpenEnabled BooleanSince: ArcGIS Maps SDK for JavaScript 4.10Deprecated since 4.27. Use MapView/SceneView.popupEnabled instead.
-
This property indicates to the
Popup
that it needs to allow or disallow the click event propagation. Set this value tofalse
if wanting to manually open the widget using the open.- Default Value:true
Exampleview.popup.viewModel.autoOpenEnabled = false; view.on("click", (event) => { // Manually open the popup view.popup.open({ // Set the options for opening the popup ... }); });
-
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 action button. It becomesfalse
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;
-
-
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";
-
Since: ArcGIS Maps SDK for JavaScript 4.7
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
Since: ArcGIS Maps SDK for JavaScript 4.19
-
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
.
-
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).- Starting with version 4.12, PopupTemplate content can no longer be set using a
wildcard, e.g.
*
. Instead, set thedefaultPopupTemplateEnabled
property totrue
. - Starting with version 4.28,
date
fields are formatted using theshort-date-short-time
preset dateFormat rather thanlong-month-day-year
in default popup templates created by setting thedefaultPopupTemplateEnabled
property totrue
. For example, previously a date that may have appeared as"December 30, 1997"
will now appear as"12/30/1997 6:00 PM"
.
- Default Value:false
- Starting with version 4.12, PopupTemplate content can no longer be set using a
wildcard, e.g.
-
The number of selected features available.
- Default Value:0
-
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
andtitle
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;
-
The number of features to fetch at one time.
- Default Value:20
-
Since: ArcGIS Maps SDK for JavaScript 4.21
-
Defines the specific abilities that can be used when querying and displaying content.
-
Since: ArcGIS Maps SDK for JavaScript 4.21
-
An array of feature view model(s).
-
goToOverride GoToOverride inheritedSince: ArcGIS Maps SDK for JavaScript 4.8
-
This function provides the ability to override either the MapView goTo() or SceneView goTo() methods.
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); };
-
Since: ArcGIS Maps SDK for JavaScript 4.4
-
Highlight the selected feature using the highlightOptions set on the MapView or the highlightOptions set on the SceneView.
- Default Value:true
-
Since: ArcGIS Maps SDK for JavaScript 4.19
-
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;
-
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. view.on("click", ({ mapPoint }) => { view.popup.viewModel.location = mapPoint; view.popup.visible = true; });
-
The number of promises remaining to be resolved.
- Default Value:0
- See also
-
The number of selected promises available.
- Default Value:0
-
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.
-
Since: ArcGIS Maps SDK for JavaScript 4.19
-
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.
-
The selected feature accessed. The content is determined based on the PopupTemplate assigned to this feature.
-
Index of the feature that is selected. When features are set, the first index is automatically selected.
-
The view model's state.
Possible Values:"ready"|"disabled"
- Default Value:disabled
-
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";
-
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.- Default Value:false
- See also
-
Since: ArcGIS Maps SDK for JavaScript 4.17
-
Indicates whether a feature was found while resolving promises.
- Default Value:false
- See also
Method Overview
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 all promises, features, content, and title. more details | FeaturesViewModel | ||
Boolean | Emits an event on the instance. more details | FeaturesViewModel | |
Promise<FetchPopupFeaturesResult> | Use this method to return feature(s) at a given screen location. more details | FeaturesViewModel | |
Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | FeaturesViewModel | |
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
FeaturesViewModel | Selects the feature at the next index in relation to the selected feature. more details | FeaturesViewModel | |
Object | Registers an event handler on the instance. more details | FeaturesViewModel | |
Opens the widget at the given location with content defined either explicitly with | FeaturesViewModel | ||
FeaturesViewModel | Selects the feature at the previous index in relation to the selected feature. more details | FeaturesViewModel | |
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 | FeaturesViewModel |
Method Details
-
addHandles(handleOrHandles, groupKey)inheritedSince: 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();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey 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()inherited
-
-
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.
Parameterstype StringThe name of the event.
event ObjectoptionalThe event payload.
ReturnsType Description Boolean true
if a listener was notified
-
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, 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.
ParametersscreenPoint ObjectAn object representing a point on the screen. This point can be in either the MapView or SceneView.
Specificationx NumberThe x coordinate.
y NumberThe y coordinate.
options FetchFeaturesOptionsoptionalThe options to pass into the
fetchFeatures
method.ReturnsType Description Promise<FetchPopupFeaturesResult> Resolves with the selected hitTest
location. In addition, it also returns an array of graphics if thehitTest
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 view.on("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]; }); }); });
-
Indicates whether there is an event listener on the instance that matches the provided event name.
Parametertype StringThe name of the event.
ReturnsType Description Boolean Returns true if the class supports the input event.
-
Since: ArcGIS Maps SDK for JavaScript 4.25
-
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType 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.
ReturnsType Description FeaturesViewModel Returns an instance of the popup's view model. - See also
-
Registers an event handler on the instance. Call this method to hook an event with a listener.
ParametersAn event or an array of events to listen for.
listener FunctionThe function to call when the event fires.
ReturnsType 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. Exampleview.on("click", function(event){ // event is the event handle returned after the event fires. console.log(event.mapPoint); });
-
open(options)inherited
-
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 totrue
. Users can alternatively set the visible property totrue
.ParametersSpecificationoptions ObjectoptionalDefines the location and content of the popup when opened.
Specificationtitle StringoptionalSets the title of the popup.
content StringoptionalSets the content of the popup.
fetchFeatures BooleanoptionalDefault Value: falseSince: 4.12
When
true
, indicates the feature's content should be fetched and displayed. 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 validview
andlocation
set.location GeometryoptionalSets the location, which is the geometry used to position the popup.
optional Sets the features, which populates the title and content based on each graphic's PopupTemplate.
optional Sets pending promises. The UI will display once the promises resolve. Each promise must resolve to an array of Graphics.
updateLocationEnabled BooleanoptionalDefault Value: falseWhen
true
, indicates the location property will be updated for each paginated feature based on the selected feature's geometry.Examples// Manually opens the corresponding widget. view.on("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. view.on("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 });
-
-
Selects the feature at the previous index in relation to the selected feature.
ReturnsType Description FeaturesViewModel Returns an instance of the popup's view model. - See also
-
removeHandles(groupKey)inheritedSince: ArcGIS Maps SDK for JavaScript 4.25
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
triggerAction(actionIndex)inherited
-
Triggers the trigger-action event and executes the action at the specified index in the actions array.
ParameteractionIndex NumberThe 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 in the action bar. more details |
FeaturesViewModel |
Event Details
-
trigger-actioninherited
-
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.
- Property
-
action ActionButton|ActionToggle
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", (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 }); } });