You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Label Features   Justin Peterson Feb 03, 2002
Re: Label Features   Kirk Kuykendall Feb 03, 2002
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Label Features 
Author Justin Peterson 
Date Feb 03, 2002 
Message I am using the below code to label a point layer. I need to change the method to "Label the features the same way". Is there somewhere in this code I can do this? Also, how do I change the size of the font that will be used to label? 
 
Sub ArcText()
    ' tested with USHighways shape file in layer(0)
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pGFLayer As IGeoFeatureLayer
    Set pGFLayer = pMxDoc.FocusMap.Layer(0)
    
    pGFLayer.AnnotationProperties.Clear
                
    Dim pLLP As ILineLabelPosition
    Set pLLP = New LineLabelPosition
    With pLLP
        .Above = False
        .AtEnd = False
        .Below = False
        .Horizontal = False
        .InLine = True
        .OnTop = True
        .Parallel = True
        .ProduceCurvedLabels = False
    End With
        
    Dim pLELP As ILabelEngineLayerProperties
    Set pLELP = New LabelEngineLayerProperties
    With pLELP
        Set .Symbol = New TextSymbol
        .IsExpressionSimple = True
        .Expression = "[rsd111wpt.WAYPOINTNO]"
        .BasicOverposterLayerProperties.LineLabelPosition = pLLP
    End With
    
    Dim pALP As IAnnotateLayerProperties
    Set pALP = pLELP
    With pALP
        .DisplayAnnotation = True
        Set .FeatureLayer = pGFLayer
        .LabelWhichFeatures = esriVisibleFeatures
        .WhereClause = "rsd111wpt.WAYPOINTNO"
    End With
    
    pGFLayer.AnnotationProperties.add pLELP
    pGFLayer.DisplayAnnotation = True
    pMxDoc.ActiveView.Refresh
    
End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Features 
Author Kirk Kuykendall 
Date Feb 03, 2002 
Message The only way I see it to do "label all features the same way" is to omit the WhereClause, as shown below.

The GetText function is taken from the IFormattedText help page example. 
 
Option Explicit
Sub ArcText()
    ' tested with USHighways shape file in layer(0)
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pGFLayer As IGeoFeatureLayer
    Set pGFLayer = pMxDoc.FocusMap.Layer(0)
    
    pGFLayer.AnnotationProperties.Clear

    Dim pLLP As ILineLabelPosition
    Set pLLP = New LineLabelPosition
    With pLLP
        .Above = False
        .AtEnd = False
        .Below = False
        .Horizontal = False
        .InLine = True
        .OnTop = True
        .Parallel = True
        .ProduceCurvedLabels = False
    End With
        
    Dim pLELP As ILabelEngineLayerProperties
    Set pLELP = New LabelEngineLayerProperties
    With pLELP
        Set .Symbol = GetTextSymbol
        .IsExpressionSimple = True
        .Expression = "[ADMN_CLASS]"
        .BasicOverposterLayerProperties.LineLabelPosition = pLLP
    End With
    
    Dim pALP As IAnnotateLayerProperties
    Set pALP = pLELP
    With pALP
        .DisplayAnnotation = True
        Set .FeatureLayer = pGFLayer
        .LabelWhichFeatures = esriVisibleFeatures
        ' omitting whereclause apparently makes it
        '"Label all features the same"
        '.WhereClause = "[ADMN_CLASS] = 'Interstate'"
    End With
    
    pGFLayer.AnnotationProperties.Add pLELP
    pGFLayer.DisplayAnnotation = True
    pMxDoc.ActiveView.Refresh
    
End Sub

Function GetTextSymbol() As ITextSymbol
    ' from the arcobjects help for IFormattedTextSymbol
    Dim myTxtSym As IFormattedTextSymbol
    Set myTxtSym = New TextSymbol
    
    '** Set the font for myTxtSym
    Dim myFont As IFontDisp
    Set myFont = New StdFont
    
    myFont.Name = "Courier New"
    myFont.Size = 8
    myTxtSym.Font = myFont
    
    '** Set the Color for myTxtSym to be Dark Red
    
    Dim myColor As IRgbColor
    Set myColor = New RgbColor
    
    myColor.Red = 150
    myColor.Green = 0
    myColor.Blue = 0
    
    myTxtSym.Color = myColor
    
    '** Set other properties for myTxtSym
    myTxtSym.Angle = 0
    myTxtSym.RightToLeft = False
    myTxtSym.VerticalAlignment = esriTVABaseline
    myTxtSym.HorizontalAlignment = esriTHAFull
    myTxtSym.CharacterSpacing = 20
    myTxtSym.Case = esriTCNormal
    Set GetTextSymbol = myTxtSym
End Function
 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/