Select to view content in your preferred language

FeatureLayer not honoring definition expression

3261
2
07-08-2012 12:33 PM
KeithSandell
Regular Contributor
I have a featureCollection object (not a server resource) that is being successfully added to an app as an esri.layers.FeatureLayer, displaying all features correctly.

I have tried to set the definition expression immediately after creating the FeatureLayer, after adding the FeatureLayer to the map and after an input element (checkbox) onchange event.

The dom shows that the definition expression is being set on the FeatureLayer, but the FeatureLayer will not honor the definition expression, continues to display all features.

***Are FeatureLayers created from featureCollection ( esri.layers.FeatureLayer(featureCollectionObject, options?) ) supposed to honor the definition expression or not?***

countyLayer = new esri.layers.FeatureLayer(counties.featureCollection.layers[0]);
    
countyLayer.setDefinitionExpression("NAME = 'VOLUSIA'");
    
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,255,255,1.0]), 1),new dojo.Color([125,125,125,0.35]));
    
countyLayer.setRenderer(new esri.renderer.SimpleRenderer(symbol));

map.addLayer(countyLayer);
0 Kudos
2 Replies
StephenLead
Honored Contributor
***Are FeatureLayers created from featureCollection ( esri.layers.FeatureLayer(featureCollectionObject, options?) ) supposed to honor the definition expression or not?***


Possibly not. The help file under Feature Layer - feature collection objects says:

Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.
0 Kudos
KeithSandell
Regular Contributor
I did read that, but since a definitionExpression is not specifically utilize a "where" clause similar to a queryTask I thought/hoped perhaps it was different in nature than what the docs may be referring to.

Under the CONSTANTS table the SNAPSHOT mode indicates, " the feature layer retrieves all the features from the associated layer """resource""" and displays them as graphics on the client. Definition expressions and time definitions are honored." I was further hoping that since SNAPSHOT mode referred to resource that it may as well include featureCollection objects and not just server resources.

Further analyzing differences in the help docs I found, "esri.layers.FeatureLayer.MODE_SNAPSHOT: features are fetched from the server based on DefinitionExpression and TimeDefinition. If the definition changes, the layer updates itself by querying features back from the server. Once the features are fetched to the client, their "visibility" on the map is based on the time and spatial extents of the map." Which speaks specifically to server resources and not just general "layer resources" which I would argue to include featureCollection objects since they are the resource that supports the existence of the layer.

So the documentation is not all that clear as to what is what when differentiating between server and featureCollection layer resources.

Guess its time to get hacky, I'll just have to make it do what I want the hard way. Probably have to drop the layer, copy the original featureCollection to a new variable, modify it to match the definitionExpression and then add it back to the display...

Thanks for the second set of eyes.
0 Kudos