📄 创建新图层并显示指定位置小车2.txt
字号:
Dim cat As Catalog = MapInfo.Engine.Session.Current.Catalog
'创建临时层
Dim tblInfoTemp As TableInfoMemTable = New TableInfoMemTable("Animation")
Dim tblTemp As Table = cat.GetTable("Animation")
Dim map As Map = MapInfo.Engine.Session.Current.MapFactory(MapControl1.MapAlias)
If Not (tblTemp Is Nothing) Then
cat.CloseTable("Animation")
End If
tblInfoTemp.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(map.GetDisplayCoordSys()))
tblInfoTemp.Columns.Add(ColumnFactory.CreateStyleColumn())
tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Name", 40))
tblInfoTemp.Columns.Add(ColumnFactory.CreateStringColumn("Dept", 15))
tblInfoTemp.Columns.Add(ColumnFactory.CreateIntColumn("Level"))
tblTemp = cat.CreateTable(tblInfoTemp)
Dim lyr As FeatureLayer = New FeatureLayer(tblTemp)
map.Layers.Add(lyr)
'创建点
Dim pt As FeatureGeometry = New MapInfo.Geometry.Point(lyr.CoordSys, New DPoint(114.07, 22.51))
Dim cs As CompositeStyle = New CompositeStyle(New SimpleVectorPointStyle(34, Color.Red, 20))
Dim ftr As Feature = New Feature(tblTemp.TableInfo.Columns)
ftr.Geometry = pt
ftr.Style = cs
ftr("Name") = "Kelly"
ftr("Dept") = "Sales"
ftr("Level") = 3
tblTemp.InsertFeature(ftr)
Dim pt2 As FeatureGeometry = New MapInfo.Geometry.Point(lyr.CoordSys, New DPoint(114.07, 22.51))
Dim cs2 As CompositeStyle = New CompositeStyle(New SimpleVectorPointStyle(34, Color.Purple, 20))
Dim ftr2 As Feature = New Feature(tblTemp.TableInfo.Columns)
ftr2.Geometry = pt2
ftr2.Style = cs2
ftr2("Name") = "Greg"
ftr2("Dept") = "Marketing"
ftr2("Level") = 2
tblTemp.InsertFeature(ftr2)
'显示标注.
Dim _textSymbol = New MapInfo.Styles.TextStyle
_textSymbol.Font.ForeColor = Color.Red
_textSymbol.Font.Size = 12
Dim txtlayer As New MapInfo.Mapping.LabelLayer
map.Layers.Add(txtlayer)
Dim source As New MapInfo.Mapping.LabelSource(MapInfo.Engine.Session.Current.Catalog.GetTable("Animation"))
source.DefaultLabelProperties.Caption = "Name"
source.DefaultLabelProperties.Style = _textSymbol
txtlayer.Sources.Append(source)
map.Center = New DPoint(114.07, 22.51)
//另外一种增加小车的方法:
//创建小车及其样式
Connection=new MapInfo.Data.MIConnection();
Connection.Open ();
MapInfo.Geometry.Point pt=new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys(),-122.8788,40.3815);
MapInfo.Styles.FontPointStyle sty=new MapInfo.Styles.FontPointStyle(66,new MapInfo.Styles.Font("MapInfo Transportation",48),0,System.Drawing.Color.Aqua,18);
//将小车增加到图层
MICommand comm=Connection.CreateCommand();
comm.CommandText ="Insert into targetTable(ID,name,obj,mi_style) values('1','car1',@obj,@style)";
comm.Parameters.Add ("@obj",pt);
comm.Parameters.Add ("@style",sty);
comm.ExecuteNonQuery();
Connection.Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -