ppp80近日用了一下mapxtreme for .net。虽然感觉没有mapx的好用,不过这
个可以和.net结合,已经很满足了。不过我的程序只用了一点点mapxtreme的
东西,所以发掘的东西很少,先记在下边:
1创建临时层
MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable("Animation");
MapInfo.Data.Table tblTemp = Cat.GetTable("Animation");
if (tblTemp != null) {
Cat.CloseTable("Animation");
}
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(mapControl1.Map.GetDisplayCoordSys()));
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("编号", 8));
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("设备编号", 8));
tblTemp = Cat.CreateTable(tblInfoTemp);
FeatureLayer lyr = new FeatureLayer(tblTemp);
mapControl1.Map.Layers.Add(lyr);
2创建点样式
MapInfo.Styles.FontPointStyle _fontSymbol=new MapInfo.Styles.FontPointStyle();
_fontSymbol.Code=53;
_fontSymbol.PointSize=14;
_fontSymbol.Color=System.Drawing.Color.Purple;
_fontSymbol.Font.Name="Map Symbols";
_fontSymbol.Font.FontWeight=MapInfo.Styles.FontWeight.Bold;
_fontSymbol.Angle=Ang;//因为是车,所以有一定角度的
3创建点
FeatureGeometry pt3 = new MapInfo.Geometry.Point(lyr.CoordSys, new DPoint(x,y)) as FeatureGeometry;
MapInfo.Styles.CompositeStyle cs3 = new MapInfo.Styles.CompositeStyle(new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Red, 10));
MapInfo.Data.Feature ftr3 = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
ftr3.Geometry = pt3;
cs3.SymbolStyle=_fontSymbol;
ftr3.Style = cs3;
ftr3["编号"] = idr[0].ToString();
ftr3["设备编号"] =idr[1].ToString();
。。。。
4为点添加标注
MapInfo.Styles.TextStyle _fontSymbol=new MapInfo.Styles.TextStyle();
_fontSymbol.Font.ForeColor=Color.Red;
_fontSymbol.Font.Size=8;
LabelLayer layer = new LabelLayer();
mapControl1.Map.Layers.Add(layer);
LabelSource source = new LabelSource(Cat.GetTable("Animation"));
source.DefaultLabelProperties.Caption = "Temp";
source.DefaultLabelProperties.Style=_fontSymbol;
layer.Sources.Append(source);
5清除所有的点
Catalog cat = MapInfo.Engine.Session.Current.Catalog;
Table tblTemp = cat.GetTable("Animation");
if (tblTemp != null)
{ tblTemp.BeginAccess (MapInfo.Data.TableAccessMode.Write );
foreach(Feature ftr in tblTemp)
{
tblTemp.DeleteFeature(ftr.Key);
}
tblTemp.EndAccess ();
}
6查找点
Feature fKS = _catalog.SearchForFeature("Animation", MapInfo.Data.SearchInfoFactory.SearchWhere("编号='"+ID+"'"));
SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchIntersectsFeature(fKS, IntersectType.Geometry);
IResultSetFeatureCollection fc = _catalog.Search("Animation", si);
mapControl1.Map.SetView(fc.Envelope);
_selection.Clear();
_selection.Add(fc);
7在datagrid中显示图层所有点
dataGrid1.CaptionVisible=false;
this.miCommand.CommandText = "Select * from " + miTable.Alias;
MapInfo.Data.MIDataReader miReader = this.miCommand.ExecuteReader();
DataTable dt = new DataTable("Data");
for (int i = 0; i < miReader.FieldCount; i++)
{
DataColumn dc = dt.Columns.Add(miReader.GetName(i));
}
while (miReader.Read())
{
DataRow dr = dt.NewRow();
for (int i = 0; i < miReader.FieldCount; i++)
{
dr[i] = miReader.GetValue(i);
}
dt.Rows.Add(dr);
}
dt.Columns[0].ColumnMapping = MappingType.Hidden;
dt.Columns[1].ColumnMapping = MappingType.Hidden;
dt.Columns[6].ColumnMapping = MappingType.Hidden;
if (showSchema)
{
dataGrid1.DataSource = miReader.GetSchemaTable();
}
else
{
dataGrid1.DataSource = dt;
}
miReader.Close();