Previous project query code won't work now

654
2
12-21-2012 11:07 AM
SteveCole
Frequent Contributor
So here's a weird one. I have a little function to zoom to the extent of a point feature based on the ID provided to the function. In it's original form, the function took the FID as the passed parameter like so:

 function zoomPointRow(id){
  thePointLayer.clearSelection();
  var query = new esri.tasks.Query();
  query.objectIds = [id];
  thePointLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features){
     var thePoint = features[0].geometry;
  var theExtent = pointToExtent(map,thePoint,10);
  map.setExtent(theExtent);
  });
 };


This works fine and worked fine with my current project until I had to change things slightly. In my new project, I'm trying to use this function with a featureLayer that I build on the fly when the map loads (like if you were importing a JSON feed, etc). Instead of using FID, I decided to just alter the query to search for an attribute value associated with the feature like this:

function zoomRow(id){
  theFeatureLayer.clearSelection();
  var query = new esri.tasks.Query();
  query.where = "SENSORID=" + id;
  theFeatureLayer.queryFeatures(query,function(features){
     gagePoint = features[0].geometry;
  theExtent = pointToExtent(map,gagePoint,10);
  map.setExtent(theExtent);
  });
 };


The function is called from the onClick event of an HTML <a> tag. Now, when I click my link to fire off the function, I get the following error in the console: "Error: FeatureLayer::_query - query contains one or more unsupported parameters
http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/esri/layers/FeatureLayer.xd.js
Line 19"

It can't get any more simpler than this so what gives? Unfortunately, the app in development is not on the public side of the firewall..

Thanks!
Steve

[EDIT] I should say that I changed the code from selectFeatures to queryFeatures in attempts to try different things. Both methods return the same error.
0 Kudos
2 Replies
KellyHutchins
Esri Frequent Contributor
Sounds like you are creating a feature collection based feature layer?

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/featurelayer.htm#FeatureLayerConst2

If this is the case queries with a where clause aren't supported. There are a few more things to be aware of - see the following list from the help:

Edits are applied on the client not posted to the server.
The feature layer generates a unique object id for new features.
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.
The feature layer toJson method returns an object with the same properties as the feature collection. The returned object includes all the features that are in the layer when the method is called. This method can be used to access a serializable representation of the features that can be saved on the server.
0 Kudos
SteveCole
Frequent Contributor
Hi Kelly,

Yes- you are correct- it is a layer based on a feature collection. I missed that note in the API reference. So do I have any other options for querying my layer besides objectId?

In my app, the feature collection gets replaced every 5 minutes after a new query to a database so I don't think I can use objectIDs as a viable query tool. I only have 8-12 features (they're stream gages) so I can just loop through the features but I'm just curious what to do if your feature collection has a lot more features in it.

Thanks!
Steve
0 Kudos