FeatureLayer selectFeatures only displays one feature

3891
2
Jump to solution
05-22-2015 06:56 AM
SarahNoakes1
Occasional Contributor II

I am creating a select features tool.  It will work as follows:

  • The user draws a polygon
  • The draw-end event fires a function that runs an identifyTask to query the visible layers (NB. the identifyTask does NOT return the geometry).
  • The callback function from the identifyTask loops through the results set and creates four arrays - a list of the layers, a list of the ids, a list of the geometry types and a corresponding set of HTML tables detailing the feature attributes for that layer
  • The first array is used to create a drop-down list of layers, and when the selection changes, the display changes to display the relevant table.

So far so straightforward.

I also want the selected features to be highlighted when the layer selection is changed.  To achieve this I have:

  • Created a featureLayer (using the id from the array) with the mode set as MODE_SELECTION
  • Set the selection symbol (uses the geometry type array to determine what type of symbol this should be)
  • Created a queryTask using the geometry of the polygon created in the first step
  • Run the selectFeatures method on the featureLayer using the queryTask
  • Added the featureLayer to the map.

However, only the first feature in each layer is highlighted.  Yet if I look at the query results in the browser console I can see multiple results are returned.

What am I missing?

Thanks,

Sarah Noakes

Cornwall Council

0 Kudos
1 Solution

Accepted Solutions
SarahNoakes1
Occasional Contributor II

Hi Sarah,

Thanks for getting back to me.  I've figured it out now - It was to do with how I was creating the FeatureLayer.  I had:

featureLayerSelectManyURL = intranetMapServiceURL + "/" + arrTableIds[0];

featureLayerSelectMany = new FeatureLayer(featureLayerSelectManyURL, {mode: FeatureLayer.MODE_SELECTION});

whereas what I needed was:

featureLayerSelectManyURL = intranetMapServiceURL + "/" + arrTableIds[0];

featureLayerSelectMany = new FeatureLayer(featureLayerSelectManyURL, {mode: FeatureLayer.MODE_SELECTION, outFields: ["*"]});

Goodness only knows why defining the outFields makes as difference - but it does!  Only took the best part of a day ;o)

Cheers,

Sarah.

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

Do you have any code you could share?

I did notice on the API page that for 'MODE_SELECTION' there are specific instructions about adding features:

  1. Call the selectFeatures method.
  2. Listen for the onSelectionComplete event.
  3. Once onSelectionComplete fires, retrieve the selected features using the getSelectedFeatures method.
0 Kudos
SarahNoakes1
Occasional Contributor II

Hi Sarah,

Thanks for getting back to me.  I've figured it out now - It was to do with how I was creating the FeatureLayer.  I had:

featureLayerSelectManyURL = intranetMapServiceURL + "/" + arrTableIds[0];

featureLayerSelectMany = new FeatureLayer(featureLayerSelectManyURL, {mode: FeatureLayer.MODE_SELECTION});

whereas what I needed was:

featureLayerSelectManyURL = intranetMapServiceURL + "/" + arrTableIds[0];

featureLayerSelectMany = new FeatureLayer(featureLayerSelectManyURL, {mode: FeatureLayer.MODE_SELECTION, outFields: ["*"]});

Goodness only knows why defining the outFields makes as difference - but it does!  Only took the best part of a day ;o)

Cheers,

Sarah.

0 Kudos