Proper way to enable mouse events on PolygonGeometry?

Nov 15, 2011 at 7:04 PM

Hello everyone,

I've looked through the discussions, but I wasn't able to find an answer for this :( My problem is explained below.

For various reasons I'm generating a number of polygonGeometries and I'm placing those geometries on my map (unavoidable requirement, since they are drawn using coordinate data from a database), using:


This procedure works perfectly, as all items are properly generated and placed on the map. I also need however that the generated polygons respond to mouse click and MouseEnter/MouseLeave events.

I wasn't able to find any way to attach the events to the PolygonGeometry objects or to the Worldgeometry objects, so after digging a bit in the documentation, I found this procedure to enable events over the map: 

Host.CommunicationManager.AttachToEvent(EngineEvents.Group, EngineEvents.OnMouseDown,"MouseDown",MouseDown);

Although this approach works and I can indeed trigger events over the map, I don't feel this should be the proper way, since the "listener" for those events aren't the objects, but the globe it self. So, on the handler object from the event I get a set of data that lets me know what was clicked (shapeId, layerId) and where (latitude, longitude), among other things,  forcing me to implement all sorts of ways to figure out which polygon (if any) was the target for the event and only then perform the desired action.

In a nutshell, when the event is raised, all I get is general information about what was clicked, I then have to fetch the object in order to perform whatever actions I need for a given event.

So, in spite of everythting is working, I can't help the feeling that I'm overcomplicating something that should be simpler.

So, I decided to approach this discussion and ask you guys:

-What is the proper way to enable/attach mouse events on PolygonGeometry?

And for a bonus question:

-Am I using the proper procedure to create the PolygonGeometries?

Thanks in advance for helping and I'm sorry for any misspellings (english is my third language),