8

I am trying to select a group of features in an ESRI javascript API featureLayer by attribute. The call errors out. My code is as follows. Here is the layer definition:

 var fieldDefs = [{
 "name": "county",
 "type": "esriFieldTypeString",
 "alias": "county"
 },
 {
 "name": "pop",
 "type": "esriFieldTypeInteger",
 "alias": "pop"
 },
 "name": "ObjectID",
 "alias": "ObjectID",
 "type": "esriFieldTypeOID"
 }
 ];
 var featureCollection = {
 "layerDefinition": null,
 "featureSet": {
 "features": [],
 "geometryType": "esriGeometryPolygon";
 }
 };
 var featureCollection.layerDefinition = {
 "geometryType": "esriGeometryPolygon";,
 "objectIdField": "ObjectID",
 "drawingInfo": {
 "renderer": {
 "type": "simple",
 "symbol": symbol
 }
 },
 "fields": fieldDefs
 };
 var featureLayer = new FeatureLayer(featureCollection, {
 id: idString,
 mode: FeatureLayer.MODE_SNAPSHOT,
 fields: fieldDefs
 });

I then populate the layer using applyEdits and later query the layer using this function:

queryCounty = function(county_name) {
 var query = new Query();
 query.where = "county = '" + county_name + "'";
 //projectsOverlayMap.clearSelection();
 console.log("WHERE: " + "county = '" + county_name + "'");
 projectsOverlayMap.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
 alert(results.length);
 });

And calling it like this:

queryCounty("Jefferson");

When I do that I get the following error:

"Error: FeatureLayer::selectFeatures - query contains one or more unsupported parameters

There are some decent on line examples of this function using geometry queries but none that I have found that use and attribute query. What am I missing?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 3, 2015 at 7:36
1

2 Answers 2

3

Are you creating featurelayer by FeatureLayer(featureCollectionObject, options?)?

If yes there are some restriction for the featurelayer object. You cannot execute queries on such layers.

See the docs https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#featurelayer2

answered Nov 3, 2015 at 10:46
2
  • The doc says "Does not support queries that need to be performed on the server" since I'm in snapshot mode, everything is persisting on the client, right? All the features are loaded in with attributes already, there is no serverside component. Commented Nov 3, 2015 at 15:53
  • 1
    I thinks the query with where will work only with feature layer that has from server.Refer the thread geonet.esri.com/thread/14137 For testing try to execute the query with objectid Commented Nov 4, 2015 at 9:47
1

It's clunky but you can query on the extent of the map and then loop through the results to get the attributes you want. For example:

require(['esri/tasks/query', 'esri/layers/FeatureLayer'], function (Query, FeatureLayer) {
 var query = new Query();
 query.geometry = projectsOverlayMap.extent;
 featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (results) {
 for(var key in results) {
 if(results[key].attributes['county'] === county_name) {
 ... do something ...
 }
 }
 });
}
answered Jun 2, 2016 at 20:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.