• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅

ArcEngine 水平分子式标注

文章来源:http://www.cnblogs.com/St_Dlng/archive/2011/12/02/2271813.html 

在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);

posted on 2013-01-10 15:07  bobird  阅读(322)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3