关闭

ArcGIS Engine标注(Label)

标签: enginearcgis
2047人阅读 评论(1) 收藏 举报
分类:

Maplex类型标注是AE标注的其中一种方式,现提供一简单使用例子
转自:http://www.cnblogs.com/cannel/archive/2011/03/24/1993383.html

/// <summary>
        /// MaplexEngine标注
        /// </summary>
        /// <param name="pGeoFeatLyr">标注图层</param>
        /// <param name="pMap">地球人都知</param>
        /// <param name="annoField">标记字段</param>
         public void Annotation(IGeoFeatureLayer pGeoFeatLyr, IMap pMap, string annoField)
        {

            //如果Map没有用Maplex引擎,要先设置Map使用这个引擎
            //IAnnotateMap pAnnotateMap;
            //pAnnotateMap = new MaplexAnnotateMapClass();
            //pMap.AnnotationEngine = pAnnotateMap;

            IAnnotateMap pAnnoMap;
            pAnnoMap = new MaplexAnnotateMapClass();
            pMap.AnnotationEngine = pAnnoMap;
            IGeoFeatureLayer pGeoFeatLayer;
            pGeoFeatLayer = pGeoFeatLyr;
            IAnnotateLayerPropertiesCollection pAnnoProps;
            pAnnoProps = pGeoFeatLyr.AnnotationProperties;
            pAnnoProps.Clear();
            ILabelEngineLayerProperties2 pLabelEngine2 = new MaplexLabelEngineLayerPropertiesClass();
            pLabelEngine2.Expression = "[" + annoField + "]";

            IMaplexOverposterLayerProperties pMaplexPro = new MaplexOverposterLayerPropertiesClass();
            pMaplexPro.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
            pMaplexPro.PolygonPlacementMethod = esriMaplexPolygonPlacementMethod.esriMaplexHorizontalInPolygon;
            pMaplexPro.CanPlaceLabelOutsidePolygon = false;
            pMaplexPro.CanRemoveOverlappingLabel = false;
            pMaplexPro.RepeatLabel = false;
            pLabelEngine2.OverposterLayerProperties = pMaplexPro as IOverposterLayerProperties;
            IMapOverposter pMapPos = axMapControl1.Map as IMapOverposter;
            IOverposterProperties pOP = pMapPos.OverposterProperties;
            IMaplexOverposterProperties pMaplexOP = pOP as IMaplexOverposterProperties;
            pMaplexOP.LabelLargestPolygon = false;
            pAnnoProps.Add(pLabelEngine2 as IAnnotateLayerProperties);
            pGeoFeatLyr.DisplayAnnotation = true;
        }

方法二:
转自:http://blog.csdn.net/chanyinhelv/article/details/8845466

        public void EnableFeatureLayerLabel(IFeatureLayer pFeaturelayer, string sLableField, IRgbColor pRGB, int size, string angleField)
        {
            //判断图层是否为空
            if (pFeaturelayer == null)
                return;
            IGeoFeatureLayer pGeoFeaturelayer = (IGeoFeatureLayer)pFeaturelayer;
            IAnnotateLayerPropertiesCollection pAnnoLayerPropsCollection;
            pAnnoLayerPropsCollection = pGeoFeaturelayer.AnnotationProperties;
            pAnnoLayerPropsCollection.Clear();

            //stdole.IFontDisp  pFont; //字体
            ITextSymbol pTextSymbol;

            //pFont.Name = "新宋体";
            //pFont.Size = 9;
            //未指定字体颜色则默认为黑色
            if (pRGB == null)
            {
                pRGB = new RgbColorClass();
                pRGB.Red = 0;
                pRGB.Green = 0;
                pRGB.Blue = 0;
            }

            pTextSymbol = new TextSymbolClass();
            pTextSymbol.Color = (IColor)pRGB;
            pTextSymbol.Size = size; //标注大小

            IBasicOverposterLayerProperties4 pBasicOverposterlayerProps4 = new BasicOverposterLayerPropertiesClass();
            switch (pFeaturelayer.FeatureClass.ShapeType)//判断图层类型
            {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                    pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
                    break;
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                    pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;
                    break;
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                    pBasicOverposterlayerProps4.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;
                    break;
            } 
            pBasicOverposterlayerProps4.PointPlacementMethod = esriOverposterPointPlacementMethod.esriRotationField;
            pBasicOverposterlayerProps4.RotationField = angleField;

            ILabelEngineLayerProperties pLabelEnginelayerProps = new LabelEngineLayerPropertiesClass(); 
            pLabelEnginelayerProps.Expression = "[" + sLableField + "]";
            pLabelEnginelayerProps.Symbol = pTextSymbol;
            pLabelEnginelayerProps.BasicOverposterLayerProperties = pBasicOverposterlayerProps4 as IBasicOverposterLayerProperties;
            pAnnoLayerPropsCollection.Add((IAnnotateLayerProperties)pLabelEnginelayerProps);
            pGeoFeaturelayer.DisplayAnnotation = true;//很重要,必须设置 
            //axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }
        }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:248782次
    • 积分:3431
    • 等级:
    • 排名:第9780名
    • 原创:64篇
    • 转载:157篇
    • 译文:0篇
    • 评论:21条
    文章分类
    最新评论