Mapxtreme 2005 添加点?
我在网上找到了一些在地图上添加点的代码。把他们放在单线程程序下运行正常,能看见添加的点。可是如果另起一个线程就看不见新加的点,不知道为啥?下面是添加点的程序:
public void CreateTempLayer()
{
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MainMap.MapAlias];
//指定表名建立表信息
MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable(tempLayerTableName);
//确保当前目录下不存在同名表
MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName);
if (tblTemp != null)
{
MapInfo.Engine.Session.Current.Catalog.CloseTable(tempLayerTableName);
}
//向表信息中添加可绘图列
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
//向表信息中添加自定义列
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("index"));
tblInfoTemp.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("name", 10));
//根据表信息创建临时表
tblTemp = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfoTemp);
//指定表,图层名和图层别名创建临时图层
FeatureLayer tempLayer = new FeatureLayer(tblTemp, tempLayerName, tempLayerName);
myMap.Layers.Add(tempLayer);
}
public void AddPointToLayer()
{
CreateTempLayer();
//dPoint.x = 116.346864;
//dPoint.y = 39.940982;
dPoint.x = 116.210368;
dPoint.y = 39.576692;
//dPoint.x = 234.09959;
//dPoint.y = 23.976621;
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MainMap.MapAlias];
//获取图层和表
FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[tempLayerName];
MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName);
//创建点图元及其样式
FeatureGeometry pgPoint = new MapInfo.Geometry.Point(workLayer.CoordSys, dPoint);
MapInfo.Styles.SimpleVectorPointStyle spsPoint = new MapInfo.Styles.SimpleVectorPointStyle(37, System.Drawing.Color.Green, 20);
MapInfo.Styles.CompositeStyle csPoint = new MapInfo.Styles.CompositeStyle(spsPoint);
MapInfo.Data.Feature ptPoint = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns);
ptPoint.Geometry = pgPoint;
ptPoint.Style = csPoint;
//将点图元加入图层
workLayer.Table.InsertFeature(ptPoint);
}
我如果这样调用:
AddPoint add = new AddPoint(MainMap);
add.AddPointToLayer();
就没有问题
但如果这样,就看不见新加的点
AddPoint add = new AddPoint(MainMap);
Thread t = new Thread(add.AddPointToLayer);
t.Start();