Querying a Feature Layer doesn't work

92
1
05-01-2019 11:56 AM
Kevin_C
New Contributor III

I'm following along with this tutorial for Querying a feature layer using the ArcGIS JavaScript API, but using my own layer. 

I am trying to query all features within the layer that have a value of 3 in the field called "mag". I'm supposed to get the length of the features in the query result when I console.log. This should not be 0.

But I am getting a result of 0, implying that I didn't get the query correct. What should my query statement query.where = "mag = 3"; be changed to here? 

var query = new Query();
query.where = "mag = 3";
query.outfields = ["*"];
query.returnGeometry = true;

var queryTask = new QueryTask({
url: "https://services5.arcgis.com/.../arcgis/rest/services/datalayer/FeatureServer"
});

queryTask.execute(query)
.then(function(result) {
console.log(result.features.length)
})
.otherwise(function(e) {
console.log(e);
})

 

Thanks!

0 Kudos
1 Reply
Kevin_C
New Contributor III

Solved it. Turns out I was using the url for Feature Service. Not the layer itself. Fixing the url works.

0 Kudos