/// <summary>
///创建临时图层
/// <param name="tableName">表名</param>
/// <param name="layerName">图层名</param>
/// </summary>
public static void CreateLayer(string tableName, stringlayerName)
{
MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[0];//取得当前地图
MapInfo.Data.TableInfoMemTable tblInfo = new MapInfo.Data.TableInfoMemTable(tableName);//建立内存表
tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys()));//向表信息中添加必备的可绘图列
tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateIntColumn("index")); //向表信息中添加索引列,用来查找
tblInfo.Columns.Add(MapInfo.Data.ColumnFactory.CreateStringColumn("value", 50)); //创建字符串型的列,用于标注
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);//确保当前目录下不存在同名表
if (table != null)
{
MapInfo.Engine.Session.Current.Catalog.CloseTable(tableName);
}
table = MapInfo.Engine.Session.Current.Catalog.CreateTable(tblInfo);//根据表信息创建临时表
FeatureLayer tempLayer = new FeatureLayer(table, layerName, layerName);//创建图层(并关联表)
//myMap.Layers.Add(tempLayer);
myMap.Layers.Insert(0, tempLayer);//插入新图层到原来图层的最顶端
LabelSource source = new LabelSource(table);//绑定Table
source.DefaultLabelProperties.Caption = "value";//指定哪个字段作为显示标注
//标注样式等属性,指在一定的缩放比例范围内显示文本
//source.DefaultLabelProperties.Visibility.Enabled = true;
//source.DefaultLabelProperties.Visibility.VisibleRangeEnabled = true;
//source.DefaultLabelProperties.Visibility.VisibleRange = new VisibleRange(0.01, 10, MapInfo.Geometry.DistanceUnit.Mile);
source.DefaultLabelProperties.Visibility.AllowDuplicates = true;
//如果其标注属性将该属性设置为 true,即使是和其它较高优先权标注重复的标注也会生成。
source.DefaultLabelProperties.Visibility.AllowOverlap = true;
source.DefaultLabelProperties.Visibility.AllowOutOfView = true;
//如果要标注的图元有部分在视图内,标注引用位置超出当前视图时,设置 AllowOutOfView 为 true 会重新计算标注引用位置。
source.Maximum = 50;
//控制为标注源自动生成的标注的最大数目。
//source.DefaultLabelProperties.Layout.UseRelativeOrientation = true;
//该属性为 true 时,根据原始的参考几何体(要标注的几何体)确定标注的角度。
//source.DefaultLabelProperties.Layout.RelativeOrientation = MapInfo.Text.RelativeOrientation.FollowPath;
//Parallel 绘制的文本与锚定的直线或折线段具有相同的角度。
//FollowPath 文本后跟锚定的折线段的轮廓。
source.DefaultLabelProperties.Layout.Alignment =MapInfo.Text.Alignment.BottomRight;
//CenterCenter 文本在其锚定内居中。
//TopLeft 文本位于其锚定的左上方。
//TopCenter 文本在其锚定上方居中。
//TopRight 文本位于其锚定的右上方。
//CenterLeft 文本在其锚定左侧垂直居中。
//CenterRight 文本在其锚定右侧垂直居中。
//BottomLeft 文本位于其锚定的左下方。
//BottomCenter 文本在其锚定以下居中。
//BottomRight 文本位于其锚定的右下方。
source.DefaultLabelProperties.CalloutLine.Use = false;
//是否使用标注线
//source.DefaultLabelProperties.CalloutLine.Type = CalloutLineType.Simple;
//Use 为 true 时,该属性按照源于已枚举 CalloutLineType 的值确定要使用的标注线类型
//Simple 指示文本使用简单的标注线(没有指向其参考几何体的指针)。
//Arrow 指示文本使用指向其参考几何体的箭头。
//source.DefaultLabelProperties.CalloutLine.Target=
//设置指向的可选位置。 为空时,文本位置按照 Point 由引用位置定义。
//MapInfo.Styles.SimpleLineStyle simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(0); //标注注释线
//source.DefaultLabelProperties.Style.CalloutLine.ApplyStyle(simpleLineStyle);
//source.DefaultLabelProperties.Layout.Angle = 33.0;
source.DefaultLabelProperties.Layout.Offset = 5;//标注偏移
//MapInfo.Styles.Font font = new MapInfo.Styles.Font("黑体", 12);
MapInfo.Styles.Font font = new MapInfo.Styles.Font("宋体", 10);
font.ForeColor =System.Drawing.Color.Red;
source.DefaultLabelProperties.Style.Font =font;
//设置标注
LabelLayer labelLayer = newLabelLayer();
labelLayer.Sources.Append(source);//加载指定数据
myMap.Layers.Add(labelLayer);
}