Select to view content in your preferred language

Changing the visible property on a feature doesn't change the actual visibility

716
5
07-20-2023 07:40 PM
sfkpereira
New Contributor II

Hi,

Scenario setup:

  • Create a feature layer or multiple (client side only)
  • Adding thousands of features using applyEdit.

Up to that point everything works, now I am checking if all my features  (could be multiple feature layers plotted at once) are in an union of geometries and for any features that are not I want to set them as not visible. I already made it work using FeatureFilters and effects but I want to be able to inspect the features and know if they are visible not just apply a css filter.

I am currently creating a query where I use the geometry and the spatialRelationship of 'disjoint' then loop through all the features and set visible to false just like any graphic and I applyEdits with the  updateFeatures property and when it says it updated the features but nothing changes on the layer. I have seen posts from years ago with similar questions so I guess my question is if there is a way to actually change the visibility or is the only option to remove them and re-add them again.

 

Anyone could replicate the issue in any sample that contains applyEdit and change it to use update and change the visible property of the features. Like on this one I hanged the delete to updating  https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer-coll...

Thanks in advance for any advice

0 Kudos
5 Replies
ReneRubalcava
Frequent Contributor II

When Features are part of a FeatureLayer, the visibility is handled by the layer, not the features. You can define what is visible based on the definitionExpression.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#definiti...

The visibility of individual features would only work in a GraphicsLayer, since it's just a bag of graphics.

0 Kudos
sfkpereira
New Contributor II

Thanks for the answering, 

So for my scenario where I would like to hide records depending on a polygon spatialRelationship and keep track of the now not visible items my best solution would be to delete the features or use a graphics layer?

0 Kudos
ReneRubalcava
Frequent Contributor II

If you don't want to use FeatureFilter, I would use the FeatureLayer (not visible) as the source for queries and place the results in a GraphicsLayer. Then you can quickly removeAll() on the graphics layer and add the results. You lose query/render capabilities which are not available on a GraphicsLayer, but it would work. This scenario is really what the FeatureFilter was designed for though.

0 Kudos
sfkpereira
New Contributor II

FeatureFilter is a nice feature but sadly doesn't help with the business needs. I need to know how many features fall within each bucket so I can reflect that in the legend with how many records of X bucket are visible in an as in 90 visible out of 100 total records in that bucket (10hidden in that example) and other small features so I need to keep counts at all times and I am not sure FeatureFilter allows me to do that and I need to run filters in all feature layers and not the views as I want to update all records

0 Kudos
ReneRubalcava
Frequent Contributor II

You can query the objectids on the layer https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryObj... and then use the result oids in your definitionExpression.

 

Or you can have a result FeatureLayer you use with applyEdits to put the results of the spatial query. Would require you delete the old features on update, but I've seen it done.

0 Kudos