Query FeatureLayer with Definition Expression

4484
3
Jump to solution
05-23-2019 06:31 AM
JeremyLyman
New Contributor II

I'm trying to run a queryExtent() on a FeatureLayer that has a Definition Expression applied, but it seems to ignore the Definition Expression when query.where is given. I'm trying to zoom to the selected states, but not AK/HI because there are inset maps for those.

var mydefinitionExpression = makeStateQuery();
const layer = new FeatureLayer({
 url: url,
 definitionExpression: mydefinitionExpression,
});

layer.when(function(){
   var query = layer.createQuery();
   query.where = "(StateFIPSN <> 02 AND StateFIPSN <> 15)";
   return layer.queryExtent(query);
})
.then(function(response){
   view.goTo({
      target:response.extent,
      duration:500
   });
});

It seems like I should be able to use both where and defEx, but the extent returned indicates that it's one or the other.  Am I missing something?

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

Sounds like you want to get the query object from the createQuery() method of the layer to honor its current configuration.

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

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus

Jeremy,

   This sample shows how it is done. You need to combine the where SQL and definition Expression SQL into either the query where or the layer definition Expression before querying.

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=featurelayer-q...

ReneRubalcava
Frequent Contributor

Sounds like you want to get the query object from the createQuery() method of the layer to honor its current configuration.

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

JeremyLyman
New Contributor II

Okay, yes inspecting the object returned from createQuery() at runtime reveals it already contains the string used by the Definition Query.  So setting the where property does indeed overwrite the previous requirement.  I'll just have to combine the two together.  A little disappointing, I'd hoped it worked more like definition expressions in ArcMap.

Thanks for your insights!

0 Kudos