Map Mouse Click and Draw

1899
2
10-14-2010 05:37 AM
JamesStreet1
New Contributor
I am trying to reproduce some code in Silverlight that I originally wrote in the Flex API. Basically I am drawing a polyline on the map and need to capture the coordinate of each mouse click as I create the line.

The approach I have taken is to add an event handler to the map mouse click and then capture each map click coordinate as I'm drawing. The problem is that this event seems to get disabled as soon as the draw object is enabled and therefore the event handler never gets fired. I am also using the map's mouse move event which does not seem to get affected the same way by the draw object. This was not the case in Flex so I'm wondering whether this is intentional and if anyone has any suggestions on how to tackle this. I did look at the events on the draw class to see if there was anything there I could use but didn't see anything that would work.

Any suggestions would be appreciated.

James
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
You can use MouseLeftButtonDown on the map and get the MapPoint this way:
  void MyMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
   Point screenPoint = e.GetPosition(MyMap);
   MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);
  }


You can also use VertexAdded on the draw object and get the MapPoint this way:
  void MyDrawObject_VertexAdded(object sender, VertexAddedEventArgs e)
  {
   MapPoint mapPoint = e.Vertex; 
  }


MouseClick is not raised when Draw is enabled is by design.
0 Kudos
dotMorten_esri
Esri Notable Contributor
The draw object also has an event that gets fired each time a vertex is added that you can use instead.
0 Kudos