创建临时图层

来源:互联网 发布:垃圾评论过滤算法 编辑:程序博客网 时间:2024/06/10 12:54
 
首先说明一下创建临时图层的作用,当你需要在现有的地图上动态地添加一些点或线等图元时,就可以在临时

图层中进行。比如说在作动态轨迹跟踪时,通过读取数据库中的点坐标,不断地更新轨迹和图元的位置。代码如

下:

 

    /// <summary>
    /// 创建临时图层
    /// Design by Glacier
    /// 2008年8月6日
    /// <param name="tempLayerTableName">表名</param>
    /// <param name="tempLayerName">图层名</param>
    /// </summary>
    public static void CreateTempLayer(string tempLayerTableName, string tempLayerName)
    {
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory

[MapControl1.MapAlias];

        //指定表名建立表信息
        MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable

(tempLayerTableName);

        //确保当前目录下不存在同名表
        MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable

(tempLayerTableName);
        if (tblTemp != null)
        {
            MapInfo.Engine.Session.Current.Catalog.CloseTable(tempLayerTableName);
        }

        //向表信息中添加可绘图列
        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn

(myMap.GetDisplayCoordSys()));
        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());

        //向表信息中添加自定义列
        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("index"));
        tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("name", 10));

        //根据表信息创建临时表
        tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfoTemp);

        //指定表,图层名和图层别名创建临时图层
        FeatureLayer tempLayer = new FeatureLayer(tblTemp, tempLayerName, tempLayerName);
        myMap.Layers.Add(tempLayer);
    }