添加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& ...
随机推荐
- Android学习---通过内容提供者(ContentProvider)操作另外一个应用私有数据库的内容
一.什么是ContentProvider? ContentProvider直译过来就是内容提供者,主要作用就是A应用提供接口给B应用调用数据,和之前介绍的sharedPreference和直接开放文件 ...
- [翻译]:怎样从C/C++代码中对C#进行回调
声明:网络上类似的中文博客大有存在,本人知识水平有限,业余爱好,也是为了备份收藏How to make a callback to C# from C/C++ code 本着共享知识的初衷,翻译一份给 ...
- Merge Intervals 运行比较快
class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...
- Linux系统编程重要细节记录(持续更新中)
1.在打印rlim_t值时,需要将其转换为long long并使用%lld printf()修饰符.
- REDIS源码中一些值得学习的技术细节02
Redis中散列函数的实现: Redis针对整数key和字符串key,采用了不同的散列函数 对于整数key,redis使用了 Thomas Wang的 32 bit Mix Function,实现了d ...
- Oracle 学习方法
参考书籍: oracle实用教程 pdf 深入浅出Oracle: DBA入门.进阶与诊断案例.pdf Oracle 认证 Dba 认证: Oca oracle 初级dba 认证(容易) Ocp o ...
- Android studio debug模式获取变量的值
打断点.debug模式运行,Console界面旁边的Debugger界面,或者在变量上右键add to watches
- AC算法 及python实现
零 导言 软件安全课上,老师讲了AC算法,写个博客,记一下吧. 那么AC算法是干啥的呢? ——是为了解决多模式匹配问题.换句话说,就是在大字符串S中,看看小字符串s1, s2,...有没有出现. AC ...
- base64格式的图片如何上传到oss
---恢复内容开始--- 对于base64图片的上传这个东西,一直是一个问题尤其是上传到oss.我们这次开发由于需要修剪图片,使用了h5的很多新特性. h5修剪图片,使用了我们的canvas.这个步骤 ...
- [C#.net] SendMessage
函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. 函数原型:LRESU ...