添加Labels的两种方法
private void AddLabel(IFeatureLayer pLayer,string fieldname,ITextSymbol Symbol)
{ container.DeleteAllElements(); IFeatureClass pClass = pLayer.FeatureClass;
IFields pFields = pClass.Fields;
int index = pFields.FindField(fieldname); ITextElement pTextElement;
IEnvelope pEnv = null;
IElement pElement = null;
//pTextElement.ScaleText = true;
//pTextElement.Symbol = Symbol; IFeatureCursor pCursor = pClass.Search(null, false);
IFeature pFeature;
IPoint point;
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
pEnv = pFeature.Extent;
point = new PointClass();
point.PutCoords((pEnv.XMin + pEnv.XMax) * 0.5, (pEnv.YMax + pEnv.YMin) * 0.5); pTextElement = new TextElementClass();
pTextElement.Symbol = Symbol;
pTextElement.ScaleText = true;
pTextElement.Text = pFeature.get_Value(index).ToString(); pElement = pTextElement as IElement;
pElement.Geometry = point; container.AddElement(pElement, 0);
pFeature = pCursor.NextFeature();
}
axMapControl1.Refresh();
}
以上为第一种方法,另一种方法(利用提供的接口):
private void Label(IFeatureLayer pLayer, string fieldname, ITextSymbol Symbol)
{
IGeoFeatureLayer pGeoFeaturelayer = pLayer as IGeoFeatureLayer;
IAnnotateLayerPropertiesCollection annotLayercol = pGeoFeaturelayer.AnnotationProperties;
annotLayercol.Clear(); IBasicOverposterLayerProperties basicoverPost = new BasicOverposterLayerPropertiesClass();
basicoverPost.BufferRatio = 0.2;
switch (pLayer.FeatureClass.ShapeType)
{
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
basicoverPost.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
basicoverPost.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
break;
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
basicoverPost.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
break; }
ILabelEngineLayerProperties pLabelEngine = new LabelEngineLayerPropertiesClass();
pLabelEngine.Expression = "[" + fieldname + "]";
pLabelEngine.Symbol = Symbol;
pLabelEngine.BasicOverposterLayerProperties = basicoverPost; annotLayercol.Add((IAnnotateLayerProperties)pLabelEngine);
pGeoFeaturelayer.DisplayAnnotation = true;
axMapControl1.Refresh();
}
最后调用:
private void labelFeatureToolStripMenuItem_Click(object sender, EventArgs e)
{
//MessageBox.Show(PropertiesForm.FieldName);
IFeatureLayer layer = axMapControl1.CustomProperty as IFeatureLayer; IGeoFeatureLayer pGeoFeaturelayer = layer as IGeoFeatureLayer;
IAnnotateLayerPropertiesCollection annotLayercol = pGeoFeaturelayer.AnnotationProperties; string fieldname = PropertiesForm.FieldName;
ITextSymbol symbol = PropertiesForm.TextSymbol; if (show == false)
{ //AddLabel(layer, "XZQMC", symbol);
Label(layer, fieldname, symbol);
show = true;
MessageBox.Show("插入成功!");
} else
{
annotLayercol.Clear();
//container.DeleteAllElements();
show = false; axMapControl1.Refresh();
}
}
添加Labels的两种方法的更多相关文章
- Linux添加系统调用的两种方法
前言 系统调用的基本原理 系统调用其实就是函数调用,只不过调用的是内核态的函数,但是我们知道,用户态是不能随意调用内核态的函数的,所以采用软中断的方式从用户态陷入到内核态.在内核中通过软中断0X80, ...
- unity3d为对象添加脚本的两种方法
首先添加一个物体,然后新建一个C#脚本.接下去有两种方法把C#脚本与物体绑定. 1.在类声明上方添加如下代码: [AddComponentMenu("a/b")] 这句话表示在该物 ...
- 关于MySQL中添加数据的两种方法
下面介绍两种执行SQL命令的方法,并作出相应地总结,第一种介绍一种常规用法,下面进行做简要地分析,首先我们需要执行打开数据库操作首先创建一个MySqlConnection对象,在其构造函数中传入一个连 ...
- view添加毛玻璃效果两种方法
第一种方法: UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectV ...
- Cocos Creator 为Button添加事件的两种方法
Button添加事件 Button 目前只支持 Click 事件,即当用户点击并释放 Button 时才会触发相应的回调函数.通过脚本代码添加回调方法一这种方法添加的事件回调和使用编辑器添加的事件回调 ...
- Cocos Creator EditBox(编辑框/输入框)添加事件的两种方法
EditBox添加事件方法一这种方法添加的事件回调和使用编辑器添加的事件回调是一样的,通过代码添加, 你需要首先构造一个 cc.Component.EventHandler 对象,然后设置好对应的 t ...
- Cocos Creator scrollview添加事件的两种方法
scrollview添加事件 方法一这种方法添加的事件回调和使用编辑器添加的事件回调是一样的,通过代码添加, 你需要首先构造一个 cc.Component.EventHandler 对象,然后设置好对 ...
- (转载)MySQl数据库-批量添加数据的两种方法
方法一:使用excel表格 方法二:使用insert语句(FileWriter批量写入) 使用excel表格 1.打开数据表,按照表的字段在excel中添加数据.注意:表中字段名必须和excel中的名 ...
- WPF中RichTextBox中添加文字的两种方法
RichTextBox控件不同于TextBox控件,后者可以直接通过其Text属性绑定或者在后台动态添加文字. (一)使用数据绑定 <RichTextBox FontSize="12& ...
随机推荐
- curl 模拟登录微信公众平台带验证码
这段时间一直写个项目, 从切图到前端到后台都要搞定,真tm累. 今天下午手残,不停用错误的密码去模拟登录微信公众平台,结果后来出现验证码,瞬间悲剧(菜鸟从来没搞过带验证码的). 研究了一下,发现其实很 ...
- 拼图 canvas分割 dom拖拽 pc 移动端
参考:Canvas drag 实现拖拽拼图小游戏 参考的案例,不支持手机端.总结下实现过程中遇到的小坑. gitHub:https://github.com/WppFrontEnd/puzzle 大概 ...
- MySQL命令实例
显示数据表结构 1.desc(describe) tablename;2.show columns from tablename;3.use information_schema; select ...
- sql 将8位字符串转换成日期型
将8位字符串转换成日期型,方法如下: ),)
- composer 安装
安装composer wget http://curl.haxx.se/ca/cacert.pem curl -sS https://getcomposer.org/installer | php - ...
- My安卓知识2--使用listview绑定sqlite中的数据
我想在我的安卓项目中实现一个这样的功能,读取sqlite数据库中的数据并显示到某个页面的listview控件中. 首先,我建立了一个Service类,来实现对数据库的各种操作,然后在这个类中添加对数据 ...
- Matlab(2) -- Find()函数
转自:http://www.matlabsky.com/thread-4228-1-1.html find函数:用于查询非零元素的行和列标志 语法: ind = find(X) ind = find( ...
- ceph实践: 搭建环境
作者:吴香伟 发表于 2014/09/26 版权声明:可以任意转载,转载时务必以超链接形式标明文章原始出处和作者信息以及版权声明 本节主要参考官网的ADDING/REMOVING OSDS章节. 同步 ...
- Python list列表的排序
当我们从数据库中获取一写数据后,一般对于列表的排序是经常会遇到的问题,今天总结一下python对于列表list排序的常用方法: 第一种:内建函数sort() 这个应该是我们使用最多的也是最简单的排序函 ...
- java问卷
1.你对自己的未来有什么规划?做了那些准备? 对于每个人来讲只有一次,七八十年的时间是一个即漫长然而又很短暂的过程,对于漫长与短暂的看法,由于每个人所处的环境的不同以及对人生看法的不同而有所差异.痛苦 ...