MapXtreme 2005学习(4):添加标注图层

MapXtreme 2005中添加标注图层是非常容易的,只要知道要标准的表和相关的列,几行代码就搞定了,比想像中要容易多了。当然还有一些标注样式可以设置,可以从类库中查到相关的说明。

    /// <summary>
    /// 添加标注图层
    /// Design by Glacier
    /// 2008年8月6日
    /// <param name="tableName">标注的表名</param>
    /// <param name="columnName">标注的列名</param>
    /// </summary>
    public static void ShowLabelLayer(string tableName, string columnName)
    {
        MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias];
       
        //新建标注图层
        LabelLayer labelLayer = new LabelLayer();
        myMap.Layers.Add(labelLayer);

        //指定要标注的数据表
        LabelSource labelSource = new LabelSource(MapInfo.Engine.Session.Current.Catalog.GetTable(tableName);
        labelLayer.Sources.Append(labelSource);
       
        //指定要标准字段所在的列
        labelSource.DefaultLabelProperties.Caption = columnName;

        //标注样式等属性
        //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;
        //source.DefaultLabelProperties.Visibility.AllowOverlap = true;
        //source.DefaultLabelProperties.Visibility.AllowOutOfView = true;
        //source.Maximum = 50;
        //source.DefaultLabelProperties.Layout.UseRelativeOrientation = true;
        //source.DefaultLabelProperties.Layout.RelativeOrientation = MapInfo.Text.RelativeOrientation.FollowPath;
        //source.DefaultLabelProperties.Layout.Angle = 33.0;
        //source.DefaultLabelProperties.Priority.Major = "index";
        //source.DefaultLabelProperties.Layout.Offset = 7;
        //source.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.BottomRight;
        //Font font = new Font("黑体", 10);
        //font.ForeColor = System.Drawing.Color.DarkBlue;
        //source.DefaultLabelProperties.Style.Font = font;
    }

原文地址:https://www.cnblogs.com/glacierh/p/1262238.html