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