Hi, I cannot figure out how to get feature in a layer or layerview from objectid directly, some function like "layerView.getFeatureById(objectid)". I store the objectids in array but I don't know how to get the features back later. Could you help me, thanks!
Solved! Go to Solution.
Hi @Lazyman ,
There is a method named queryFeatures() on many of the layer types where you can pass in a Query object defining a query with the object id you are looking for.
https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html
You'll first need to define a Query and then pass that query as a parameter into queryFeatures(). One thing to look out for is the casing for the ObjectID field can be different depending on the environment hosting the service. So you might want to log out the layers fields or look at the REST enpoint of the service to match the casing for ObjectID. (OBJECTID, ObjectID, etc...)
const query = new Query();
query.where = "OBJECTID = 49"
layer.queryFeatures(query).then((results) => {
console.log(results.features);
});
Hi @Lazyman ,
There is a method named queryFeatures() on many of the layer types where you can pass in a Query object defining a query with the object id you are looking for.
https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-Query.html
You'll first need to define a Query and then pass that query as a parameter into queryFeatures(). One thing to look out for is the casing for the ObjectID field can be different depending on the environment hosting the service. So you might want to log out the layers fields or look at the REST enpoint of the service to match the casing for ObjectID. (OBJECTID, ObjectID, etc...)
const query = new Query();
query.where = "OBJECTID = 49"
layer.queryFeatures(query).then((results) => {
console.log(results.features);
});
Everything said here is accurate, but the nuances of the OID field name can be avoided by using query.objectIds instead of query.where.
Thank you both!