require(["esri/widgets/Features"], (Features) => { /* code goes here */ });
import Features from "@arcgis/core/widgets/Features.js";
esri/widgets/Features
The Features widget allows users to view a feature's popupTemplate content such as attributes, actions, related records, etc., without having to be tied to the View. This widget looks and behaves similarly to the Popup widget, however unlike Popup, the Features widget can be placed outside of the view. For example, when features are selected in the View, the Popup widget opens within the View whether it is docked or anchored to the selected feature. With the Features widget, the same information that popup provides is shown in a separate container from the view, such as a HTML div within a Calcite Design System Shell Panel.
In the image above, a Calcite shell panel displays the Features widget along with a MapView in a separate div.
A generic title
and content
property can be set directly on the Features widget or
each individual layer's PopupTemplate can be displayed (e.g.
the Olympic National Park feature's PopupTemplate that contains text, media, and relationship elements).
The action bar, shown below the title in the image above, displays actions that can be defined either on the widget level within the open() method
or in the PopupTemplate of the layer.
If multiple features are passed into the Features widget, the widget provides buttons to page though the features and a feature menu that allows the
list of features to be displayed so the end user can choose which feature content to display in the widget. The widget also respects
feature reduction PopupTemplates for binning and clustering.
The Features widget should be used if needing to use the Popup functionality outside of the View. If wanting to show a single feature's content without actions, related records, clustering configuration, etc., then use the Feature widget.
// Create a new instance of Features and set this on the View's
// popup. When features are selected in the map, the Features widget
// will automatically open in its respective container.
const view = new MapView({
container: "viewDiv",
map: map,
popup: new Features({
container: "features-widget"
})
});
// Create a new instance of Features and set the view property
// to the View along with the container that holds the widget
// such as a Calcite Shell Panel.
const featuresWidget = new Features({
view: view,
container: "features-widget"
});
// Use reactiveUtils to watch for when the view has a click event
// then open the Features widget in its respective container.
reactiveUtils.on(()=> view, "click",
(event)=>{
featuresWidget.open({
location: event.mapPoint,
fetchFeatures: true
})
});
Constructors
-
new Features(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 |
---|---|---|---|
Boolean | Indicates whether the popup displays its content. more details | Features | |
String|HTMLElement | The ID or node representing the DOM element containing the widget. more details | Widget | |
String|HTMLElement|Widget | The content of the Features widget. more details | Features | |
String | The name of the class. more details | Accessor | |
Graphic[] | An array of features associated with the Features widget. more details | Features | |
GoToOverride | This function provides the ability to override either the MapView goTo() or SceneView goTo() methods. more details | Features | |
Number | Indicates the heading level to use for the title of the widget. more details | Features | |
String | Icon which represents the widget. more details | Widget | |
String | The unique ID assigned to the widget when the widget is created. more details | Widget | |
String | The widget's default label. more details | Features | |
Promise | An array of pending Promises that have not yet been fulfilled. more details | Features | |
Graphic | The selected feature accessed by the Features widget. more details | Features | |
Number | Index of the feature that is selected. more details | Features | |
Feature | Returns a reference to the current Feature. more details | Features | |
String | The title of the Features widget. more details | Features | |
MapView|SceneView | A reference to the MapView or SceneView. more details | Features | |
FeaturesViewModel | This is a class that contains all the logic (properties and methods) that controls this widget's behavior. more details | Features | |
Boolean | Indicates whether the widget is visible. more details | Features | |
VisibleElements | The visible elements that are displayed within the widget. more details | Features |
Property Details
-
collapsed Booleanreadonly
-
Indicates whether the popup displays its content. If
true
, only the header displays.- Default Value:false
-
-
The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use cases when working with widgets.
Examples// Create the HTML div element programmatically at runtime and set to the widget's container const basemapGallery = new BasemapGallery({ view: view, container: document.createElement("div") }); // Add the widget to the top-right corner of the view view.ui.add(basemapGallery, { position: "top-right" });
// Specify an already-defined HTML div element in the widget's container const basemapGallery = new BasemapGallery({ view: view, container: basemapGalleryDiv }); // Add the widget to the top-right corner of the view view.ui.add(basemapGallery, { position: "top-right" }); // HTML markup <body> <div id="viewDiv"></div> <div id="basemapGalleryDiv"></div> </body>
// Specify the widget while adding to the view's UI const basemapGallery = new BasemapGallery({ view: view }); // Add the widget to the top-right corner of the view view.ui.add(basemapGallery, { position: "top-right" });
-
-
The content of the Features widget. When set directly on the Popup, this content is 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.
Example// This sets generic instructions in the widget that will always be displayed // unless it is overridden by a PopupTemplate featuresWidget.content = "Click a feature on the map to view its attributes";
-
The name of the class. The declared class name is formatted as
esri.folder.className
.
-
An array of features associated with the Features widget. 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 widget is 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 Features widget is set based on the value of the selected feature.
This value is
null
if no features are associated with the widget.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 Features widget instance. The content and title of // the widget 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]; const featuresWidget = new Features({ container: "features-widget", features: graphics visible: true });
-
goToOverride GoToOverride
-
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); };
-
headingLevel Number
-
Indicates the heading level to use for the title of the widget. By default, the title is rendered as a level 2 heading (e.g.
<h2>Popup title</h2>
). Depending on the widget's placement in your app, you may need to adjust this heading for proper semantics. This is important for meeting accessibility standards.
-
Icon which represents the widget. It is typically used when the widget is controlled by another one (e.g. in the Expand widget).
- Default Value:null
- See also
-
The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.
-
label String
-
The widget's default label.
-
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.
-
selectedFeature Graphicreadonly
-
The selected feature accessed by the Features widget. The content displayed in the widget 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.
-
selectedFeatureWidget Featurereadonly
-
Returns a reference to the current Feature. This is useful if needing to get a reference to the Feature widget in order to make any changes to it.
-
title String
-
The title of the Features 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.
- See also
Example// This title will display in the widget unless a selected feature's // PopupTemplate overrides it. featuresWidget.title = "Population by zip codes in Southern California";
-
viewModel FeaturesViewModel
-
This is a class that contains all the logic (properties and methods) that controls this widget's behavior. See the FeaturesViewModel class to access all properties and methods on the widget.
-
visible Boolean
-
Indicates whether the widget is visible.
-
visibleElements VisibleElements
-
The visible elements that are displayed within the widget. This provides the ability to turn individual elements of the widget's display on/off.
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 | ||
Use this method to remove focus from the Widget. more details | Features | ||
String | A utility method used for building the value for a widget's | Widget | |
Removes promises, features, content, and title from the Features widget. more details | Features | ||
This is a convenience method to closes the widget. more details | Features | ||
Destroys the widget instance. more details | Widget | ||
Boolean | Emits an event on the instance. more details | Features | |
Promise<FetchPopupFeaturesResult> | Use this method to return feature(s) at a given screen location. more details | Features | |
Use this method to give focus to the Widget if the widget is able to be focused. more details | Features | ||
Boolean | Indicates whether there is an event listener on the instance that matches the provided event name. more details | Features | |
Boolean | Returns true if a named group of handles exist. more details | Accessor | |
Boolean |
| Widget | |
Boolean |
| Widget | |
Boolean |
| Widget | |
FeaturesViewModel | Selects the feature at the next index in relation to the selected feature. more details | Features | |
Object | Registers an event handler on the instance. more details | Features | |
Opens the Features widget in its container with content defined either explicitly with | Features | ||
Adds one or more handles which are to be tied to the lifecycle of the widget. more details | Widget | ||
This method is primarily used by developers when implementing custom widgets. more details | Widget | ||
FeaturesViewModel | Selects the feature at the previous index in relation to the selected feature. more details | Features | |
Removes a group of handles owned by the object. more details | Accessor | ||
Object | This method is primarily used by developers when implementing custom widgets. more details | Widget | |
Renders widget to the DOM immediately. more details | Widget | ||
This method is primarily used by developers when implementing custom widgets. more details | Widget | ||
Triggers the trigger-action event and executes the action at the specified index in the actions array. more details | Features | ||
Promise |
| Widget |
Method Details
-
addHandles(handleOrHandles, groupKey)inherited
-
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.
-
blur()
-
Use this method to remove focus from the Widget.
-
A utility method used for building the value for a widget's
class
property. This aids in simplifying css class setup.Parameterrepeatable The class names.
ReturnsType Description String The computed class name. Example// .tsx syntax showing how to set css classes while rendering the widget render() { const dynamicIconClasses = { [css.myIcon]: this.showIcon, [css.greyIcon]: !this.showIcon }; return ( <div class={classes(css.root, css.mixin, dynamicIconClasses)} /> ); }
-
clear()
-
-
close()
-
This is a convenience method to closes the widget. Users can alternatively close the widget by directly setting the visible property to
false
.- See also
-
destroy()inherited
-
Destroys the widget instance.
-
emit(type, event){Boolean}
-
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
-
fetchFeatures(screenPoint, options){Promise<FetchPopupFeaturesResult>}
-
Use this method to return feature(s) at a given screen location. These features are fetched from all of the layerviews in the view. In order to use this, a layer must already have an associated PopupTemplate. This method allows a developer to control how the input location is handled.
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// Use reactiveUtils to watch the view's click event. reactiveUtils.on(() => view, "click", (event) => { // Call fetchFeatures and pass in the click event screenPoint featuresWidget.fetchFeatures(event.screenPoint).then((response) => { // Access the response from fetchFeatures response.allGraphicsPromise.then((graphics) => { // If there are no graphics in the click event, then make sure // the Features widget is not showing. if(graphics.length === 0){ featuresWidget.visible = false; } // If graphics do exist, set the Features widget features property to the returned // graphics from fetchFeatures and set the visible property to true. else{ featuresWidget.features = graphics; featuresWidget.visible = true; } }); });
-
focus()
-
Use this method to give focus to the Widget if the widget is able to be focused.
-
hasEventListener(type){Boolean}
-
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.
-
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"); }
-
isFulfilled()
may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled,true
will be returned.ReturnsType Description Boolean Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).
-
isRejected()
may be used to verify if creating an instance of the class is rejected. If it is rejected,true
will be returned.ReturnsType Description Boolean Indicates whether creating an instance of the class has been rejected.
-
isResolved()
may be used to verify if creating an instance of the class is resolved. If it is resolved,true
will be returned.ReturnsType Description Boolean Indicates whether creating an instance of the class has been resolved.
-
next(){FeaturesViewModel}
-
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
-
on(type, listener){Object}
-
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)
-
Opens the Features widget in its container with content defined either explicitly with
content
or driven from the PopupTemplate of input features. This method sets the Feature widget's visible property totrue
. Users can alternatively show the Features widget by directly setting the visible property totrue
.ParametersSpecificationoptions ObjectoptionalDefines the content of the Feature's widget when opened.
Specificationactions Collection<ActionButton>optionalThis property allows you to specify a collection of actions to the action bar when the Features widget opens.
collapsed BooleanoptionalIndicates whether the widget displays its content. If
true
, only the header displays.content String|HTMLElement|WidgetoptionalSets the content of the widget.
optional Sets the widget's features, which populate the title and content of the widget based on each graphic's PopupTemplate.
featureMenuOpen BooleanoptionalDefault Value: falseThis property enables multiple features in the widget to display in a list rather than displaying the first selected feature. Setting this to
true
allows the user to scroll through the list of features returned from the query and choose the selection they want to display within the widget.fetchFeatures BooleanoptionalDefault Value: falseWhen
true
, indicates the widget should fetch the content of this feature and display it. In order for this option to work, there must be a validview
andlocation
set.location GeometryoptionalThe geometry used to query for the features when
fetchFeatures=true
.optional Sets pending promises on the widget. The widget will display once the promises resolve. Each promise must resolve to an array of Graphics.
title StringoptionalSets the title of the widget.
updateLocationEnabled StringoptionalIndicates whether to update the location when the selectedFeatureIndex changes.
- See also
Examples// Use reactiveUtils to watch the view's click event. reactiveUtils.on(() => view, "click", (event) => { featuresWidget.open({ // Title and content displayed in the widget title: `Click location: (${event.mapPoint.x},${event.mapPoint.y})`, content: "This is the default content displayed on click." }); });
// The Features widget must have a view set on the widget along with the // location property to fetch features. // Use reactiveUtils to watch the view's click event. reactiveUtils.on(() => view, "click", (event) => { featuresWidget.open({ location: event.mapPoint, // Display the content for the selected feature(s) if a popupTemplate is defined. fetchFeatures: true }); });
// Open the Features widget with a specified array of graphics that already // have a PopupTemplate set and display the feature menu when it opens. featuresWidget.open({ // array of graphics features: graphics, // selected features initially display in a list featureMenuOpen: true });
-
own(handleOrHandles)inheritedDeprecated since 4.28 Use addHandles() instead.
-
Adds one or more handles which are to be tied to the lifecycle of the widget. The handles will be removed when the widget is destroyed.
const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true} ); this.own(handle); // Handle gets removed when the widget is destroyed.
ParameterhandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the widget is destroyed.
-
postInitialize()inherited
-
This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.
-
previous(){FeaturesViewModel}
-
Selects the feature at the previous index in relation to the selected feature.
ReturnsType Description FeaturesViewModel Returns an instance of the Features widget view model. - See also
-
removeHandles(groupKey)inherited
-
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");
-
This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.
ReturnsType Description Object The rendered virtual node.
-
renderNow()inherited
-
Renders widget to the DOM immediately.
-
scheduleRender()inherited
-
This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.
-
triggerAction(actionIndex)
-
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.
-
when()
may be leveraged once an instance of the class is created. This method takes two input parameters: acallback
function and anerrback
function. Thecallback
executes when the instance of the class loads. Theerrback
executes if the instance of the class fails to load.Parameterscallback FunctionoptionalThe function to call when the promise resolves.
errback FunctionoptionalThe function to execute when the promise fails.
ReturnsType Description Promise Returns a new promise for the result of callback
.Example// Although this example uses the BasemapGallery widget, any class instance that is a promise may use when() in the same way let bmGallery = new BasemapGallery(); bmGallery.when(function(){ // This function will execute once the promise is resolved }, function(error){ // This function will execute if the promise is rejected due to an error });
Type Definitions
-
FetchFeaturesOptions
-
Optional properties to use with the fetchFeatures method.
- Properties
-
event Object
The
click
event for either the MapView or SceneView. The event can be supplied in order to adjust the query radius depending on the pointer type. For example, touch events query a larger radius.signal AbortSignalThe signal object that can be used to abort the asynchronous task. The returned promise will be rejected with an Error named
AbortError
when an abort is signaled. See also AbortController for more information on how to construct a controller that can be used to deliver abort signals.
-
VisibleElements
-
The visible elements that are displayed within the widget. This provides the ability to turn individual elements of the widget's display on/off.
- Properties
-
actionBar BooleanDefault Value:true
Indicates whether to display the action bar that holds the feature's actions will be displayed.
closeButton BooleanDefault Value:trueIndicates whether to display a close button on the widget dialog.
collapseButton BooleanDefault Value:falseSince 4.28. Indicates whether to display the collapse button on the widget dialog.
featureNavigation BooleanDefault Value:trueIndicates whether pagination for feature navigation will be displayed. This allows the user to scroll through various selected features using pagination arrows.
heading BooleanDefault Value:trueIndicates whether to display the widget heading.
spinner BooleanDefault Value:trueIndicates whether to display the widget's loading spinner.
Event Overview
Name | Type | Summary | Class |
---|---|---|---|
{action: ActionButton} |
Fires after the user clicks on an action in the Features widget. more details |
Features |
Event Details
-
trigger-action
-
Fires after the user clicks on an action in the Features widget. 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
The action clicked by the user. For a description of this object and a specification of its properties, see the actions property on the view model class.
- See also
ExamplefeaturesWidget.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 }); } });