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?
-
has it got anything to do with gis.stackexchange.com/a/112438/5850vinayan– vinayan2015年11月03日 10:18:13 +00:00Commented Nov 3, 2015 at 10:18
2 Answers 2
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
-
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.Frank Conry– Frank Conry2015年11月03日 15:53:35 +00:00Commented Nov 3, 2015 at 15:53
-
1I 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 objectidShabeerali– Shabeerali2015年11月04日 09:47:52 +00:00Commented Nov 4, 2015 at 9:47
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 ...
}
}
});
}
Explore related questions
See similar questions with these tags.