Search code examples
c#arcgis

Executing function based on pointer location


I am working with ArcGIS SDK for dot net. I am programming using vc#. I want to execute a piece of code as soon as the mouse pointer enters a particular longitude/latitude on map or if mouse is clicked on that location. there are many event handlers but I don't know how to retrieve the location the mouse pointer is at. e.g I want to display some picture as soon as mouse pointer is at longitude 25 and lat 33.


Solution

    1. Add a MouseMove listener to your MapView.
    2. Your listener method will have a parameter of type MouseEventArgs. Call GetPosition(null) on that parameter to get the screen point.
    3. Use MapView.ScreenToLocation(Point) to get the MapPoint in map coordinates.
    4. If your map isn't in longitude/latitude, use GeometryEngine.Project(Geometry, SpatialReference.Create(4326)) to convert to longitude/latitude.
    5. Check the longitude and latitude to see if they're in the range you want.

    I tried posting my source code here but Stack Overflow gave me an error, so here it is as a screenshot:

    enter image description here