I can get the current cursor position inside a Map Tool as follows:
protected override async Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e) { // Get cursor point MapPoint mapPoint = await QueuedTask.Run(() => { return ActiveMapView.ClientToMap(e.ClientPoint); }); }
However, I would like to get the cursor position outside of a MapTool. Does anyone know how to handle this? I've already posted another question: https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-catch-event-when-z-changes/m-p/1339114#M10565
Thanks,Barbara
Hi Barbara,
As illustrated by your current implementation, the ArcGIS Pro SDK provides you with the MapTool to give you access to the necessary context / information to create a MapPoint based on the position of the mouse within the MapView.
Beyond the scope of the Pro API, you could use the Windows API but will have to manage all the scenarios and conversions yourself.
I found a solution to the problem:
I declare an internal class member variable (CursorPoint) inside my MapTool which I can access from outside:
internal class ToolAddRasterPoint : MapTool { internal MapPoint CursorPoint{ get; set; } public ToolAddRasterPoint() { IsSketchTool = true; UseSnapping = false; SketchType = SketchGeometryType.Point; MyModule.ToolAddRasterPoint = this; // to access from outside } protected override async void OnToolMouseMove(MapViewMouseEventArgs e) { await QueuedTask.Run(() => { CursorPoint = MapView.Active.ClientToMap(e.ClientPoint); }); } }
@BarbaraSchneider2 ,
could you elaborate some more on what you're trying to achieve and what context you would be in?
Hi Selim,
I want to do the following:
1. The user clicks on a keyboard shortcut
2. This keyboard shortcut is linked to a command, in which I programmatically get the current cursor position and create a MapPoint
Within a map tool, this looks as follows:
2. This keyboard shortcut is linked to a command, in which I programmatically activate a MapTool
3. The user has to click again on the Stereo Map to get the cursor position
--> This is one click more. The users of my applications perform these steps about 500 times a day, so these are 500 clicks more...
This is the code to get the cursor position (x, y, and z) using the Windows API:
System.Drawing.Point cursorPoint = System.Windows.Forms.Cursor.Position; System.Windows.Point screenPoint = new System.Windows.Point(cursorPoint.X, cursorPoint.Y); var mapPoint = await QueuedTask.Run(() => { // Convert to map position return MapView.Active.ScreenToMap(screenPoint); });
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.