Select to view content in your preferred language

Selection Of Multiple Graphics In Layer

938
5
05-18-2010 02:27 PM
HeavyWoody
Emerging Contributor
I am creating a graphics layer at runtime from code behind.  What I really would like to do is allow the user to use like the Query piece where you can draw a bounding box (or rubberband), and then be able to loop through the graphics layer and check to see which graphic items fell into the area that was drawn.  I see demos on Feature Services doing this, but like I said, I building a graphics layer at runtime so I cannot do it like that.

Is this possible?  If so, how?
0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor
The Editing class in v2.0 fully supports selection on GraphicsLayer, as long as the selectionmode is point or rectangle. Only if you need to select by polyline or polygon does it have to be a FeatureLayer.
Links:
http://help.arcgis.com/en/webapi/silverlight/apiref/topic238.html
http://help.arcgis.com/en/webapi/silverlight/apiref/topic214.html
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave

You could also go more low-level and use the FindGraphicsInHostCoordinates method which is also supported in v1.2:
http://help.arcgis.com/en/webapi/silverlight/apiref/topic487.html
0 Kudos
AlexAgranov
Emerging Contributor
I made this work in WPF, however at the cost of the ability to navigate the map in NWSE by dragging it. I intercept the Map-->MouseDown event to activate the Editor.Select command but it prevents navigation. In order to keep default navigation in place, I'd have to move activate the select command from another button or toolbar.
0 Kudos
JenniferNery
Esri Regular Contributor
The Editor supports GraphicsLayer too, you can look at this sample for guide:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave. Look at the "Select" buttons.

The only thing you will need to do is when you create your GraphicsLayer, give it an ID. The Editor ignores layers that do not have IDs. Also you can set Editor's Map property but leave its LayerIDs alone, you don't need to specify this if your layers will be added at runtime and you do not have this information yet. Setting the Map property is sufficient.
0 Kudos
AlexAgranov
Emerging Contributor
What if I don't want to use Editor for multiple selection. Let's say I subscribe to Graphic.MouseLeftButtonUp event and call Graphic.Select(). For some reason the graphics layer will only remember the last selection. How do I enable multiple select on a graphics layer so it doesn't do that?
0 Kudos
dotMorten_esri
Esri Notable Contributor
The Editor actually does what you are doing (although it used the Draw object, and it's the draw object that prevents navigation), so it is possible to do with intercepting events. I'm not sure how you would NOT disable map navigation while drawing on the map. Doing both at same time would be really confusing. Either you draw on the map, or you navigate the map.
0 Kudos