Skip to main content
Post Reopened by PolyGeo
added 1750 characters in body
Source Link
Weequay
  • 101
  • 5

The following is code that I am using that doesn't work. It only functions with pixels.

await QueuedTask.Run(() =>
                {
                    System.Drawing.Point pt = System.Windows.Forms.Control.MousePosition;
                    MapPoint mapPt = MapView.Active.ScreenToMap(new Point(pt.X, pt.Y));
                    double bufferRadius = 100;

                    ArcGIS.Core.Geometry.Polygon poly = CreateHaloPolygon(mapPt, Convert.ToInt32(bufferRadius), out double haloRadius);
                    //_graphics.Add(new GraphicProperties(null, null, polySymRef, poly, lineColor, bufferRadius, bufferInfo[2]));
                    _graphics.Add(new GraphicProperties(null, null, polySymRef, poly, lineColor, haloRadius, bufferInfo[2]));
                });

private ArcGIS.Core.Geometry.Polygon CreateHaloPolygon(MapPoint mapPoint, int pixels, out double radius)
    {
        // Get the halo radius
        Point screenPoint = MapView.Active.MapToScreen(mapPoint);
        Point radiusScreenPoint = new Point((screenPoint.X + pixels), screenPoint.Y);
        MapPoint radiusMapPoint = MapView.Active.ScreenToMap(radiusScreenPoint);
        radius = GeometryEngine.Instance.Distance(mapPoint, radiusMapPoint);

        // Build a circle geometry
        Coordinate2D coord2D = new Coordinate2D(mapPoint);
        EllipticArcSegment arcSegment = EllipticArcBuilder.CreateEllipticArcSegment(coord2D, radius, esriArcOrientation.esriArcClockwise, MapView.Active.Map.SpatialReference);
        PolygonBuilder polyBuilder = new PolygonBuilder(new[] { arcSegment });

        return polyBuilder.ToGeometry();
    }

The following is code that I am using that doesn't work. It only functions with pixels.

await QueuedTask.Run(() =>
                {
                    System.Drawing.Point pt = System.Windows.Forms.Control.MousePosition;
                    MapPoint mapPt = MapView.Active.ScreenToMap(new Point(pt.X, pt.Y));
                    double bufferRadius = 100;

                    ArcGIS.Core.Geometry.Polygon poly = CreateHaloPolygon(mapPt, Convert.ToInt32(bufferRadius), out double haloRadius);
                    //_graphics.Add(new GraphicProperties(null, null, polySymRef, poly, lineColor, bufferRadius, bufferInfo[2]));
                    _graphics.Add(new GraphicProperties(null, null, polySymRef, poly, lineColor, haloRadius, bufferInfo[2]));
                });

private ArcGIS.Core.Geometry.Polygon CreateHaloPolygon(MapPoint mapPoint, int pixels, out double radius)
    {
        // Get the halo radius
        Point screenPoint = MapView.Active.MapToScreen(mapPoint);
        Point radiusScreenPoint = new Point((screenPoint.X + pixels), screenPoint.Y);
        MapPoint radiusMapPoint = MapView.Active.ScreenToMap(radiusScreenPoint);
        radius = GeometryEngine.Instance.Distance(mapPoint, radiusMapPoint);

        // Build a circle geometry
        Coordinate2D coord2D = new Coordinate2D(mapPoint);
        EllipticArcSegment arcSegment = EllipticArcBuilder.CreateEllipticArcSegment(coord2D, radius, esriArcOrientation.esriArcClockwise, MapView.Active.Map.SpatialReference);
        PolygonBuilder polyBuilder = new PolygonBuilder(new[] { arcSegment });

        return polyBuilder.ToGeometry();
    }
Post Closed as "Not suitable for this site" by PolyGeo
added 4 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to convert Converting screen pixels to map units with C# using the ArcGIS Pro SDK

I am looking to create polygons (halos/rings) around the mouse cursor programmatically with C# using the ArcGIS Pro SDK. I have figured out how to create the halos by using System.Windows.Forms.Control.MousePosition and then converting into lat/long by using MapView.Active.ScreenToMap. I have also used a MouseHook from the Win32Api to give me a MouseMove event. This allows me to associate the polygon to the mouse cursor and move it around the map as an overlay. The

The problem that I am having now is that I can only create a polygon (halo/ring) with a radius in pixels. I need to be able to use map units, like feet, meters, miles, kilometers, etc. For example, I want to create a polygon (halo/ring) that has a radius of 100 feet. Is

Is there some way to accomplish this?

How to convert screen pixels to map units with C# using the ArcGIS Pro SDK

I am looking to create polygons (halos/rings) around the mouse cursor programmatically with C# using the ArcGIS Pro SDK. I have figured out how to create the halos by using System.Windows.Forms.Control.MousePosition and then converting into lat/long by using MapView.Active.ScreenToMap. I have also used a MouseHook from the Win32Api to give me a MouseMove event. This allows me to associate the polygon to the mouse cursor and move it around the map as an overlay. The problem that I am having now is that I can only create a polygon (halo/ring) with a radius in pixels. I need to be able to use map units, like feet, meters, miles, kilometers, etc. For example, I want to create a polygon (halo/ring) that has a radius of 100 feet. Is there some way to accomplish this?

Converting screen pixels to map units with C# using ArcGIS Pro SDK

I am looking to create polygons (halos/rings) around the mouse cursor programmatically with C# using the ArcGIS Pro SDK. I have figured out how to create the halos by using System.Windows.Forms.Control.MousePosition and then converting into lat/long by using MapView.Active.ScreenToMap. I have also used a MouseHook from the Win32Api to give me a MouseMove event. This allows me to associate the polygon to the mouse cursor and move it around the map as an overlay.

The problem that I am having now is that I can only create a polygon (halo/ring) with a radius in pixels. I need to be able to use map units, like feet, meters, miles, kilometers, etc. For example, I want to create a polygon (halo/ring) that has a radius of 100 feet.

Is there some way to accomplish this?

Source Link
Weequay
  • 101
  • 5

How to convert screen pixels to map units with C# using the ArcGIS Pro SDK

I am looking to create polygons (halos/rings) around the mouse cursor programmatically with C# using the ArcGIS Pro SDK. I have figured out how to create the halos by using System.Windows.Forms.Control.MousePosition and then converting into lat/long by using MapView.Active.ScreenToMap. I have also used a MouseHook from the Win32Api to give me a MouseMove event. This allows me to associate the polygon to the mouse cursor and move it around the map as an overlay. The problem that I am having now is that I can only create a polygon (halo/ring) with a radius in pixels. I need to be able to use map units, like feet, meters, miles, kilometers, etc. For example, I want to create a polygon (halo/ring) that has a radius of 100 feet. Is there some way to accomplish this?