不报错,能运行,就是没有实现在两点间画线的功能。。
private void Page_Load(object sender, System.EventArgs e)
{
if (StateManager.IsManualState())
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
{
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
}// Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
}
//MapControl MapControl1 = new MapControl();
DPoint p = new DPoint(126.0, 40.0);
DPoint q = new DPoint(139.0, 39.0);
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0]; FeatureLayer TmFlyr;//下面两个是我手动添加的Form1的公有成员变量
MapInfo.Data.Table TmTbl; MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
//TmTbl = Cat.GetTable("World"); //如果是打开现有表进行操作可以直接通过表名字得到某个表 TableInfoMemTable TmInfo = new TableInfoMemTable("Tm"); TmTbl = Cat.GetTable("Tm");
//这里是打开名字为“Tm”的Table,这句在其实没有用处,但是当你打开的是已经加载
//GST文件的地图时,需要首先判断一下会不会重名
if (TmTbl != null) { Cat.CloseTable("Tm"); } //如果表不为空,标明没有重名 //要创建一个Table,需要首先创建Tables信息,下面就是创建Tables信息:( 就好像在数据库里面创建字段一样 )
//这些字段标明了你表中的各个元素的属性,方便在程序中通过特定值查找等操作
//构造GeometryColumn字段
TmInfo.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
//构造Style类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStyleColumn());
//构造String类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Name", 12));
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Loca", 50));
//构造Int类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateIntColumn("Indx")); TmTbl = Cat.CreateTable(TmInfo); //创建临时表 TmFlyr = new FeatureLayer(TmTbl); //创建临时图层
//MapControl1.Map.Layers.Add(TmFlyr);
myMap.Layers.Add(TmFlyr);//将临时图层加入当前的MapXTreme图层当中 //下面应该是将坐标点根据当前地图的坐标系进行了一次转换
FeatureGeometry SVpt = new MapInfo.Geometry.Point( TmFlyr.CoordSys, new DPoint(p.x, q.y ) ) as FeatureGeometry;
CompositeStyle Vcs = new CompositeStyle( new SimpleVectorPointStyle( 37, Color.Red, 10 ) ); //创建点样式
Feature Vftr = new Feature(TmTbl.TableInfo.Columns); //创建图元
Vftr.Geometry = SVpt; //设置图元属性
Vftr.Style = Vcs;
Vftr["Name"] = "KHT";
Vftr["Loca"] = "Beijing";
Vftr["Indx"] = 1;
TmTbl.InsertFeature( Vftr ); //将图元加入表中 MapInfo.Geometry.DPoint[] Lpt = new DPoint[2]; //创建一个点数组{多个点可以多建立}
Lpt[0]=p;
Lpt[1]=q;
FeatureGeometry MLpt = new MultiPolygon ( TmFlyr.CoordSys, CurveSegmentType.Linear,Lpt );//创佳一个多边形
SimpleLineStyle bStyle = new SimpleLineStyle( new LineWidth( 3, LineWidthUnit.Pixel ), 2, Color.Red) ; //创建一个边框样式
SimpleInterior iStyle = new SimpleInterior ( 2, Color.Blue, Color.Blue,false); //创建一个内部样式
CompositeStyle Lcs = new CompositeStyle ( new AreaStyle( bStyle, iStyle), null, null, null); //创建线样式 Feature Lftr = new Feature( MLpt, Lcs ); //创建多边形图元 TmTbl.InsertFeature( Lftr); //将图元加入表中
}
private void Page_Load(object sender, System.EventArgs e)
{
if (StateManager.IsManualState())
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
{
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
}// Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
}
//MapControl MapControl1 = new MapControl();
DPoint p = new DPoint(126.0, 40.0);
DPoint q = new DPoint(139.0, 39.0);
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0]; FeatureLayer TmFlyr;//下面两个是我手动添加的Form1的公有成员变量
MapInfo.Data.Table TmTbl; MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
//TmTbl = Cat.GetTable("World"); //如果是打开现有表进行操作可以直接通过表名字得到某个表 TableInfoMemTable TmInfo = new TableInfoMemTable("Tm"); TmTbl = Cat.GetTable("Tm");
//这里是打开名字为“Tm”的Table,这句在其实没有用处,但是当你打开的是已经加载
//GST文件的地图时,需要首先判断一下会不会重名
if (TmTbl != null) { Cat.CloseTable("Tm"); } //如果表不为空,标明没有重名 //要创建一个Table,需要首先创建Tables信息,下面就是创建Tables信息:( 就好像在数据库里面创建字段一样 )
//这些字段标明了你表中的各个元素的属性,方便在程序中通过特定值查找等操作
//构造GeometryColumn字段
TmInfo.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
//构造Style类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStyleColumn());
//构造String类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Name", 12));
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Loca", 50));
//构造Int类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateIntColumn("Indx")); TmTbl = Cat.CreateTable(TmInfo); //创建临时表 TmFlyr = new FeatureLayer(TmTbl); //创建临时图层
//MapControl1.Map.Layers.Add(TmFlyr);
myMap.Layers.Add(TmFlyr);//将临时图层加入当前的MapXTreme图层当中 //下面应该是将坐标点根据当前地图的坐标系进行了一次转换
FeatureGeometry SVpt = new MapInfo.Geometry.Point( TmFlyr.CoordSys, new DPoint(p.x, q.y ) ) as FeatureGeometry;
CompositeStyle Vcs = new CompositeStyle( new SimpleVectorPointStyle( 37, Color.Red, 10 ) ); //创建点样式
Feature Vftr = new Feature(TmTbl.TableInfo.Columns); //创建图元
Vftr.Geometry = SVpt; //设置图元属性
Vftr.Style = Vcs;
Vftr["Name"] = "KHT";
Vftr["Loca"] = "Beijing";
Vftr["Indx"] = 1;
TmTbl.InsertFeature( Vftr ); //将图元加入表中 MapInfo.Geometry.DPoint[] Lpt = new DPoint[2]; //创建一个点数组{多个点可以多建立}
Lpt[0]=p;
Lpt[1]=q;
FeatureGeometry MLpt = new MultiPolygon ( TmFlyr.CoordSys, CurveSegmentType.Linear,Lpt );//创佳一个多边形
SimpleLineStyle bStyle = new SimpleLineStyle( new LineWidth( 3, LineWidthUnit.Pixel ), 2, Color.Red) ; //创建一个边框样式
SimpleInterior iStyle = new SimpleInterior ( 2, Color.Blue, Color.Blue,false); //创建一个内部样式
CompositeStyle Lcs = new CompositeStyle ( new AreaStyle( bStyle, iStyle), null, null, null); //创建线样式 Feature Lftr = new Feature( MLpt, Lcs ); //创建多边形图元 TmTbl.InsertFeature( Lftr); //将图元加入表中
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (StateManager.IsManualState())
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
{
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
} // Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
}
//MapControl MapControl1 = new MapControl(); DPoint p = new DPoint(126.0, 40.0);
DPoint q = new DPoint(139.0, 39.0);
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0]; FeatureLayer TmFlyr;//下面两个是我手动添加的Form1的公有成员变量
MapInfo.Data.Table TmTbl; MapInfo.Data.Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
//TmTbl = Cat.GetTable("World"); //如果是打开现有表进行操作可以直接通过表名字得到某个表 TableInfoMemTable TmInfo = new TableInfoMemTable("Tm"); TmTbl = Cat.GetTable("Tm");
//这里是打开名字为“Tm”的Table,这句在其实没有用处,但是当你打开的是已经加载
//GST文件的地图时,需要首先判断一下会不会重名
if (TmTbl != null) { Cat.CloseTable("Tm"); } //如果表不为空,标明没有重名 //要创建一个Table,需要首先创建Tables信息,下面就是创建Tables信息:( 就好像在数据库里面创建字段一样 )
//这些字段标明了你表中的各个元素的属性,方便在程序中通过特定值查找等操作
//构造GeometryColumn字段
TmInfo.Columns.Add(ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));
//构造Style类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStyleColumn());
//构造String类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Name", 12));
TmInfo.Columns.Add(ColumnFactory.CreateStringColumn("Loca", 50));
//构造Int类型Column字段
TmInfo.Columns.Add(ColumnFactory.CreateIntColumn("Indx")); TmTbl = Cat.CreateTable(TmInfo); //创建临时表 TmFlyr = new FeatureLayer(TmTbl); //创建临时图层
//MapControl1.Map.Layers.Add(TmFlyr);
myMap.Layers.Add(TmFlyr);//将临时图层加入当前的MapXTreme图层当中 //下面应该是将坐标点根据当前地图的坐标系进行了一次转换
FeatureGeometry SVpt = new MapInfo.Geometry.Point(TmFlyr.CoordSys, new DPoint(p.x, q.y)) as FeatureGeometry; CompositeStyle Vcs = new CompositeStyle(new SimpleVectorPointStyle(37, Color.Red, 10)); //创建点样式
Feature Vftr = new Feature(TmTbl.TableInfo.Columns); //创建图元
Vftr.Geometry = SVpt; //设置图元属性
Vftr.Style = Vcs;
Vftr["Name"] = "KHT";
Vftr["Loca"] = "Beijing";
Vftr["Indx"] = 1; TmTbl.InsertFeature(Vftr); //将图元加入表中 MapInfo.Geometry.DPoint[] Lpt = new DPoint[2]; //创建一个点数组{多个点可以多建立}
Lpt[0] = p;
Lpt[1] = q;
FeatureGeometry MLpt = new MultiPolygon(TmFlyr.CoordSys, CurveSegmentType.Linear, Lpt);//创佳一个多边形
SimpleLineStyle bStyle = new SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), 2, Color.Red); //创建一个边框样式
SimpleInterior iStyle = new SimpleInterior(2, Color.Blue, Color.Blue, false); //创建一个内部样式
CompositeStyle Lcs = new CompositeStyle(new AreaStyle(bStyle, iStyle), null, null, null); //创建线样式 Feature Lftr = new Feature(MLpt, Lcs); //创建多边形图元 TmTbl.InsertFeature(Lftr); //将图元加入表中
}
}