lwh_122524 2023-03-13 09:39 采纳率: 60%
浏览 15
已结题

mapxtreme2008 +C#中定制图元不用图层怎么实现

mapxtreme2008 开发中点线面、自定义定制图元的功能都是通过图层实现的,但图层的方式有时会出现卡顿的问题,如下是定制图元的实现方式,若不用图层该怎么实现?

//这是定制图元的功能
            Map map = this.mapControl.Map;
            Table tblTemp = Session.Current.Catalog.GetTable("temp");
            if (!mIsRun)
             bmpPath = SaveBmpPic(@"\dataImg\" + System.IO.Path.GetFileName(platform.MKFile), platform.Sailing.Heading);
            if (tblTemp == null)
            {
                TableInfoMemTable tableInfoMemTable = new TableInfoMemTable("temp");
                tableInfoMemTable.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()));
                tableInfoMemTable.Columns.Add(ColumnFactory.CreateStyleColumn());//样式列   
                tableInfoMemTable.Columns.Add(ColumnFactory.CreateStringColumn("ID", 20));
                tableInfoMemTable.Columns.Add(ColumnFactory.CreateStringColumn("Name", 30));
                tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfoMemTable);
                mFeatureLayer = new MapInfo.Mapping.FeatureLayer(tblTemp);
                map.Layers.Add(mFeatureLayer);
            }
            FeatureGeometry featureGeometry = new MapInfo.Geometry.Point(mFeatureLayer.CoordSys, dPoint);
            BitmapPointStyle bitmapPointStyle = new BitmapPointStyle(Path.GetFileName(bmpPath), BitmapStyles.None, new System.Drawing.Color(), 25);
            CompositeStyle compositeStyle = new CompositeStyle(bitmapPointStyle);
            MapInfo.Data.Feature feature = new MapInfo.Data.Feature(mFeatureLayer.Table.TableInfo.Columns);
            feature["ID"] = platform.ID;
            feature["Name"] = System.IO.Path.GetFileNameWithoutExtension(platform.MKFile);
            feature.Geometry = featureGeometry;
            feature.Style = compositeStyle;
            mFeatureLayer.Table.InsertFeature(feature);

  • 写回答

2条回答 默认 最新

  • 社区专家-Monster-XH 2023-03-13 09:46
    关注

    基于Monster 组和GPT的调写:

    • 可以直接在地图控件上绘制自定义的图元,可以通过以下步骤实现:
    • 在地图控件上注册绘制事件。

    • 在绘制事件处理函数中,绘制自定义的图元。

    具体的实现方式如下:

    private void mapControl_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
    
        // 绘制点
        Point point = new Point(100, 100);
        Bitmap bitmap = new Bitmap("bitmap.bmp");
        g.DrawImage(bitmap, point.X - bitmap.Width / 2, point.Y - bitmap.Height / 2);
    
        // 绘制线
        Point[] linePoints = new Point[] { new Point(200, 200), new Point(300, 300), new Point(400, 200) };
        Pen linePen = new Pen(Color.Red, 2);
        g.DrawLines(linePen, linePoints);
    
        // 绘制面
        Point[] polygonPoints = new Point[] { new Point(500, 100), new Point(600, 200), new Point(700, 100) };
        SolidBrush polygonBrush = new SolidBrush(Color.Blue);
        g.FillPolygon(polygonBrush, polygonPoints);
    }
    
    

    在绘制事件处理函数中,可以使用GDI+绘图功能绘制点、线、面等自定义的图元。需要注意的是,绘制的坐标需要转换为屏幕坐标。可以使用MapControl.CoordSys.MapToPixel方法将地图坐标转换为屏幕坐标。如果需要与地图坐标进行交互,可以使用MapControl.CoordSys.PixelToMap方法将屏幕坐标转换为地图坐标。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月11日
  • 已采纳回答 4月11日
  • 创建了问题 3月13日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度