CreatePolygonGraphicElement

QueuedTask.Run( () => {
        var layout = Project.Current.GetItems>().FirstOrDefault().GetLayout();
        var element = layout.Elements.OfType>().FirstOrDefault();
        if (element == null) return;
        //Get the element's X, Y, Width and height
        var x = element.GetX();
        var y = element.GetY();
        var width = element.GetWidth();
        var height = element.GetHeight();

        //Create a polygon using the Graphic elements X, Y, Width and Height.
        MapPoint pt1 = MapPointBuilder.CreateMapPoint(x, y); //Anchor pt - lower left
        MapPoint pt2 = MapPointBuilder.CreateMapPoint(x + width, y); //lower right
        MapPoint pt3 = MapPointBuilder.CreateMapPoint(x + width, y + height );//upper right
        MapPoint pt4 = MapPointBuilder.CreateMapPoint(x, y + height);//upper left

        List> list = new List>() { pt1, pt2, pt3, pt4 };

        Polygon polygon = PolygonBuilder.CreatePolygon(list, null);

        //Rotate the polygon by the same angle the graphic element is rotated by
        var polygonRotate = GeometryEngine.Instance.Rotate(polygon, pt1, element.GetRotation() * (Math.PI / 180)) as Polygon; //Angle should be in radians.

        //Use polygonRotate to get the bounds of the rotated text element
        System.Diagnostics.Debug.WriteLine($"Width: {polygonRotate.Extent.Width}, Height: {polygonRotate.Extent.Height}");

        //Create another graphic element that envelops the original element
        Envelope env = polygonRotate.Extent;
        CIMStroke lineStroke = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot);
        LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, env, SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Null, lineStroke));

      });

你可能感兴趣的:(CreatePolygonGraphicElement)