Hi,
Version 3.17.
We surprised that FeatureLayer selectFeatures() method does not return "features" and "method" - just Array of objects.
And help is not correct
FeatureLayer | API Reference | ArcGIS API for JavaScript 3.18
That means there is a difference to use QueryTask.execute() or FeatureLayer.selectFeatures().
Should we use 3.18?
Any help please.
Solved! Go to Solution.
Piterson,
That was in my very first reply:
censusBlockPointsLayer.on("selection-complete", function(evt) {
console.info(evt);
....
Piterson,
Not sure how your code is handling the FeatureLayer.selectFeatures but this sample does return feature and method just fine (I just added a console.info(evt)):
ArcGIS API for JavaScript Sandbox
censusBlockPointsLayer.on("selection-complete", function(evt) {
console.info(evt);
....
Robert,
Thank you for the response.
I see.
Please try this
censusBlockPointsLayer.on("selection-complete", function(evt) {
var query = new Query();
query.outFields = ["*"];
query.where = "OBJECTID < 5";
censusBlockPointsLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (featureSet) {
console.info(featureSet);
});
//console.info(evt);
var totalPopulation = sumPopulation(censusBlockPointsLayer.getSelectedFeatures());
var r = "";
r = "<b>The total Census Block population within the drive time polygon is <i>" + totalPopulation + "</i>.</b>";
dom.byId('messages').innerHTML = r;
});
What is the point in doing a selection inside the response of another selection. Also by adding that, you would be creating an infinite loop in your code, because you are executing a selection inside the selection complete handler event.
You are right.
Could we do it in
function initFunctionality() {
var query2 = new Query();
query2.outFields = ["*"];
query2.where = "OBJECTID < 5";
censusBlockPointsLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW, function (featureSet) {
console.info(featureSet);
});
...
};
The print in console is the same: Array of Objects
Piterson,
OK the difference is that you are using an inline deferred handler verses an on event deferred handler and the return is different by design for these. When you do a inline handler like you are the returned result is only an array of graphics as you would already have access to the selection method.
Robert,
This makes sense.
Could you please provide an example when we get "features" and "method" from selectFeatures()?
Piterson,
That was in my very first reply:
censusBlockPointsLayer.on("selection-complete", function(evt) {
console.info(evt);
....
Many Thanks, Robert.