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.
Solved! Go to Solution.
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/
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#sour...
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;
}
});
});
});
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/
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#sour...
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;
}
});
});
});