Select to view content in your preferred language

Get list of graphics under a mouse defined region

3115
2
01-29-2015 09:42 AM
EdwardSohn2
New Contributor III

Need to get the list of graphics that lie under a region/geometry defined by mouse action (such as click-drag draw, or a simple left mouse click) and then use this list of graphics to select it and retrieve its list of attributes.

The graphics are already defined on the graphicslayer, and do not want to query the backend again.

What is the best way to do this?

0 Kudos
2 Replies
JoshHevenor
Occasional Contributor II

Graphics often have their attributes embedded. If there's a template defined on the graphic then a click can trigger a popup infoWindow to display those attributes.

A graphics layer has a number of events (click, mouse-move) that can be used to highlight the relevant graphics in a layer as well. Depending on what you want to do those might help. Sticking to click-popup is the easiest path.

OwenEarley
Regular Contributor

As your graphics are already within a GraphicsLayer you have access to the click event to handle mouse click events. This will allow you to handle the simple left mouse click scenario.

The region selection would require a different approach. Firstly, you would need to capture your region shape using something like the map mouse-down and mouse-drag-end events or alternatively use the draw toolbar to create a graphic.

When you have a selection extent you can then loop through all of the graphics in your graphics layer and test which ones intersect your selection graphic using the extent.contains() method.

This sample shows using the draw toolbar to capture the selection extent.

0 Kudos