import FeatureFilter from "@arcgis/core/layers/support/FeatureFilter.js";
Inheritance
FeatureFilterAccessor
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 geometry
featureLayerView.filter = new FeatureFilter({
where: "percentile >= 30",
geometry: filterPolygon,
spatialRelationship: "contains",
distance: 10,
units: "miles"
});

screen-size-perspective

See also

Constructors

Constructor

Constructor

Parameters

ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.
Example
// Typical usage
const filter = new FeatureFilter({
where: "magnitude >= 3"
});
layerView.filter = filter;

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.
PropertyTypeClass
readonly inherited
Query["distance"]
Query["geometry"]
Query["spatialRelationship"]
Query["timeExtent"]
Query["units"] | null | undefined
Query["where"]

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

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

distance

autocast Property
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

autocast Property
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

Property
Type
number[] | null | undefined

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 empty
const oidsArray = layerView.queryObjectIds(query);
layerView.filter = oidsArray.length > 0 ? { objectIds: oidsArray } : { where: "1=0" };

spatialRelationship

autocast Property
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.

intersects

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

contains

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.

crosses

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

envelope-intersects

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

overlaps

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.

touches

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.

within

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

disjoint

See also
Default value
"intersects"
Example
// display features that are completely within state
let filter = new FeatureFilter({
spatialRelationship: "contains",
geometry: statePolygon
});

timeExtent

autocast Property
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.

units

autocast Property
Type
Query["units"] | null | undefined

The unit for calculating the buffer distance when distance is specified in a spatial filter. If units is not specified, the unit is derived from the filter geometry's spatial reference.

where

autocast Property
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.

See also
Examples
filter.where = "NAME = '" + stateName + "'";
filter.where = "POP04 > " + population;

Methods

MethodSignatureClass
inherited static
fromJSON(json: any): any
clone(): FeatureFilter
createQuery(): Query
inherited
toJSON(): any

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

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

ParameterTypeDescriptionRequired
json
any

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

Method
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

Method
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 configuration
const queryParams = layerView.filter.createQuery();
// set a geometry for querying features by the view's extent
queryParams.geometry = view.extent;
// query the layer with the modified params object
layerView.queryFeatures(queryParams)
.then(function(results){
// prints the array of result graphics to the console
console.log(results.features);
});

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

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.