您的位置:首页 > 其它

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: