---
title: "添加标注图层"
author: "seven7680"
date: "2009-03-30T16:08:49Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2009-03-30T16:08:49Z"
id: 357733
url: "https://seven7680.iteye.com/blog/357733"
---

在MapXtreme 2005中添加标注图层是非常容易的，只要知道要标准的表和相关的列，几行代码就搞定了，比想像中要容易多了。当然还有一些标注样式可以设置，可以从类库中查到相关的说明。 复制内容到剪贴板 代码: /// /// 添加标注图层 /// 2008年8月6日 /// 标注的表名 /// 标注的列名 /// 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; }