MapXtreme 图层操作 创建临时图层-添加图元-加图层标注-清除图元
2015-06-11 14:19:00 访问(1710) 赞(0) 踩(0)
public class map_operation
{
public MapControlModel model;
public MapInfo.Mapping.Map map;
public Catalog Cat;
public MapInfo.Data.Table tblTemp;
public map_operation()
{
model = MapControlModel.GetModelFromSession();
map = model.GetMapObj("Map1");
Cat = MapInfo.Engine.Session.Current.Catalog;
tblTemp = Cat.GetTable("Animation");
}
//创建临时图层
public void creat_temp_table()
{
TableInfoMemTable tblInfoTemp = new TableInfoMemTable("Animation"); //创建GPS终端小车集图层
if (tblTemp != null) //Table exists close it
{
Cat.CloseTable("Animation");
}
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);
FeatureLayer lyr = new FeatureLayer(tblTemp);
map.Layers.Add(lyr);
}
//添加图元
public void insert_feature(string fileName,double x,double y,string GPS_NUMBER)
{
BitmapPointStyle bStyle = new BitmapPointStyle(fileName); //fileName格式为@"gpscar2_p2.bmp" 这个@代表C:\Program Files\Common Files\MapInfo\MapXtreme\6.7.1\CustSymb
bStyle.PointSize = Convert.ToInt16(24);
bStyle.NativeSize = true;
bStyle.Attributes = StyleAttributes.PointAttributes.BaseAll;
bStyle.SetApplyAll();
FeatureGeometry pt = new MapInfo.Geometry.Point(map.GetDisplayCoordSys(), new DPoint(y, x)) as FeatureGeometry;
Feature ftr = new Feature(tblTemp.TableInfo.Columns);
ftr.Geometry = pt; //图元地理位置设置
ftr.Style = bStyle; //图元为位图样式
ftr["Name"] = "aaaa";
ftr["Dept"] = GPS_NUMBER; //GPS终端号
ftr["Level"] = 2;
tblTemp.InsertFeature(ftr); //插入图元
}
//加图层标注
public void creat_mark()
{
MapInfo.Data.Table tblTemp = Cat.GetTable("Animation");
LabelSource labelSource = new LabelSource(tblTemp); //给所创建的临时表Animation中的图元加标注
//指定要标准字段所在的列
labelSource.DefaultLabelProperties.Caption = "Name"; //所要标注的列名
labelSource.DefaultLabelProperties.Layout.Offset = 8; //标注偏移
labelSource.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.TopRight;//标注对齐方式
labelSource.DefaultLabelProperties.Style.Font.BackColor = System.Drawing.Color.White; //字体背景
labelSource.DefaultLabelProperties.Style.Font.ForeColor = System.Drawing.Color.Red; //字体颜色
labelSource.DefaultLabelProperties.Style.Font.TextEffect = MapInfo.Styles.TextEffect.Box; //边缘效果
labelSource.DefaultLabelProperties.Style.Font.FontWeight = MapInfo.Styles.FontWeight.Bold; //粗体
MapInfo.Styles.SimpleLineStyle simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(0); //标注注释线
labelSource.DefaultLabelProperties.Style.CalloutLine.ApplyStyle(simpleLineStyle);
//取消标注注释线
LabelLayer labelLayer = new LabelLayer();
labelLayer.Name = "jcbz"; //设置标注图层的名称
labelLayer.Sources.Append(labelSource); //往地图中加入该标注层
map.Layers.Add(labelLayer);
}
//清除临时图层中所有的图元
public void clear_feature()
{
SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
IResultSetFeatureCollection ifs;
MapInfo.Data.Table Tm;
Tm = Cat.GetTable("Tm");
if (Tm != null) //Table exists close it
{
si = MapInfo.Data.SearchInfoFactory.SearchWhere("");
ifs = MapInfo.Engine.Session.Current.Catalog.Search("Tm", si);
foreach (Feature ft in ifs)
Tm.DeleteFeature(ft); //删除所有该图层上的图元
}
}
}
标签:
MapXtreme 图层操作 创建临时图层-添加图元-加图层标注-清除图元 


上一条:
下一条:
相关评论
发表评论