添加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& ...
随机推荐
- 关于spring boot jar包与war包的问题
此文为转载:http://mrlee23.iteye.com/blog/2047968 在开发调试完成之后,可以将应用打成JAR包的形式,在Eclipse中可以直接使用Maven插件的package命 ...
- CS0012: 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义
entity framework,没在view引用 实体对象时,一直没问题,引用后爆出这个错误来 CS0012: 类型"System.Data.Objects.DataClasses.En ...
- 第二章 Mybatis代码生成工具
1.mybatis-generator作用 1).生成pojo 与 数据库结构对应 2).如果有主键,能匹配主键 3).如果没有主键,可以用其他字段去匹配 4).动态select,update,del ...
- MySQL数据库设置远程访问权限方法总结
1,设置访问单个数据库权限 mysql>grant all privileges on test.* to 'root'@'%'; 说明:设置用户名为root,密码为空,可访问数据库test 2 ...
- [python] 创建临时文件-tempfile模块
This module generates temporary files and directories. It works on all supported platforms.In versio ...
- [linux] 结构化命令-for
1 for命令 # for:迭代循环:默认空格为分隔符 for var in list do commands done 1.1 读取列表中的值 #!usr/bin/bash for test in ...
- Eclipse导入Maven项目,使用server 启动报错,class 找不到,
问题发现: 1.导入maven 项目后,用server 启动,选择项中没有这个项目 解决: 说明server 没有把该项目当成web项目,需要设置 项目右键 properties ---- proj ...
- spring mvc 工作流程
Spring Web MVC 处理Http请求的大致过程:一旦Http请求到来,DispatcherSevlet将负责将请求分发.DispatcherServlet可以认为是Spring提供的前端控制 ...
- UVa 11292 Dragon of Loowater
简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...
- 【线段树】bzoj1756 Vijos1083 小白逛公园
我们知道,求一段序列的最大子段和是O(n)的,但是这样是显然会超时的. 我们需要一个数据结构来支持修改和计算的操作,对于这种修改一个而查询区间的问题,考虑使用线段树. 在线段树中,除了左端点,右端点, ...