物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 688|回复: 0

MapXtreme2004代码 在地图上新增加点图元

[复制链接]
发表于 2013-3-13 20:53:53 | 显示全部楼层 |阅读模式
        Dim otable As MapInfo.Data.Table
        Dim oftr As MapInfo.Data.Feature
        Dim ostyle1 As New MapInfo.Styles.SimpleVectorPointStyle
        Dim ostyle2 As New MapInfo.Styles.SimpleLineStyle
        Dim ostyle3 As New MapInfo.Styles.AreaStyle
        Dim ostyle4 As New MapInfo.Styles.TextStyle
        Dim ostyle As New MapInfo.Styles.FontPointStyle
        'Dim ostyle As New MapInfo.Styles.SimpleVectorPointStyle
        Dim opoint As MapInfo.Geometry.Point
        Dim k As MapInfo.Data.Key

        oLayer = mapcontrol.Map.Layers("TempLayer")
        otable = oLayer.Table

        opoint = New MapInfo.Geometry.Point(mapcontrol.Map.GetDisplayCoordSys, mapcontrol.Map.Bounds.Center.x, mapcontrol.Map.Bounds.Center.y)
        ''ostyle1 = New MapInfo.Styles.CompositeStyle(ostyle3, ostyle2, ostyle4, ostyle1,)
        ostyle.Font.Name = "宋体"
        ostyle.PointSize = 30
        ostyle.Color = System.Drawing.Color.Red
        oftr = New MapInfo.Data.Feature(opoint, ostyle)
        k = otable.InsertFeature(oftr)
2  private void Button1_Click(object sender, System.EventArgs e)
{
    //在当前地图中心的X和Y坐标的二分之一处画点
    Map map1=MapControl1.Map;
    double x=map1.Center.x/2;
    double y=map1.Center.y/2;
    showPointOnSearchTableMap(x,y);
}
private void showPointOnSearchTableMap(double x, double y)
{  
    Map map=MapControl1.Map;
    MapInfo.Data.Table table=MapInfo.Engine.Session.Current.Catalog.GetTable("temp");      
    CoordSys coordSys=map.GetDisplayCoordSys();
    if (table==null)
    {   
        TableInfoMemTable tableInfo=new TableInfoMemTable("temp");
        tableInfo.Temporary =true;
        Column column;
       column=new GeometryColumn(coordSys);
        column.Alias="MI_Geometry";
        column.DataType =MIDbType.FeatureGeometry;
        tableInfo.Columns.Add(column);
        column=new Column();
        column.Alias="MI_Style";
        column.DataType =MIDbType.Style;
        tableInfo.Columns.Add(column);
        table = MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfo);
    }
    else
    {
        MIConnection conn=new MIConnection();
        MICommand tempcmd=conn.CreateCommand();
        tempcmd.CommandText ="delete from temp";
        conn.Open();
        tempcmd.ExecuteNonQuery();
        conn.Close();
        tempcmd.Dispose();
    }
    //创建点及其样式
    FeatureGeometry geometry=new MapInfo.Geometry.Point (coordSys,x,y);  
    SimpleVectorPointStyle vStyle=new SimpleVectorPointStyle(40,System.Drawing.Color.Green,14);
    //创建的点的样式、颜色和大小都在上条语句中修改
    CompositeStyle cStyle=new MapInfo.Styles.CompositeStyle(vStyle);
    MIConnection connection=new MIConnection();
    MICommand cmd=connection.CreateCommand();
    cmd.Parameters.Add("geometry",MIDbType.FeatureGeometry);
    cmd.Parameters.Add("style",MIDbType.Style);
    cmd.CommandText ="Insert Into temp(MI_Geometry,MI_Style) values (geometry,style)";
    connection.Open();
    cmd.Parameters[0].Value  =geometry;
    cmd.Parameters[1].Value =cStyle;
    int nchanged=cmd.ExecuteNonQuery();
    cmd.Dispose();
    //创建图层并将其插入到当前地图的最上层
    FeatureLayer fl = new FeatureLayer(table);
    map.Layers.Insert(0,fl);
    map.Center = new MapInfo.Geometry.DPoint(x,y);
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-13 11:22 , Processed in 0.107159 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表