mapxtrememapxtreme
1 设置图层可选状态
2 设置层的可用状态
3 层居中,看全图
/**////<summary> ///使指定层全部呈现在地图的可见范围中 ///</summary> ///<paramname="tableAlias">层别名</param> publicvoidLayerCenter(stringlayerName)
{
MapInfo.Data.Table[]tables=newMapInfo.Data.Table[1];
tables[0]=MapInfo.Engine.Session.Current.Catalog.GetTable(layerName);
if(tables[0]==null)
return;
if(mapControl1.Map.Layers[layerName]==null)
return;
if(mapControl1.Map.Layers[layerName].Enabled==false)
mapControl1.Map.Layers[layerName].Enabled=true;
MapInfo.Mapping.IMapLayerFilteriMapLayerFilter=MapInfo.Mapping.MapLayerFilterFactory.FilterByTable(tables);
MapInfo.Mapping.MapLayerEnumeratormapLayerEnumerator=mapControl1.Map.Layers.GetMapLayerEnumerator(iMapLayerFilter);
mapControl1.Map.SetView(mapLayerEnumerator);
OnFeatureUnclick();
}
4 放大缩小地图
5 移动层的顺序
mapControl1.Map.Layers.Move(index1,index2);
6 图元/图层透明
/**////<summary> ///设置层的透明与否 ///</summary> ///<paramname="layerName">层名</param> ///<paramname="opaqueType">不透明类型ALL全部不透明BORDER只有边界不透明(内部透明)NONE全部透明</param> ///<paramname="borderColor">如果是边界不透明,此处设置边界颜色</param> publicvoidLayerTransparent(stringlayerName,OpaqueTypeopaqueType,System.Drawing.ColorborderColor)
{
MapInfo.Styles.CompositeStylecompositeStyle=GetOpaqueStyle(opaqueType,borderColor);
//创建连接和命令来更新table中的数据
MapInfo.Data.MIConnectionconnection=newMapInfo.Data.MIConnection();
connection.Open();
MapInfo.Data.MICommandcommand=connection.CreateCommand();
command.CommandText="update"+layerName+"setobj=obj,MI_Style=@style";
command.Parameters.Add("@style",compositeStyle);
command.Prepare();
command.ExecuteNonQuery();
//关闭连接
command.Cancel();
command.Dispose();
connection.Close();
connection.Dispose();
}
/**////<summary>
///创建style
///</summary>
///<paramname="opaqueType">不透明类型:ALL全部不透明(白色实心);BORDER边界不透明(填充部分透明);NONE全透明</param>
///<paramname="borderColor">如果opaqueType=BORDER,此处设定边界颜色</param>
///<returns>组合style</returns>
privateMapInfo.Styles.CompositeStyleGetOpaqueStyle(OpaqueTypeopaqueType,System.Drawing.ColorborderColor)
{
MapInfo.Styles.SimpleInteriorInterior;
if(opaqueType==OpaqueType.ALL)
Interior=newMapInfo.Styles.SimpleInterior();//缺省构造函数是白色实心
else
Interior=newMapInfo.Styles.SimpleInterior(1);//0是线透明,1是面透明
MapInfo.Styles.LineWidthlineWidth=newMapInfo.Styles.LineWidth(1,MapInfo.Styles.LineWidthUnit.Point);
MapInfo.Styles.SimpleLineStyleLineStyle;
if(opaqueType==OpaqueType.ALL)
LineStyle=newMapInfo.Styles.SimpleLineStyle(lineWidth);
elseif(opaqueType==OpaqueType.BORDER)
LineStyle=newMapInfo.Styles.SimpleLineStyle(lineWidth,2,borderColor);//2表示填充透明,即能够显示轮廓
else
LineStyle=newMapInfo.Styles.SimpleLineStyle(lineWidth,0);//0表示全部透明,即连轮廓都看不到
MapInfo.Styles.AreaStyleareaStyle=newMapInfo.Styles.AreaStyle(LineStyle,Interior);
MapInfo.Styles.CompositeStylecompositeStyle=newMapInfo.Styles.CompositeStyle(areaStyle,null,null,null);
returncompositeStyle;
}
7 选择全部图元
MapInfo.Engine.Session.Current.Catalog.Search( table, MapInfo.Data.SearchInfoFactory.SearchAll(), MapInfo.Engine.Session.Current.Selections.DefaultSelection, MapInfo.Data.ResultSetCombineMode.Replace);8 设置坐标系
缺省情况下,MapXtreme使用的CoordSys是经纬度投影(LongLat)和WGS84基准面。我想修改投影类型为 CoordSysType.TransverseMercator ,基准面为DatumID.Pulkovo1942
MapInfo.Geometry.CoordSysFactory coordSysFactory=MapInfo.Engine.Session.Current.CoordSysFactory;
mapControl1.Map.SetDisplayCoordSys(coordSysFactory.CreateCoordSys("mapinfo:coordsys 8,1001,7,117,0,1,20500000,0"));
coordSysFactory.CreateCoordSys("mapinfo:coordsys 8,1001,7,117,0,1,20500000,0") 默认的原点是(B=0,L=117),如果要把原点设在(23,117)应该怎么写这个字符串呢?
coordSysFactory.CreateCoordSys("mapinfo:coordsys 8,1001,7,114,23,1,20500000,25000000")
9 保存新画的层为tab文件
下面的源码是新建一个永久表,然后在表中添加feature,然后保存为硬盘上的tab文件。
privateMapInfo.Data.TableCreateNewMapDataTable(stringtableName)
{
//以下代码是建立永久表
MapInfo.Data.TableInfoNativetableInfoNative=newMapInfo.Data.TableInfoNative(tableName);
tableInfoNative.TablePath=@"D:\DATA\"+tableName+".TAB";
tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("ID"));
tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
MapInfo.Geometry.CoordSyscoordSys=mapControl1.Map.GetDisplayCoordSys();
tableInfoNative.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(coordSys));
MapInfo.Data.Tabletable=MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfoNative);
//以下代码是建立临时表
//MapInfo.Data.TableInfotableInfo=MapInfo.Data.TableInfoFactory.CreateTemp(tableName);
//tableInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("ID"));
//MapInfo.Data.Tabletable=MapInfo.Engine.Session.Current.Catalog.CreateTable(tableInfo);
MapInfo.Mapping.FeatureLayerfeatureLayer=newMapInfo.Mapping.FeatureLayer(table);
this.mapControl1.Map.Layers.Add(featureLayer);
returntable;
}
privatevoidAddFeaturesAndSave()
{
MapInfo.Styles.SimpleLineStyleLineStyle=newMapInfo.Styles.SimpleLineStyle(newMapInfo.Styles.LineWidth(1,MapInfo.Styles.LineWidthUnit.Point));
MapInfo.Styles.CompositeStylecompositeStyle=newMapInfo.Styles.CompositeStyle(null,LineStyle,null,null);
MapInfo.Geometry.CoordSyscoordSys=mapControl1.Map.GetDisplayCoordSys();
MapInfo.Data.Tabletable=CreateNewMapDataTable("NewTable");
MapInfo.Data.TableInfotableInfo=table.TableInfo;
while(……)
{
MapInfo.Data.Featurefeature=newMapInfo.Data.Feature(tableInfo.Columns);
feature.Geometry=……
feature.Style=……
feature["ID"]=……
table.InsertFeature(feature);
}
tableInfo.WriteTabFile();//保存为.tab文件
mapControl1.Refresh();
}
10 计算缩放比例
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-27889-1.html
灭之
鄙视质监局
他们那里会知道什么就被撞沉了