ArcEngine labeling and annotation (-)

       Labeling and annotation are two ArcEngine provided in the labeling map features using a text message the way which is marked as the property of a layer of existence, can be created dynamically, annotation is stored as a geographic feature. It should be noted Shp file does not support for annotation drawing marked in two ways let us look first.:

    1. TextElment drawing annotation.

    The principle of this method is the property of the table to create a property TextElment object, and then add annotations using IGraphicsContainer AddElement method of example code:

        // Use TextElment drawing labeled, fieldName property is to be drawn public static void AddLable (AxMapControl axMapControl, the ILayer Layer, String the fieldName)         {             IRgbColor the pColor variable to = new new RgbColorClass ()             {                 Red = 255 ,                 Blue = 0 ,                 Green = 0             };             the IFontDisp pFont = new new StdFont ()             {                 the Name = " Arial " ,











Size
= 5
}
as IFontDisp;
 
            ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color
= pColor,
Font
= pFont,
Size
= 11
};

IGraphicsContainer pGraContainer
= axMapControl.Map as IGraphicsContainer;

//遍历要标注的要素
IFeatureLayer pFeaLayer = layer as IFeatureLayer;
IFeatureClass pFeaClass
= pFeaLayer.FeatureClass;
IFeatureCursor pFeatCur
=pFeaClass.Search ( null , to false );
IFeature pFeature
= pFeatCur.NextFeature ();
int index = pFeature.Fields.FindField (the fieldName); // index of the field to be labeled IEnvelope PenV = null ; ITextElement pTextElment = null ; IElement PELE = null ; the while (pFeature ! = null ) { // use the geographic center of the object as the position marked PenV = pFeature.Extent;







IPoint pPoint
= new PointClass();
pPoint.PutCoords(pEnv.XMin
+ pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);

pTextElment
= new TextElementClass()
{
Symbol
= pTextSymbol,
ScaleText
= true,
Text
= pFeature.get_Value(index).To\String()
};
pEle
= pTextElment as IElement;
pEle.Geometry
= pPoint;
//添加标注
pGraContainer.AddElement(pEle, 0);
pFeature
= pFeatCur.NextFeature();
}
(axMapControl.Map
as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, axMapControl.Extent);
}

     2. Use ArcEngine label objects in the mouth .LabelEngineLayerProperties to label features

        IGeoFeatureLayer in AnnotationProperties is denoted by a set of objects comprising the LabelEngineLayerProperties LabelEngineLayerProperties achieved:

     IAnnotateProperties,   // 
IAnnotateLayerProperties, // you can control the display scale labels, filters, etc. ILabelEngineLayerProperties, IAnnotateLayerTransformationProperties // control labeled reference scale, units, labels and border and zoom ratio

And several other major .LabelEngineLayerProperties interface can operate a plurality of label attributes and behavior of elements, such as the text of the label position, dimensioning, setup script, text, symbols, etc. This class implements a large number of properties and methods of labeling operations, complex the label is very useful, but TextElment suitable for simple labeling.  ILabelEngineLayerProperties2 is the primary interface LabelEngineLayerPropertiesClass his Expression and IsExpressionSimple used as follows:

        IsExpressionSimple = true, Expression simple expression of the form: "[" property field + name + "]" + other,

        IsExpressionSimple = true = false, Expression complex expressions, its content is a character string, but a complete VBScript or JScript function or expression.

 ExpressionParser property is an Expression parser, which supports more complex and Vbs JS code.

  

        // add annotation, more powerful than TextElment public static void AddAnnotate (the ILayer Layer, String the fieldName)         {             IGeoFeatureLayer pGeoLayer = Layer AS IGeoFeatureLayer;             IAnnotateLayerPropertiesCollection IPALPColl = pGeoLayer.AnnotationProperties;             IPALPColl.Clear ();             IRgbColor the pColor variable to = the GetColor ( 255 , 0 , 0 , 255 );             the IFontDisp pFont = new new StdFont ()             {









Name
= " Arial " , Bold Font = to true } AS the IFontDisp; ITextSymbol pTextSymbol = new new TextSymbolClass () { Color = the pColor variable to, the Font = pFont, Size = 12 is }; // for controlling relative positional relationship between labels and elements ILineLabelPosition pLineLpos = new new LineLabelPositionClass () { Parallel =













to false , // modify the properties marked Perpendicular = to true , InLine = to true }; // for controlling denoted conflict ILineLabelPlacementPriorities pLinePlace = new new LineLabelPlacementPrioritiesClass () { AboveStart = . 5 , // so that priority is above and start. 5 BelowAfter = . 4 }; // used to achieve control of ILineLabelPosition and ILineLabelPlacementPriorities and higher property IBasicOverposterLayerProperties pBOLP =










new BasicOverposterLayerPropertiesClass()
{
FeatureType
= esriBasicOverposterFeatureType.esriOverposterPolygon,
LineLabelPlacementPriorities
= pLinePlace,
LineLabelPosition
= pLineLpos
};

//创建标注对象
ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass()
{
Symbol
= pTextSymbol,
BasicOverposterLayerProperties
= pBOLP,
IsExpressionSimple
= to true ,
the Expression
= " [ " + the fieldName + " ] " }; // set the reference scale marked IAnnotateLayerTransformationProperties pAnnoLyrPros = pLableEngine AS IAnnotateLayerTransformationProperties; pAnnoLyrPros.ReferenceScale = 2500000 ; // set the minimum and maximum scale labels visible IAnnotateLayerProperties pAnnoPros = pLableEngine AS IAnnotateLayerProperties ; pAnnoPros.AnnotationMaximumScale = 2500000








;
PAnnoPros.AnnotationMinimumScale
= 25000000 or ; // pAnnoPros.WhereClause property set filters IPALPColl.Add (pAnnoPros); pGeoLayer.DisplayAnnotation = to true ; }




  


Reproduced in: https: //www.cnblogs.com/LoveLyre/archive/2011/09/10/2173310.html

Guess you like

Origin blog.csdn.net/weixin_34168880/article/details/92840838