Select to view content in your preferred language

Definition Expression Issue

453
2
Jump to solution
08-09-2023 10:41 AM
AndrewMurdoch1
Occasional Contributor II

Good Day

I'm using "@arcgis/core": "4.27.6"


I think I found a bug in the querying logic when setting a definition expression (DE).  Assume I have a layer and I set the DE to 'a = 1 OR a =2', and two of the X features are now shown.

If I run another query on the map: 'a = 3', and get back a feature / geometry, why is the visible flag still true when the feature isn't visible?  Should I be able to use a DE as a first pass filter that's constant, and then on top of that apply more filters using queries? 

This is a code sample of what I'm doing:

Definition Expression Stage, assume query: 'a = 1 OR a = 2':

 

 

this._view?.map?.layers?.forEach((layer) => {
  if (layer?.type === 'feature' && !layer?.id.includes('meta-')) {
    layer.definitionExpression = query;
  }
}

 

 


Running the second query, assume mapQuery is: 'a = 3':

 

 

const query = {
  where: mapQuery,
  outFields: ['*'],
  returnGeometry: true
}

const visibleFeatures: Graphic[] = [];
this._view.when(() => {
  this._view.map.layers.forEach((layer) => {
    if (layer.type === 'feature') {
      layer.queryFeatures(query).then((queryRes) => {
        queryRes.features?.forEach((feature) => {
          if (feature.visible) {
            visibleFeatures.push(feature);
          }
        })

        r(visibleFeatures);
       }).catch((error) => {
         console.log(error);
         j(error);
       })
     }
   })
})

 

 

 
When I look for anything but a 1 or 2, they aren't visible on the map, so that flag shouldn't be set.

Thanks

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

The visible property for graphics that come from a FeatureLayer is pretty much meaningless; it's really only useful for graphics in GraphicsLayers.

Your query is also being sent to the service to be executed, and it returns all features that match.  Because the conditions of the DE are not included, it therefore returns features 1 and 2 also.  If you want the conditions of the DE to be included, you should use createQuery, and then modify the where clause with the additional conditions.

Alternatively, if you just want to query the layer on the client side, which will honor your DE, then you can use queryFeatures on the layer's LayerView.

View solution in original post

2 Replies
JoelBennett
MVP Regular Contributor

The visible property for graphics that come from a FeatureLayer is pretty much meaningless; it's really only useful for graphics in GraphicsLayers.

Your query is also being sent to the service to be executed, and it returns all features that match.  Because the conditions of the DE are not included, it therefore returns features 1 and 2 also.  If you want the conditions of the DE to be included, you should use createQuery, and then modify the where clause with the additional conditions.

Alternatively, if you just want to query the layer on the client side, which will honor your DE, then you can use queryFeatures on the layer's LayerView.

AndrewMurdoch1
Occasional Contributor II

Thanks! That did exactly what I wanted 🙂

0 Kudos