feature layer geometry filter

2989
5
11-24-2013 09:38 PM
EdwardSohn1
New Contributor
Doing somethign like (below):

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

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

   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:
setDefinitionExpression()
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.

Thanks.
0 Kudos
5 Replies
EdwardSohn1
New Contributor
Doing somethign like (below):

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

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

   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:
setDefinitionExpression()
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.

Thanks.
0 Kudos
JohnathanBarclay
Occasional Contributor
When you first define the feature layer, add the property:

mode: FeatureLayer.MODE_SELECTION

Then when querying by geometry, don't use
featureLayer.queryFeatures(query, function(){

use this instead
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(){


Only selected features will be displayed on the map.
EdwardSohn1
New Contributor
When you first define the feature layer, add the property:

mode: FeatureLayer.MODE_SELECTION

Then when querying by geometry, don't use
featureLayer.queryFeatures(query, function(){

use this instead
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(){


Only selected features will be displayed on the map.


Ok will try that.
Will this affect my initial query before applying the geometry?
Initially I retrieve all features and show them on the map with no filters applied.  Also user may choose to apply filters which get sent via the where clause without the geometry filtering...  I assume those functionalities will not get affected...
Also will there be any performance hit: initially I was using ON_DEMAND mode for that reason.  Will switching to MODE_SELECTION cause performance hit possibly?
0 Kudos
EdwardSohn1
New Contributor
Ok, so I tried MODE_SELECTION and selectFeatures isntead of queryFeatures and it works with respect to geometry filter in the query.
But now all of the features show up as selected.
I guess I can change the select symbology to make it same as unselected symbology to work around this.

But now the other code which selects a feature based on the datagrid row selected and also when user clicks on a feature may not work.  Shoudl I convert these other code to do the reverse, i.e. to unselect the feature?  But then will they disappear from the layer?  Is there another state I can use to indicate user has selected them.  I.e. I want to use the result of selectFeatures function call as normal unselected state so that the geometry filter works, and then use another state to actually indicate user selection of the features...

Is there some other way to do these things?
Thanks, this is sort of urgent and I am relatively new to Javascript API.
0 Kudos
EdwardSohn1
New Contributor
So what I eneded up doing was to use selectFeatures instead of queryFeatures, and pass in the geometry by the query object.
But I also had to change the select symbology to that of normal symbols so that the features didn't show up selected.
Also I had to turn off all instances where I select a feature or clear selections of the feature layer, so that the queried features stay visible on the layer.

There was one case where I had to artificially induce a selected state for a feature (when user selects the corresponding row in the datagrid), but changing the feature sysmbology rather than actually selecting that feature.

I suppose there may be other ways of doing thigs, but due to time constraints just going with this implementation for the time being.
Perhaps other methods are avaialble?  Such as not addding the feature layer to the map and actually manually adding the graphic to the map?  Tried that first but it generated too many sideeffect errors with info window and maptips which were associated with the featurelayer previously.  I suppose it may be possible to redo those based on the map and the graphics on it instead.

Please post any other suggestions or methods.
Just learning this stuff- new to the API...
0 Kudos