MapXtreme2005+C#.Net 2.0从入门到精通之:
For Absolute Beginner(1)
² MapXtreme2005对象的层次关系:
|--Layer(图层实体)è存取feature(图元)
Map地图)--|
|--Table(属性表格)è存取属性字段(fields)值
(Map是由Layers和Tablet两个不可分割部分组成的一个整体)
²首先获得Map对象
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
²Map对象的方法、属性:
(1)设置地图的视图方法SetView:
myMap.SetView(myMap.Layers.Bounds, myMap.GetDisplayCoordSys());
(2)获取当前页面的坐标:
myMap.GetDisplayCoordSys();
(3)地图缩放倍数属性Zoom:
放大2倍:
myMap.Zoom = new MapInfo.Geometry.Distance(myMap.Zoom.Value / 2, myMap.Zoom.Unit);
缩小2倍:
myMap.Zoom = new MapInfo.Geometry.Distance(myMap.Zoom.Value * 2, myMap.Zoom.Unit);
²有了Map对象后,再就可以获得Layer图层对象了,方法如下:
FeatureLayer lyr = myMap.Layers["worldcap"] as FeatureLayer;
注释:地图是有许多图层的,故Map的Layers对象其实是个Layer数组,通过Layer的名字通过[]操作符来引用的。(在这里可以简单的认为Map就是纯粹的地图对象,因而可以通过点(.)运算符来索引了。
(1)移动层的顺序Move:
从第一层移动第二层:
myMap.Layers.Move(0,1);
(2)添加新的图层Add:
添加图元要素层:(图层和表是不可分割的一个整体的两个部分,添加图元要素之前,要确定该图层的表。)
MapInfo.Data.Table tab = MapInfo.Engine.Session.Current.Catalog.OpenTable(@"D:/XtremeMapData/usa.tab", " USA ");
FeatureLayer fl = new FeatureLayer(tab);
myMap.Layers.Add(fl);
添加标注要素层:
MapInfo.Mapping.LabelLayer labelLayer = new LabelLayer("LabelUS");
LabelSource labelSource = new LabelSource(tab);
MapInfo.Styles.SimpleLineStyle simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(); labelSource.DefaultLabelProperties.Style.CalloutLine.ApplyStyle(simpleLineStyle);
labelLayer.Sources.Append(labelSource);
myMap.Layers.Add(labelLayer);
(3)FeatureLayer、LabelLayers等都是在MapInfo.Mapping空间中的。
²有了Map对象后,再就就可以获得Table属性表格了,方法如下:
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(“world”);
注释:Table是通过Catalog类的静态方法GetTable()来获得的。这点与Layers不同的。
1.Table、临时表等是在MapInfo.Data空间中的。
2创建临时表(暂时存放在内存中的表):
创建临时表之前必须要确定表的名字、字段(可绘图列、属性值列)等信息,即是TableInfo;
MapInfo.Data.TableInfoMemTable tblInfoTemp = new MapInfo.Data.TableInfoMemTable(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);
//获得该临时表
MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName);
//指定表,图层名和图层别名创建临时图层
FeatureLayer tempLayer = new FeatureLayer(tblTemp, tempLayerName, tempLayerName);
myMap.Layers.Add(tempLayer);