Select to view content in your preferred language

How to create a halo around the mouse cursor

2994
8
Jump to solution
02-22-2022 11:23 AM
DaveLewis73
Regular Contributor

I am looking for a way to create a ring or halo around the mouse cursor.  I created this functionality in ArcGIS Desktop using ArcObjects, but now I need to port it over to ArcGIS Pro with WPF.  I know that I could do this using a Map Tool, but I need the halo to persist and not be tied just to when a single tool is active.  With that being said, before I tackle the ring/halo portion of the task, I need a way to get the mouse cursor coordinates as it passes over the active map frame.  I am looking into MouseEventArgs, which is what I used in ArcGIS Desktop.  However, I can't get this to work in Pro.  Is there anything in the ArcGIS Pro SDK like ArcMap.Document.CurrentLocation or some other way of getting the mouse cursor location on mouse move? Any assistance would be greatly appreciated. 

0 Kudos
1 Solution

Accepted Solutions
John_Jones
Regular Contributor

You will likely have some success following approaches similar to described here... https://stackoverflow.com/questions/4226740/how-do-i-get-the-current-mouse-screen-coordinates-in-wpf  the API we provide is focused on helping users develop their own commands and tools to add to ArcGIS Pro. The API doesn't directly correspond to providing extensibility points specifically to plug in functionality to existing commands and tools (as that is much harder to provide stability for as the internals of existing tools change for various reasons), but that doesn't mean facilities doing so don't exist, they just aren't particularly supported.

View solution in original post

8 Replies
John_Jones
Regular Contributor

I'm not sure how easy this is to accomplish in 2.9, but we did install an easier way of accomplishing this for the next version of Pro (due out this Spring / Summer) as we noted that we had internal support for this but it wasn't part of the Public API.

The new API on MapTool will include a both a string property (SketchTip) which can be set to show a simple string, using some default font settings, next to the cursor and another property specifying a DAML ID of a registered EmbeddableControl which will enable you to have an arbitrary WPF UserControl on the cursor (which should work well for your case of drawing a halo around the cursor).

As you probably want to get results on current version reading the current mouse position is also on the MapViewMouseEventArgs given to your MapTool.OnToolMouseMove override (on the ClientPoint property https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic10058.html ) .

Drawing WPF content on top of the MapView can be a little tricky but the API https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic17211.html is helpful in making it work.  (The upcoming new API enhancement is being provided to make this all a bit easier for common workflows as yours).  

0 Kudos
DaveLewis73
Regular Contributor

John,

Thank you for your response.  It is good to know that the API will be expanded in the future to make it easier to accomplish my task.  However, it appears that the future and current methods of doing this all require the use of a MapTool.  This is something that I cannot do, since I need to be able to toggle the halos on and off and work in concert with other tools.  I need to associate this with a simple button click and not a MapTool.  Is there any way to do this outside of the aforementioned MapTool?  For example, I used the Windows API with a MouseHook in ArcGIS Desktop.  This exposed a mouse move event for me that worked perfectly.  I was then able to draw my halos around the current mouse point.  Unfortunately, however, I have tried this in ArcGIS Pro and I can't seem to get it to work.  Please let me know if further information is required.

0 Kudos
DaveLewis73
Regular Contributor

John,

I was noticing that there is an X/Y coordinate function that appears at the bottom of the map frame.  This is getting the current mouse coordinates and is clearly not a MapTool.  How is this accomplished?  Could this be a solution to my problem?

0 Kudos
John_Jones
Regular Contributor

You will likely have some success following approaches similar to described here... https://stackoverflow.com/questions/4226740/how-do-i-get-the-current-mouse-screen-coordinates-in-wpf  the API we provide is focused on helping users develop their own commands and tools to add to ArcGIS Pro. The API doesn't directly correspond to providing extensibility points specifically to plug in functionality to existing commands and tools (as that is much harder to provide stability for as the internals of existing tools change for various reasons), but that doesn't mean facilities doing so don't exist, they just aren't particularly supported.

DaveLewis73
Regular Contributor

Thank you John.  I was able to get the current X/Y location of the mouse by getting the System.Windows.Forms.Control.MousePosition and then casting it into MapView.Active.ClientToMap.  That worked and gave me latitude and longitude, which is what I want.  The only problem is that it works all over the screen, including all windows (not just the map frame).  Do you know how I can determine when I am over the map frame only, not any other window on the screen?  Additionally, I realize this might be putting the cart before the horse, but I was wondering if there is a Pro version of the IGraphicTracker or something similar?  I used this in the Desktop version of my code to keep track of my halo graphics.

0 Kudos
ChadPaul3000
New Contributor

Hi Dave,

Do you mind posting your Halos snippet.  I'm attempting to do something similar in Visual Studio 2022 with Pro 3.0.

Thanks,

Chad

0 Kudos
DaveLewis73
Regular Contributor

Chad,

Sorry for the late reply, but I have been on vacation and just saw this.  Unfortunately, the code for the distance halo is much more than a snippet.  It turned out to be pretty extensive to implement everything.  What part of the code would you be interested in specifically?

Thank you,

Dave

0 Kudos
23Starbuck
Emerging Contributor

Did this ever become a tool? ‌  It would be wonderful to have this tool. For example, if you need to drawl in a new line route for a transmission line that has a right-of-way width of 50' (25' left & right of centerline "aka cursor") you can quickly see as you are digitizing point for your line the spacing between your centerline and all objects around you. The tool would give people the ability to see spacing/distance as they are actively digitizing in point, line or area features. This would save so much time on during the feature collection process. An editor would not have to stop and start their editing session every time they needed to check and make sure there is enough space between a house and the transmission their mapping in.

0 Kudos