/// <summary>
        /// Create a circular polygon around a mappoint for with a radius in pixels.
        /// </summary>
        /// <param name="mapPoint">Center of the circle as a mappoint.</param>
        /// <param name="pixels">Circle radius in screen pixels.</param>
        /// <returns>A polygon geometry.</returns>
        private Polygon CreateSearchPolygon(MapPoint mapPoint, int pixels)
        {
            //get search radius
            var screenPoint       = MapView.Active.MapToScreen(mapPoint);
            var radiusScreenPoint = new System.Windows.Point((screenPoint.X + pixels), screenPoint.Y);
            var radiusMapPoint    = MapView.Active.ScreenToMap(radiusScreenPoint);
            var searchRadius      = GeometryEngine.Instance.Distance(mapPoint, radiusMapPoint);

            //build a search circle geometry
            var cent       = new Coordinate2D(mapPoint);
            var searchGeom = EllipticArcBuilderEx.CreateCircle(cent, searchRadius, ArcOrientation.ArcClockwise, MapView.Active.Map.SpatialReference);
            var searchPB   = new PolygonBuilderEx(new[] { searchGeom }, AttributeFlags.None);

            return(searchPB.ToGeometry());
        }
        /// <summary>
        /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it.
        /// </summary>
        /// <param name="geometry">The geometry created by the sketch.</param>
        /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns>
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (CurrentTemplate == null || geometry == null)
            {
                return(Task.FromResult(false));
            }

            return(QueuedTask.Run(() =>
            {
                //build a circular arc
                var cent = new Coordinate2D(geometry as MapPoint);
                var circleEAB = EllipticArcBuilderEx.CreateCircle(cent, Radius, ArcOrientation.ArcClockwise, MapView.Active.Map.SpatialReference);

                // find the source layer and determine whether polyline/polygon.  Create the appropriate shape
                var lyr = CurrentTemplate.Layer as BasicFeatureLayer;
                Geometry circleGeom = null;
                if (lyr.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    circleGeom = PolygonBuilderEx.CreatePolygon(new[] { circleEAB }, AttributeFlags.None);
                }
                else
                {
                    circleGeom = PolylineBuilderEx.CreatePolyline(circleEAB, AttributeFlags.None);
                }

                // Create an edit operation
                var createOperation = new EditOperation();
                createOperation.Name = string.Format("Create circular {0}", CurrentTemplate.Layer.Name);
                createOperation.SelectNewFeatures = true;

                // Queue feature creation
                createOperation.Create(CurrentTemplate, circleGeom);

                // Execute the operation
                return createOperation.ExecuteAsync();
            }));
        }
Example #3
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (ActiveElementContainer == null)
            {
                Task.FromResult(true);
            }

            if (Module1.SelectedSymbol == null)
            {
                return(Task.FromResult(true));
            }

            return(QueuedTask.Run(() =>
            {
                var centerPt = ((Polygon)geometry).Extent.CenterCoordinate;
                double circleArea = ((Polygon)geometry).Extent.Area;
                double radius = Math.Sqrt(circleArea / Math.PI);
                var circle = EllipticArcBuilderEx.CreateCircle(centerPt, radius, ArcOrientation.ArcClockwise);

                List <Segment> circleSegments = new List <Segment>()
                {
                    circle
                };
                var circlePolygon = PolygonBuilderEx.CreatePolygon(circleSegments);

                var ge = ElementFactory.Instance.CreateTextGraphicElement
                             (this.ActiveElementContainer, TextType.CircleParagraph,
                             circlePolygon, Module1.SelectedSymbol as CIMTextSymbol, "Text"
                             );
                //The new text graphic element has been created
                //We now switch to Pro's out of box "esri_layouts_inlineEditTool"
                //This will allow inline editing of the text
                //This tool will work on graphics on both map view and layouts
                FrameworkApplication.SetCurrentToolAsync("esri_layouts_inlineEditTool");
                return true;
            }));
        }