Can I filter a FeatureLayer by a custom geometry

527
3
03-28-2018 03:09 AM
deleted-user-RhG9zFDAFTI1
New Contributor

Hi I'm using ArcGIS JS API 3.21 and Web Appbuilder for Developers 2.7.

I'm defining and adding a feature layer from a map service to my map, giving it a custom unique value renderer and setting a definition expression and it is working fine. The final thing I need to do is to filter it by a custom polygon geometry. In the service you can pass custom geometry to a query, I just need to find out how to set a filter on my feature layer using the same geometry.

I've tried using MODE_SELECTION and then selecting features with the geometry, but this gets rid of my unique value renderer in favour of the selection symbol. I'm pretty sure I can't set a unique value renderer as the selection symbol and even then that would be a bit hacky.

The user needs to generate a custom selection of features from the map using attribute filtering and custom polygon filtering, and once they are happy with their selection the features are submitted via a HTTP request to an ordering system. The user only wants their currently selected features to appear on the map.

Something like this would be good:

var featureLayer = new FeatureLayer(layerUrl, {
mode: FeatureLayer.MODE_SNAPSHOT,
outFields: [field],
id: OverLayerID,
showAttribution: false
});
featureLayer.setRenderer(renderer);
featureLayer.setDefinitionExpression(expr);
featureLayer.setInputGeometry(geometry); <------  something like this would be perfect
this.map.addLayer(featureLayer);

The featurelayer definition expression and input geometry can be updated on the fly as the user interacts with the widget.

Any suggestions would be appreciated.

Thanks

Mike.

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Mike,

   Your workflow should be do a queryIds on the FeatureLayer to get the ids that the geometry intersect with and then use the FeatureLayers setDefinitionExpression using a sql statement like ObjectID IN (your results from the Ids query array.join()).

0 Kudos
deleted-user-RhG9zFDAFTI1
New Contributor

Hi Robert,

  Thanks for getting back to me. The feature layer that they are doing their selection on has many thousands of features that are densely packed. Is there a limit to the length of the definition expression that I can use, as the number of selected features have the potential to be quite large.

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mike,

   That is exactly the situation that the SQL Syntax ObjectID IN (x,y,z) is capable of handling.

0 Kudos