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);

基于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方法将屏幕坐标转换为地图坐标。

不用图层,可以自己对图元进行一个编组。