creating a filter (query?)

3929
2
09-09-2014 06:32 AM
Labels (1)
joepublic
New Contributor III

I am using esri's feature service and ersi-leaflet library to display my map.  The following code snippet is used to display

the countries

featureURL = "http://dev.xxxxx.org/arcgis/rest/services/MEP/noRelate_tester/FeatureServer/0"

var countries = L.esri.featureLayer(featureURL,

{

   style: getStyle,

  onEachFeature: onEachFeature

}).addTo(map);

 

At this time, it is displaying all the countries.

 

I'd like to display (or highlight) only the countries that satisfies a certain filter or query.

For example, I want to display only the countries that satisfy the filter/query type = SDG.

 

I reviewed the docs and examples for esri-leaflet library but am totally lost as to how use the query method.

 

Can someone point me to an example that show how to use the filter/query to do the above

 

Thanks

Chris

Tags (1)
0 Kudos
2 Replies
WinstonHoyle
New Contributor II

The query method has examples on Esri Leaflet.

Example 1: https://esri.github.io/esri-leaflet/examples/querying-feature-layers-1.html

Example 2: https://esri.github.io/esri-leaflet/examples/querying-feature-layers-2.html

From Esri Leaflet Issues, I found a problem similar to yours. 

Since you pass a GeoJSON feature you have access to attributes, like the "filter" attribute. 

function filter(feature) {
   return feature.properties.type === "SDG";
}

var countries = L.esri.featureLayer(featureURL,{
  filter: filter,
  style: getStyle,
  onEachFeature: onEachFeature
}).addTo(map);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Issue #214: https://github.com/Esri/esri-leaflet/issues/214

0 Kudos
JohnGravois
Frequent Contributor

instead of fetching all the features from the service and filtering on the client, it's a better to only ask ArcGIS Online/Server for the features you want (using the where constructor option).

L.esri.featureLayer({
  where: "STATE_NAME = 'Kansas'",
}).addTo(map);

 

Querying features | Esri Leaflet 

0 Kudos