Select to view content in your preferred language

Does a featureLayer, based on a featureCollection, support query by ObjectID?

1214
4
Jump to solution
02-17-2013 03:19 PM
StephenLead
Honored Contributor
It's possible to create a featureLayer on-the-fly using a featureCollection, as described at http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#FeatureLayer/FeatureLayerConst2, which also mentions:



  • 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



Does this mean that a featureLayer based on a featureCollection will not support featureLayer.queryFeatures based on query.objectIds as in this example?

 var query = new esri.tasks.Query(); query.objectIds = [features[0].attributes.OBJECTID]; query.outFields = [ "*" ]; // Query for the features with the given object ID featureLayer.queryFeatures(query, function(featureSet) { });


I'm seeing sporadic results, with the query sometimes working and sometimes not working. Unfortunately I don't have an easily reproducible piece of code that I can share.

Thanks for any advice,
Steve
0 Kudos
1 Solution

Accepted Solutions
StephenLead
Honored Contributor
I seem to have answered my own question, which is that a featureLayer based on a featureCollection does support query by objectID.

Read on if you're interested in verifying this.....

Sample code here - it's pretty rough, with no error checking, but here's how to demonstrate that it works:

- an empty featureLayer is created when the map loads
- hit the Find button at the top left of the map
- any lakes with a name starting with "LAKE CR%" will be added to the feature layer
- these are shown in pink on the map, and their ObjectIDs are written to the firebug console
- make a note of one of the ObjectIds and enter it into the text box at the top left
- hit the Query ObjectId button and see the results in the console

If you use the Find button again, it deletes the existing features and re-adds new features, which have incremented ObjectIds.

In my other code, I'm finding that in this case the queryFeatures function is not finding the new features (eg where objectId = 14). Since it's working correctly here, my "sporadic" problems must lie elsewhere in my code.

Cheers,
Steve

Update: in my other code, I was only passing a single ObjectID object, rather than an array of [ObjectIds] as required. Strangely, this worked some of the time.

View solution in original post

0 Kudos
4 Replies
RahulMetangale1
Frequent Contributor
Steve,

If you want query to be done on client side then you can directly loop through graphics and find the graphic with the matching object id. How does it matter when you are doing query on the client side if you do it or api does it for you?

-Rahul
0 Kudos
StephenLead
Honored Contributor
Hi Rahul,

Say I have 10,000 features to loop through until I find the right one - I'd assume that running a query by ObjectID would be a lot faster than having to process all of those features, and evaluate each one to check whether it has the right OID.

Thanks,
Steve
0 Kudos
LukePhilips
Deactivated User
Steve,
Can you explain more as to "sporadic results"? I've been working on similar tasks but haven't seen issues (or at least I'm not paying attention if they are happening like you have..).
0 Kudos
StephenLead
Honored Contributor
I seem to have answered my own question, which is that a featureLayer based on a featureCollection does support query by objectID.

Read on if you're interested in verifying this.....

Sample code here - it's pretty rough, with no error checking, but here's how to demonstrate that it works:

- an empty featureLayer is created when the map loads
- hit the Find button at the top left of the map
- any lakes with a name starting with "LAKE CR%" will be added to the feature layer
- these are shown in pink on the map, and their ObjectIDs are written to the firebug console
- make a note of one of the ObjectIds and enter it into the text box at the top left
- hit the Query ObjectId button and see the results in the console

If you use the Find button again, it deletes the existing features and re-adds new features, which have incremented ObjectIds.

In my other code, I'm finding that in this case the queryFeatures function is not finding the new features (eg where objectId = 14). Since it's working correctly here, my "sporadic" problems must lie elsewhere in my code.

Cheers,
Steve

Update: in my other code, I was only passing a single ObjectID object, rather than an array of [ObjectIds] as required. Strangely, this worked some of the time.
0 Kudos