Select to view content in your preferred language

visible features in featureLayerView

433
1
11-17-2022 02:36 PM
GaryB
by
Occasional Contributor

Hello,

I have created a featureLayerView from a polygon featureLayer (think census tracts) and I allow the user to set various attribute based filters.

I would now like to get the number of features currently shown on the screen (which seems like it would be a very straight forward thing to do).

To do this I apply a spatial query to the featureLayerView using the extent from the mapView for query geometry. 

The problem is I sometimes get  the correct answer and sometimes don't (the worst kind of problem).  Looking at the features that are returned, sometimes features  are well out of current view (e.g. closest point on the polygon is probably a few miles outside of the relatively zoomed in view).   

All data, as well as the mapview are in web Mercator.

Any thoughts would be greatly appreciated,

Thanks, Gary

0 Kudos
1 Reply
ReneRubalcava
Honored Contributor

Are you checking for the view or layerView updating property to be false before you query?

Here is a sample watching for the extent to change and waiting for the view to stop updating.

https://codepen.io/odoe/pen/mdKqVdM?editors=0010

It uses a debounce, but for client-side data, might not need it.

If this isn't the issue you're seeing, if you have a repro to look at, could get a better idea of the issue.

0 Kudos