Learn how to use a SQL query to limit features displayed in a feature layer.
A hosted feature layer can contain a large number of features. To display a subset of the features, you can filter features on the server-side with a definition expression. Definition expressions are different than feature layer queries: they only support a SQL where clause without a geometry (spatial) parameter, and are only used to filter features at the time they are displayed in a map or scene. They cannot be used to get features like a feature layer query.
You need a free ArcGIS developer account to access your dashboard and API keys. The API key must be scoped to access the services used in this tutorial.
In the require statement, add the FeatureLayer module.
The ArcGIS Maps SDK for JavaScript is available as AMD modules and ES modules, but this tutorial is based on AMD. The AMD require function uses references to determine which modules will be loaded – for example, you can specify "esri/Map" for loading the Map module. After the modules are loaded, they are passed as parameters (e.g. Map) to the callback function where they can be used in your application. It is important to keep the module references and callback parameters in the same order. For more information on the different types of modules, visit the Introduction to Tooling guide topic.
Use the FeatureLayer class to access the LA County Parcels feature layer. Since you are performing a server-side query, the feature layer does not need to be added to the map. However, to view the results of the query, the feature layer will be added to the map.
Create a featureLayer and set the url property to access the feature layer in the feature service. Set the outFields property to return all attributes on the client and the popupTemplate to display the parcel description and land value. Set the definitionExpression to 1=0 so no features are displayed when the layer is loaded. Add featureLayer to the map.
When the map displays, you should be able to choose a SQL query from the selector that applies a definition expression to the visible extent of the map. Only the features that match are added to the feature layer and displayed in the view.