Show mouse coordinates

1492
6
07-16-2020 11:21 PM
VanyaIvanov
Occasional Contributor

How to display mouse cursor coordintes on Scene(not Map)?

I didn't find any code example. I've found how to display coordinates on Map(Show Mouse Coordinates | ArcGIS for Developers ). But it seems it doesn't fit for Scene 

0 Kudos
6 Replies
dotMorten_esri
Esri Frequent Contributor

You can use the Scene.ScreenToBaseSurface method from a MouseMove event: https://developers.arcgis.com/net/latest/wpf/api-reference/html/M_Esri_ArcGISRuntime_UI_Controls_Sce... 

There's also a more accurate ScreenToLocationAsync method that takes data in layers into account, but this is a lot slower and not recommended to be used on a mouse move event.

0 Kudos
VanyaIvanov
Occasional Contributor

could you please give me link to code example? i didnt understand how to use it(

0 Kudos
dotMorten_esri
Esri Frequent Contributor

It's basically identical to the sample you linked to, but with sceneview and the ScreenToBaseSurface method instead of ScreenToLocation.

Comprodigy
New Contributor

Just an FYI that link is no longer working.

0 Kudos
VanyaIvanov
Occasional Contributor

my code sample that works. if somebody is interested in

private async void MySceneView_MouseMove(object sender, MouseEventArgs e)
{

   if (MySceneView.GetCurrentViewpoint(ViewpointType.BoundingGeometry) == null)
   return;

   //get screen coordinates

   System.Windows.Point screenPoint = e.GetPosition(MySceneView);
   ScreenCoordsTextBlock.Text = string.Format("Screen Coords: X = {0}, Y = {1}", screenPoint.X, screenPoint.Y);

   

   //get geographical coordinates

   MapPoint mapPoint = new MapPoint(0,0,0);

   mapPoint = await MySceneView.ScreenToLocationAsync(screenPoint);

   MapCoordsTextBlock.Text = string.Format("Map Coords: X = {0}, Y = {1}, Z = {2}",
   Math.Round(mapPoint.X, 4), Math.Round(mapPoint.Y, 4));

}

0 Kudos
dotMorten_esri
Esri Frequent Contributor

I'd recommend you be very careful with running async code in an event as frequent as mouse-move. The async get location call is actually quite expensive, so it could severely affect rendering performance. I'd recommend using the synchronous ScreenToBaseSurface method instead in this event, and not run the high-accuracy one until after the mouse stopped moving, as well as avoid doing it while SceneView.IsNavigating==true (I doubt it's really that useful while navigating anyway)