MapXtreme 2005学习(2):向图层中添加点

在添加点之前先要在地图上创建一个临时图层,创建临时图层请参考《MapXtreme2005学习(1):创建临时图层》。本示例中通过指定图层名,表名,点坐标在图层中添加一个点。代码如下:

 

    /// <summary>
    /// 向图层中添加点
    /// Design by Glacier
    /// 2008年8月6日
    /// <param name="tempLayerTableName">表名</param>
    /// <param name="tempLayerName">图层名</param>
    /// <param name="dPoint">点坐标</param>
    /// </summary>
    public static void AddPointToLayer(string tempLayerTableName, string tempLayerName, DPoint dPoint)
    {
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];

        //获取图层和表
        FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[tempLayerName];
        MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName);

        //创建点图元及其样式
        FeatureGeometry pgPoint = new MapInfo.Geometry.Point(workLayer.CoordSys, dPoint);
        MapInfo.Styles.SimpleVectorPointStyle spsPoint = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 20);
        MapInfo.Styles.CompositeStyle csPoint = new MapInfo.Styles.CompositeStyle(spsPoint);
        MapInfo.Data.Feature ptPoint = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
        ptPoint.Geometry = pgPoint;
        ptPoint.Style = csPoint;

        //将点图元加入图层
        workLayer.Table.InsertFeature(ptPoint);
    }

posted @ 2008-08-06 15:48  Glacier  阅读(2267)  评论(8编辑  收藏  举报