How to use SelectionManager

1901
4
06-05-2018 11:34 PM
MarkTurnbull
New Contributor III

I am building a custom WAB widget that selects features from a third party SOE across a number of predefined layers. I am trying to use the SelectionManager to present the highlighted features on the map and the associated selected records in the attribute table. Reference information about the SelectionManager is scant and I have been using the Select widget to see how I can implement it.

I have the code mostly working except that the highlighted features are not appearing on the map, they are however being selected in the attribute table.

I am using selectionManager.setSelection method passing in the appropriate layerObject, obtained from the appropriate layerInfo from the webmap and an array of Graphic objects for the selected features and these features definitely exist in the layer passed. The service containing the selection layer is a dynamic map service, not a feature service, but the Select tool works fine on this service.

I can't see any code in the Select widget to add the graphic objects to the map, so I assume the SelectionManager handles that, is this correct?

Does anyone have any ideas as to what I might be doing wrong?

Tags (1)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Mark,

I can't see any code in the Select widget to add the graphic objects to the map, so I assume the SelectionManager handles that, is this correct?

Correct. The one thing you will notice is that if the Select widget is configured to allow selecting a layer in a map service (i.e. not a FeatureLayer) then the Select widget will create a FeatureLayer for that layer in the Map Service. You can verify this by putting a breakpoint in the SelectionManager updateSelectionByFeatures method and see that the layer that is passed into the setSelection method is a FeatureLayer not a ArcGISDynamicMapServiceLayer even though your web map does not have a FeatureLayer by default for that map service layer. So if you are passing in a ArcGISDynamicMapServiceLayer and features array to the setSelection method that is likely your issue.

MarkTurnbull
New Contributor III

Hi Robert

Thanks for your reply.

After a large amount of debugging, I worked out that it was because I was creating the Graphic objects using coordinates in a different SpatialReference, even though I was setting the geometry's SR appropriately. It appears the graphic geometries don't reproject if their SR does not match the SR of the GraphicsLayer.

by Anonymous User
Not applicable

Hi Mark,

Wondering if you solved this? I'm experiencing the same thing.

I have a layer in a different spatialRef than the map. Performing a query, I get back the results and pass it into selectionManager.setSelection -- and always get a pointed added near 0,0 (a metres vs dd spatial ref problem).

Did you go to the trouble of reprojecting the graphic before passing it into the setSelection -- or did you figure out another way to handle this?

thanks

0 Kudos
Adri2cPérez_Beneito
Occasional Contributor

Hi Mark,

I developed a custom widget using 'SelectionManager', maybe it will help you..

Best

A.

0 Kudos