Selecting Graphics

Discussion created by jdpeck on Dec 10, 2010
Latest reply on Dec 13, 2010 by vtammineni
I need to draw various graphics onto my map:  circles, lines, points, etc.  I also need to know when a user clicks on one of these graphics so my code can do some other work.  My question to those of you who are experienced is:  what is the best way to do this?

Right now I create Elements and add them to a GraphicsContainer.  I use the ElementProperties interface to store a unique ID number in their CustomProperty fields.  In my map events listener, when a user clicks, I use LocateElements to find any Elements at that point and then dig out their IDs so I know what I have.

That seems like a terrible hack to me.  Plus I have issues when one element is on top of another.  I've considered using the built in "Select Elements" tool.  It highlights and adds handles to the graphic which I don't want, but I can listen for OnSelectionChanged and call UnselectAllElements to get rid of them.  I need to know whenever a user clicks, so I'd have to make this tool active at all times, unless some other tool like pan or zoom is being used.

I've also thought about adding these graphics as Features instead of Elements but I do not have a geodatabase and I can't find any easy way to create Features without one.  Also, I don't know if it's worth it.

What I'd really like is an element event listener that will let me execute some of my own code whenever the element is clicked.  Is there something like that out there that my endless Googling hasn't found?  How would you do it?

Thanks for any help.