feature layer geometry filter

Discussion created by sohnem2 on Nov 24, 2013
Latest reply on Nov 25, 2013 by sohnem2
Doing somethign like (below):

selectionToolbar = new esri.toolbars.Draw(map);

dojo.connect(selectionToolbar, "onDrawEnd", function (geometry) {

   var query = new gQuery();
   query.outFields = outfieldsList;
   if (whereClause) query.where = whereClause;

   query.geometry = geometry;
   query.returnGeometry = true;
   query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
   query.outSpatialReference = featureLayer.spatialReference;

   featureLayer.queryFeatures(query, function (featureSet) {


It's filtering by the geometry as I can see by inspecting featureSet.features list but the features being show on the map is not corresponding to the features that are being returned by the query.
If I put in featureLayer.clear() before calling the query, all features are removed from the map.

The funny thing is when I  query with a where clause but without the user of geometry filter, then what is returned from teh query is reflected on the map.  Why might filtering by where clause and by geomotry be different in terms of not what the result of the query would be but in terms of what is shown on the map?

It seems that the reason this is occuring is that the featurelayer has its where expression set by:
so that once the where clause is set, it is applied to the feature layer and whenever it gets refreshed, the where caluse applies.
But the geometry field is applied only to the query object and does not become part of the featurelayer.
So even if the query returns with geometry filter applied, it seems that the featurelayer gets refreshed without the geometry.

Is there a way to apply the geometry at the featurelayer level like the where expression?

Or can I remove the features from the featurelayer based on the query results? Will it get overwritten if the featurelayer redraws itself, like when the map is panned?

Or should I not add the featurelayer to the map itself and handle the graphics myself by addiing it to the map after a query? And clear the map graphics before each query? Is there a performance hit with this method? Since I am using the ON_DEMAND mode with the featurelayer.

Please advise as this is urgent, and I am sort of new to the J API.