• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

CreatePolygonGraphicElement

QueuedTask.Run( () => {
        var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
        var element = layout.Elements.OfType<GraphicElement>().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<MapPoint> list = new List<MapPoint>() { 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));

      });

posted on 2020-04-03 22:26  gisai  阅读(485)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3