import FeatureFilter from "@arcgis/core/layers/support/FeatureFilter.js";const FeatureFilter = await $arcgis.import("@arcgis/core/layers/support/FeatureFilter.js");- Inheritance
- FeatureFilter→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.22
This class defines parameters for setting a client-side filter on a FeatureLayer.featureEffect or layer view. Once a FeatureFilter's properties are defined, it can be used to set the FeatureLayerView.filter property of the layer view or FeatureEffect.filter.
You can set filters by attributes, time, geometry and geometry with distance. Only the features that meet the requirements specified in the filter will be displayed. Filters only affect feature visibility. They do not return geometry or attribute information associated with the filtered features. The FeatureLayerView.queryFeatures() method must be called to access additional information.
FeatureFilter runs against features that are available for drawing on the client-side. Client-side features are optimized
for performance hence, feature filter results are not always accurate. Use the layer's queryFeatures() method or the definitionExpression
property if you need to run your filter against all features that are available in the layer.
See querying and filtering guide doc for more information.
// display rain gauges where their water percent is over 30%// and if the gauges are completely contained by the 10-mile// buffer around the filter geometryfeatureLayerView.filter = new FeatureFilter({ where: "percentile >= 30", geometry: filterPolygon, spatialRelationship: "contains", distance: 10, units: "miles"});
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
- Example
- // Typical usageconst filter = new FeatureFilter({where: "magnitude >= 3"});layerView.filter = filter;
Properties
distance
- Type
- Query["distance"]
Specifies a search distance from a given geometry in a spatial filter. The units property indicates the unit of measurement. In essence, setting this property creates a buffer at the specified size around the input geometry. The filter will use that buffer to display features in the layer or layer view that adhere to the to the indicated spatial relationship.
geometry
- Type
- Query["geometry"]
The geometry to apply to the spatial filter. The spatial relationship as specified by spatialRelationship will indicate how the geometry should be used to filter features.
Known Limitations
Mesh geometry types are currently not supported.
objectIds
An array of objectIds of the features to be filtered. If the array of object IDs is empty, all features will be displayed.
To hide all features when the array is empty, set the filter's where property to 1=0 as shown below.
- Example
- // hide all features when objectIds array is emptyconst oidsArray = layerView.queryObjectIds(query);layerView.filter = oidsArray.length > 0 ? { objectIds: oidsArray } : { where: "1=0" };
spatialRelationship
- Type
- Query["spatialRelationship"]
For spatial filters, this parameter defines the spatial relationship to filter features in the layer view against the filter geometry. The spatial relationships discover how features are spatially related to each other. For example, you may want to know if a polygon representing a county completely contains points representing settlements.
The spatial relationship is determined by whether the boundaries or interiors of a geometry intersect.
- Boundary — The endpoints of all linear parts for line features, or the linear outline of a polygon. Only lines and polygons have boundaries.
- Interior — Points are entirely interior and have no boundary. For lines and polygons, the interior is any part of the geometry that is not part of the boundary.
The possible values for this parameter are described below and the images highlight the geometries returned for the specified spatial relationship for given geometries.
The intersects spatial relationship returns features in the layer view that intersect the filter geometry.
Known Limitations
The filter of SceneLayerView with 3D object scene layers only supports the
spatial relationships contains, intersects and disjoint.

The contains spatial relationship returns features in the layer view that are completely contained by the filter geometry.

The crosses spatial relationship returns features in the layer view when the interior of a filter geometry comes into contact with
the interior or boundary of features in the layer view. In other words, the geometries share some interior area, but not all interior area.

The envelope-intersects spatial relationship returns features in the layer view that intersect the envelope (or extent)
of the filter geometry.

The overlaps spatial relationship returns features in the layer view that overlap the filter geometry.
Only features of the same geometry can be compared.

The touches spatial relationship returns features in the layer view that touch the filter geometry.
The boundaries of the geometries intersect, but not their interiors.

The within spatial relationship returns features in the layer view that completely contain the filter geometry.
In other words, the filter geometry is completely within the features in the layer view. It is opposite of
contains.

The disjoint spatial relationship returns features in the layer view that do not intersect the filter geometry in anyway.
Opposite of intersects.

- Default value
- "intersects"
- Example
- // display features that are completely within statelet filter = new FeatureFilter({spatialRelationship: "contains",geometry: statePolygon});
timeExtent
- Type
- Query["timeExtent"]
A range of time with start and end date. Only the features that fall within this time extent will be displayed.
The Date field to be used for timeExtent should be added to FeatureLayer.outFields
list when the layer is initialized. This ensures the best user experience when switching or updating fields for time filters.
Notes
The temporal filter can only be applied to a layer view if its layer has TimeInfo.
where
- Type
- Query["where"]
A where clause for the feature filter. Any legal SQL92 where clause operating on the fields in the layer is allowed. Be sure to have the correct sequence of single and double quotes when writing the where clause in JavaScript.
For apps where users can interactively change fields used for attribute filter, we suggest you include all possible fields in the FeatureLayer.outFields of the layer. This ensures the best user experience when switching or updating fields for attribute filters.
Notes
Attribute values are case sensitive.
- Examples
- filter.where = "NAME = '" + stateName + "'";filter.where = "POP04 > " + population;
Methods
| Method | Signature | Class |
|---|---|---|
| inherited static | fromJSON(json: any): any | |
| clone(): FeatureFilter | | |
| createQuery(): Query | | |
| inherited | toJSON(): any |
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
clone
- Signature
-
clone (): FeatureFilter
Creates a deep clone of the FeatureFilter object.
- Returns
- FeatureFilter
A new instance of a FeatureFilter object equal to the object used to call
.clone().
createQuery
- Signature
-
createQuery (): Query
Creates Query parameters that can be used to fetch features that satisfy the layer's current filters and definitions.
- Returns
- Query
The query object representing the layer's filters and other definitions.
- Example
- // Get a query object from the filter's current configurationconst queryParams = layerView.filter.createQuery();// set a geometry for querying features by the view's extentqueryParams.geometry = view.extent;// query the layer with the modified params objectlayerView.queryFeatures(queryParams).then(function(results){// prints the array of result graphics to the consoleconsole.log(results.features);});
toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.