Select to view content in your preferred language

How Command esri:Map mouseclick?

2513
3
07-29-2010 12:55 PM
StefhanCampos
Deactivated User
Hi, i am using MVVM  approach,i need "command mouseclick" to get current
coordinates, anyone know  ?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You would usually use MouseLeftButtonDown event to do this, get the screen point and translate them to the actual map coordinates.

System.Windows.Point screenPoint = args.GetPosition(MyMap);
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = MyMap.ScreenToMap(screenPoint);

You can refer to this blog for Binding EventArgs to a Command http://silverlight-essentials.com/blog/

Jennifer
0 Kudos
DarinaTchountcheva
Frequent Contributor
Try this link:

http://blogs.infosupport.com/blogs/alexb/archive/2010/04/02/silverlight-4-using-the-visualstatemanag...

Read the whole article, the title doesn't say anything about commands, but look at the code.
I have used it, and it worked for me.

Good Luck!
0 Kudos
jonataspovoas
Regular Contributor
You can do this

public MainPage
 {
  InitializeComponent();    
 
  MyMap.MouseLeftButtonDown +=new MouseButtonEventHandler(MapaImpressao_MouseLeftButtonDown);
 }

/* This triggers when the the button is PRESSED! if you want it to Trigger when the user stops
 * holding the button, change Down to Up.
 * Also, if you want that if works if the Right button instead of the left, change Left to Right.
 */
private void MyMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //This shows the coordinates relative to the Root of the application
            MessageBox.Show(string.Format("X: {0}, Y: {1}", e.GetPosition(LayoutRoot).X, e.GetPosition(LayoutRoot).Y));
            //This shows the coordinates relative to the Map of the application
            MessageBox.Show(string.Format("X: {0}, Y: {1}", e.GetPosition(MyMap).X, e.GetPosition(MyMap).Y));
            //changing "MyMap" to any other object on the screen (like an Grid, or Border) will change the Reference of the coordinates
            //This 2 lines bellow will center the point you clicked on the map.
            MapPoint coordinate = new MapPoint(e.GetPosition(MyMap).X, e.GetPosition(MyMap).Y);
            MyMap.PanTo(coordinate);
        }


I hope this is useful xD
0 Kudos