queryFeatures does not return if query has no results

1603
2
Jump to solution
01-03-2014 10:43 AM
james-rae
New Contributor III
featureLayer.queryFeatures appears to not execute the callback if there are no features that match the query.

I have modified the following sample to illustrate (JS API 3.8):
http://developers.arcgis.com/en/javascript/samples/fl_paging/

If one replaces the contents of function queryRecordsByPage with the following (obviously without the line numbers):

    1.  var query = new Query();     2.  //query.objectIds = pageInfo.objectIds.slice(begin, end);     3.  query.outFields = ["*"];     4.  query.geometry = featureLayer.fullExtent;     5.  //query.geometry = new esri.geometry.Extent(-1, -1, 1, 1, 4326);      6.  // Query for the records with the given object IDs and populate the grid     7.  featureLayer.queryFeatures(query, function (featureSet) {     8.    updateGrid(featureSet, pageNumber);     9.  });



- updateGrid (line 😎 gets called with the code as it is shown above. This is expected, as our query geometry has points within it.
- when I comment out line 4 and uncomment line 5, updateGrid (line 😎 doesn't get called at all (in this case, no points are within the custom extent).

Is this normal behaviour for featureLayer.queryFeatures?  I was hoping the callback would trigger, returning an empty feature set (so my code can react to the "nothing within this extent" case).
Any feedback is appreciated.  Thanks.
0 Kudos
1 Solution

Accepted Solutions
JonathanUihlein
Esri Regular Contributor
Try this:
query.geometry = new esri.geometry.Extent(-1, -1, 1, 1, new esri.SpatialReference({wkid:4326}));


*edit

According to the documentation, the spatialReference property needs to be a spatialReference object, not a string or integer.

https://developers.arcgis.com/en/javascript/jsapi/extent.html

View solution in original post

0 Kudos
2 Replies
JonathanUihlein
Esri Regular Contributor
Try this:
query.geometry = new esri.geometry.Extent(-1, -1, 1, 1, new esri.SpatialReference({wkid:4326}));


*edit

According to the documentation, the spatialReference property needs to be a spatialReference object, not a string or integer.

https://developers.arcgis.com/en/javascript/jsapi/extent.html
0 Kudos
james-rae
New Contributor III
Beauty.  Thank you Jon. 
I love it when the fix a one-line fix due to something dumb on our end!
0 Kudos