[GIS] ESRI Javascript FeatureLayer Select by Attributes

arcgis-javascript-apifeature-layerquery

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?

Best Answer

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