You can perform a SQL or spatial query to access a subset of the data in a feature service. The results of the query can contain the attributes, geometry, or both attributes and geometry, for each matching record. These results can be used for further processing or can be displayed in an application.
How to query a feature service
To perform SQL and spatial queries, you reference the main Esri Leaflet plugin. The L.esri.
operation can be used to query feature, map, and image services.
- Reference the Esri Leaflet plugin.
- Find the URL of the service against which you want to query.
- Set the service URL and the feature layer ID.
- Define the SQL or spatial query.
Example
Query a feature layer (spatial)
In this example, you perform a spatial query to find which parcels intersect a geometry. Available spatial queries include: within, contains, intersects, and overlaps.
<script src="https://unpkg.com/esri-leaflet@3.0.12/dist/esri-leaflet.js"
integrity="sha512-oUArlxr7VpoY7f/dd3ZdUL7FGOvS79nXVVQhxlg6ij4Fhdc4QID43LUFRs7abwHNJ0EYWijiN5LP2ZRR2PY4hQ=="
crossorigin=""></script>
<script>
parcels
.query()
.intersects(feature.geometry)
.ids(function (error, queryResult) {
parcels.setWhere("OBJECTID IN (" + queryResult.join(",") + ")");
});
</script>