ArcEngine 水平分子式标注

在ArcMap中,实现水平分子式标注的方法是在Label Expression中选中Advanced,输入如下VBA代码:

Function FindLabel ( [FieldName1] , [FieldName2]  )
  FindLabel = [FieldName1] &chr(13)&"———————————"&chr(13)& [FieldName2]
End Function

或者:

Function FindLabel ( [FieldName1] , [FieldName2]  )
  FindLabel = "<und>"&"      "&[FieldName1] &"     "&"</und>"& vbcrlf &[FieldName2]
End Function


注释:方法一中 chr(13)表示换行,间隔线表示分母线,&为VBScript连接字符,分母线的长短用间隔数表示,

                    也就是       字段1,换行,分母线,换行,字段2

        方法二中 <und>  </und>表示下划线,vbclf表示换行,分母线的长短用空格数表示,

                    也就是       加下划线的字段1,换行,字段2

       最后,分子和分母与分母线的间隔,可通过(TextSymbol)Symbol—>(Symbol Selector)Propertie—>(Editor)Formatting Text中的Leading调节。

在ArcEngine中,实现代码如下所示:

                IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
               
                ITextSymbol textSymbol = new ESRI.ArcGIS.Display.TextSymbol();
                if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    continue;
                }
                else if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    textSymbol.Color = ((geoFeatureLayer.Renderer as ISimpleRenderer).Symbol as ILineSymbol).Color;
                }
                else if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    textSymbol.Color = ((geoFeatureLayer.Renderer as ISimpleRenderer).Symbol as IMarkerSymbol).Color;
                }
                textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;

                ILabelEngineLayerProperties2 pLelp = new LabelEngineLayerPropertiesClass();
                pLelp.IsExpressionSimple = false;
                pLelp.Symbol = textSymbol;
                IAnnotationExpressionEngine AnnExpEng = new AnnotationVBScriptEngineClass();
                pLelp.ExpressionParser = AnnExpEng;

                //方法一
                //pLelp.Expression = "Function FindLabel (" + "[编号]" + ", " + "[编号备注]" + ") \n " +
                //    "  FindLabel = " + "[编号]" + "&chr(13)" +"&\"——————————\""+ "&chr(13)" + "&[编号备注]" + "\n  End Function";
                //方法二
                pLelp.Expression = "Function FindLabel (" + "[编号]" + ", " + "[编号备注]" + ") \n " +
                   "  FindLabel = " + "\"<und>\"" + "&\"   \"" + "&[编号]" + "&\"   \"" + "&\"</und>\"" + " &vbcrlf " + "&[编号备注]" + "\n  End Function";

                IBasicOverposterLayerProperties pBasicOverposterLayerProperties = pLelp.BasicOverposterLayerProperties;                  
                pBasicOverposterLayerProperties.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
                 //水平标注
                ILineLabelPosition linelabelPosition;
                linelabelPosition = new LineLabelPositionClass();
                 linelabelPosition.Horizontal = true;
                 linelabelPosition.Above = false;
                 linelabelPosition.Parallel = false;
                 linelabelPosition.Perpendicular = false;
                 linelabelPosition.InLine = true;
                 linelabelPosition.Below = false;
                 linelabelPosition.OnTop = true;
                 pBasicOverposterLayerProperties.LineLabelPosition = linelabelPosition;
                
                pLelp.BasicOverposterLayerProperties = pBasicOverposterLayerProperties;
                pBasicOverposterLayerProperties.LabelWeight = esriBasicOverposterWeight.esriHighWeight;

                IAnnotateLayerProperties alps = (IAnnotateLayerProperties)pLelp;                
                alps.DisplayAnnotation = true;
                alps.FeatureLayer = geoFeatureLayer;
                alps.LabelWhichFeatures = esriLabelWhichFeatures.esriAllFeatures;
                
                geoFeatureLayer.AnnotationProperties.Clear();
                geoFeatureLayer.AnnotationProperties.Add(alps);
                geoFeatureLayer.DisplayAnnotation = true;              
               
                System.Runtime.InteropServices.Marshal.ReleaseComObject(textSymbol);

转载于:https://www.cnblogs.com/St_Dlng/archive/2011/12/02/2271813.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值