arcEngine添加标注(上)
2015-10-29 19:30
405 查看
arcEngine添加标注有3个技术点:1,获得图层的属性字段;2,初始化符号显示控件;3,添加标注。
获得图层的属性字段:
//每个图层都是一个表的图形化显示,ILayer跟ITale可以互相转换
ITable pTable = pLayer as ITable;
IField pField = null;
for (int i = 0; i < pTable.Fields.FieldCount; i++)
{
pField = pTable.Fields.get_Field(i);
//下面3种类型的字段不能显示
if(pField.Type!=esriFieldType.esriFieldTypeXML&&
pField.Type!=esriFieldType.esriFieldTypeRaster&&pField.Type!=esriFieldType.esriFieldTypeGeometry)
cmbField.Items.Add(pField.AliasName);
}
初始化符号显示控件:
string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path; //获得arcgis的安装路径
axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle"); //打开样式文件
//显示文字符号(esriStyleClassTextSymbols)
axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassTextSymbols).SelectItem(0);
添加标注:
IGeoFeatureLayer geoFeatureLayer = pLayer as IGeoFeatureLayer;
//AnnotationProperties属性控制标注的内容、格式
geoFeatureLayer.AnnotationProperties.Clear();
//标注放置的位置
IBasicOverposterLayerProperties blProperty = new BasicOverposterLayerPropertiesClass();
ILabelEngineLayerProperties llProperty = new LabelEngineLayerPropertiesClass();
ITextSymbol textSymbol = new TextSymbolClass();
textSymbol = (ITextSymbol)styleGalleryItem.Item;
IColor ic = new RgbColorClass();
ic.RGB = colorPickerButton1.SelectedColor.B * 65536 + colorPickerButton1.SelectedColor.G * 256 + colorPickerButton1.SelectedColor.R;
textSymbol.Color = ic;
stdole.IFontDisp tempFont = new stdole.StdFont() as stdole.IFontDisp;
tempFont.Name = cmbFont.SelectedNode.Text;
DevComponents.Editors.ComboItem cmbItem = (DevComponents.Editors.ComboItem)cmbSize.SelectedItem;
tempFont.Size = Convert.ToDecimal(cmbItem.Text);
textSymbol.Font = tempFont;
textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
//标注内容表达式
string pLabel = "[" + (string)cmbField.SelectedItem + "]";
llProperty.Expression = pLabel;
//复杂表达式,下次博客内容
if (cmbField.SelectedIndex == cmbField.Items.Count - 1)
{
llProperty.IsExpressionSimple = false;
IAnnotationExpressionEngine annoEE = new AnnotationJScriptEngine();
llProperty.ExpressionParser = annoEE;
llProperty.Expression = fieldExpression;
}
//llProperty.ExpressionParser
blProperty.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
llProperty.BasicOverposterLayerProperties = blProperty;
llProperty.Symbol = textSymbol;
geoFeatureLayer.AnnotationProperties.Add(llProperty as IAnnotateLayerProperties);
geoFeatureLayer.DisplayAnnotation = true;
pMap.Refresh();
获得图层的属性字段:
//每个图层都是一个表的图形化显示,ILayer跟ITale可以互相转换
ITable pTable = pLayer as ITable;
IField pField = null;
for (int i = 0; i < pTable.Fields.FieldCount; i++)
{
pField = pTable.Fields.get_Field(i);
//下面3种类型的字段不能显示
if(pField.Type!=esriFieldType.esriFieldTypeXML&&
pField.Type!=esriFieldType.esriFieldTypeRaster&&pField.Type!=esriFieldType.esriFieldTypeGeometry)
cmbField.Items.Add(pField.AliasName);
}
初始化符号显示控件:
string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path; //获得arcgis的安装路径
axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle"); //打开样式文件
//显示文字符号(esriStyleClassTextSymbols)
axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass.esriStyleClassTextSymbols).SelectItem(0);
添加标注:
IGeoFeatureLayer geoFeatureLayer = pLayer as IGeoFeatureLayer;
//AnnotationProperties属性控制标注的内容、格式
geoFeatureLayer.AnnotationProperties.Clear();
//标注放置的位置
IBasicOverposterLayerProperties blProperty = new BasicOverposterLayerPropertiesClass();
ILabelEngineLayerProperties llProperty = new LabelEngineLayerPropertiesClass();
ITextSymbol textSymbol = new TextSymbolClass();
textSymbol = (ITextSymbol)styleGalleryItem.Item;
IColor ic = new RgbColorClass();
ic.RGB = colorPickerButton1.SelectedColor.B * 65536 + colorPickerButton1.SelectedColor.G * 256 + colorPickerButton1.SelectedColor.R;
textSymbol.Color = ic;
stdole.IFontDisp tempFont = new stdole.StdFont() as stdole.IFontDisp;
tempFont.Name = cmbFont.SelectedNode.Text;
DevComponents.Editors.ComboItem cmbItem = (DevComponents.Editors.ComboItem)cmbSize.SelectedItem;
tempFont.Size = Convert.ToDecimal(cmbItem.Text);
textSymbol.Font = tempFont;
textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
//标注内容表达式
string pLabel = "[" + (string)cmbField.SelectedItem + "]";
llProperty.Expression = pLabel;
//复杂表达式,下次博客内容
if (cmbField.SelectedIndex == cmbField.Items.Count - 1)
{
llProperty.IsExpressionSimple = false;
IAnnotationExpressionEngine annoEE = new AnnotationJScriptEngine();
llProperty.ExpressionParser = annoEE;
llProperty.Expression = fieldExpression;
}
//llProperty.ExpressionParser
blProperty.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
llProperty.BasicOverposterLayerProperties = blProperty;
llProperty.Symbol = textSymbol;
geoFeatureLayer.AnnotationProperties.Add(llProperty as IAnnotateLayerProperties);
geoFeatureLayer.DisplayAnnotation = true;
pMap.Refresh();
相关文章推荐
- LeetCode 213: House Robber II
- C++primer学习:关于upper_bound和lower_bound的探究.
- iPhone开发 判断当前的网络是3g还是wifi
- Eclipse快捷键
- 求两个数最大公约数
- SPDY 是什么?如何部署 SPDY?
- 重定向和请求转发的区别
- IOS的APP结构、生命周期、main
- 装系统
- 更快学习 JavaScript 的 6 个思维技巧
- ArcEngine栅格和矢量渲染(含可视化颜色带)
- SQL 编码规范
- 经典SQL语句大全
- 从标准输入读取几行输入,每行输入都要打印到标准输出上,前面加上行号
- 原码, 反码, 补码 详解
- multithreading--演示中断线程Thread的异常
- 学习笔记二
- 支付宝的应用+代码
- MetaQ 实例之四
- 时间换算