FeatureLayer selectFeatures does not return "features" and "method"

2152
8
Jump to solution
12-12-2016 04:59 PM
PitersonPaulgek
New Contributor III

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.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Piterson,

  That was in my very first reply:

        censusBlockPointsLayer.on("selection-complete", function(evt) {
          console.info(evt);
          ....

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

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);
          ....

0 Kudos
PitersonPaulgek
New Contributor III

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;
});

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
PitersonPaulgek
New Contributor III

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
PitersonPaulgek
New Contributor III

Robert,

This makes sense. 

Could you please provide an example when we get "features" and "method" from selectFeatures()?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

  That was in my very first reply:

        censusBlockPointsLayer.on("selection-complete", function(evt) {
          console.info(evt);
          ....
PitersonPaulgek
New Contributor III

Many Thanks, Robert.

0 Kudos