Is there a similar property or workaround like definitionExspression of a featureLayer but in graphicsLayer?
my goal is to filter out graphics with certain attributes from a graphicsLayer but not remove them.
Hi there, You should use client-side FeatureLayer instead of GraphicsLayer if you want to filter features based on attributes. We have couple of samples that showcase how to create client-side feature layer from graphics
https://next.sites.afd.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/
https://next.sites.afd.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection-edits/
FeatureLayer.source SDK help talks about how to create client-side layers: https://next.sites.afd.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#source
With all this said, you still must use GraphicsLayer then you could query all graphics in your GraphicsLayerView and set the visibility of graphics to false based on your needs. You can do something like this:
view.whenLayerView(graphicsLayer).then(function(layerView){ layerView.queryGraphics().then(function(results){ results.forEach((item)=>{ console.log(graphic?.attributes) if (graphic?.attributes?.Name){ // set your requirement here graphic.visible = false; } }); }); });
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.