首页 > 代码库 > 地图标注

地图标注

地图标注:是表示制图对象的名称或数量及质量特征的文字和数字等文字语言。来说明制图对象的名称、种类、性质、和数量等具体特征。

  ArcEngine中注记分为两种:标注(Label)、注记(Annotation)。Annotation以更复杂的方法和属性对要素图层进行标注,这个过程可以是自动的,不需用户干预,而且注记内容可以保存到地图数据库中。

  AnnotationLayerPropertiesCollection对象是一个要素图层的属性,是一个标注集对象的集合。标注集是与某个要素图层相关联的,用于描述要素图层如何被标注,可以通过IGeoFeaturelayer中的AnnotationProperties属性获取。IAnnotationLayerPropertiesCollection接口提供了对保存在集合中的IAnnocationLayerProperties(LabelEngineLayerProperties、MaplexLabelEngineProperties)对象进行操作,通过该接口,开发者可以对集合中的组件进行添加、删除、排序和查询等操作。L        abelEngineLayerProperties对象维持着一个要素图层的注记实例。

  IAnnocationLayerProperties的WhereClause属性用于设置一个SQL语句,确定哪些要素可以被标注。

  AnnotationMaximunScale和AnnotationMinMunScale用于设置文字标注的最大和最小范围。

  LabelEngineLayerProperties对象也实现ILabelEngineLayerProperties接口,提供用于制作过程中的主要属性,设置文字符号、标注文字排放等,其中BasicOverposterLayerProperties用于设置标注文本如何被放置,以及处理文字之间的冲突。IBasicOverposterLayerProperties接口中的LineLabelPlacementPriorities用于设置标注文本的摆放路径的权重,LineLabelPosition用于设置标注文本的排放位置,PointPlacementPriorities用于设置一个与点相关的标注路径的权重等。

 

    class MapMarker    {        private AxMapControl axMapControl;        public MapMarker(AxMapControl _axMapControl)        {            axMapControl = _axMapControl;        }        /// <summary>        /// 使用注记        /// </summary>        /// <param name="pGeoFeatureLyr">要注记的图层</param>        /// <param name="AnnoField">注记内容</param>        public void Annotation(IGeoFeatureLayer pGeoFeatureLyr, string AnnoField)        {            IGeoFeatureLayer pGeoFeatureLayer;//用 GeoFeatureLayer才能操作标注            pGeoFeatureLayer = pGeoFeatureLyr;            IAnnotateLayerPropertiesCollection pAnnoProps;//定义标注集对象的集合            pAnnoProps = pGeoFeatureLyr.AnnotationProperties;            pAnnoProps.Clear();//清除里面的集合,不知道是不是必须的            IAnnotateLayerProperties pAnnoLayerPros;            ILineLabelPosition pPosition;//控制Label相对位置            ILineLabelPlacementPriorities pPlacement;//control placement position priorities for line labels            IBasicOverposterLayerProperties pBasic;//Provides access to members that control the placement of labels relative to features using conflict detection            ILabelEngineLayerProperties pLabelEngine;//可以控制标注的过程中的主要属性,设置文字符号,标注文字排放等            ITextSymbol pTextSymbol;            pTextSymbol = new TextSymbolClass();            stdole.StdFont pFont;//定义字体吧,不知道            pFont = new stdole.StdFontClass();            pFont.Name = "Verdana";            pFont.Size = 10;            pTextSymbol.Font = pFont as stdole.IFontDisp ;            pTextSymbol.Color = HsvColor(250,160,200);            pPosition = new LineLabelPositionClass();            pPosition.Parallel = false;//Label和线平行            pPosition.Perpendicular = true;//Label和线垂直            pPlacement = new LineLabelPlacementPrioritiesClass();            pBasic = new BasicOverposterLayerPropertiesClass();            pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline;            pBasic.LineLabelPlacementPriorities = pPlacement;            pBasic.LineLabelPosition = pPosition;            pLabelEngine = new LabelEngineLayerPropertiesClass();            pLabelEngine.Symbol = pTextSymbol;            pLabelEngine.BasicOverposterLayerProperties = pBasic;            pLabelEngine.Expression = AnnoField;//注记的内容            pAnnoLayerPros = pLabelEngine as IAnnotateLayerProperties;            pAnnoProps.Add(pAnnoLayerPros);            pGeoFeatureLayer.DisplayAnnotation = true;            axMapControl .Refresh (esriViewDrawPhase .esriViewBackground ,null ,null );        }        private HsvColor HsvColor(int hue, int saturation, int val)        {            HsvColor hsvColor;            hsvColor = new HsvColorClass();            hsvColor.Hue = hue;            hsvColor.Saturation = saturation;            hsvColor.Value = val;            return hsvColor;        }    }

 

示例代码

示例1

Maplex类型标注是AE标注的其中一种方式,现提供一简单使用例子 . 转自:LINK

        /// <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;        }

 

示例2, LINK

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

 

 

 

 

 

 

参考文章

ArcGIS Engine标注(Label)

 

地图标注