Setting LineLabelPosition properties doesn't work

598
2
02-12-2013 12:16 PM
LimingWu
New Contributor II
Please Help!!!

I'm trying to set the label placement properties for a newly created polyline layer in my code.  However, LineLabelPosition properties are not working. My code looks like this:

    Private Sub CreateLabels(ByRef layer As IGeoFeatureLayer)

        Dim labelClasses As IAnnotateLayerPropertiesCollection
        labelClasses = layer.AnnotationProperties

        Dim labelClass As IAnnotateLayerProperties = Nothing
        labelClasses.QueryItem(0, labelClass, Nothing, Nothing)

        Dim label1 As ILabelEngineLayerProperties = labelClass
        CType(label1, IAnnotateLayerProperties).Class = "Label at start"
        CType(label1, IAnnotateLayerProperties).DisplayAnnotation = True
        label1.Expression = "[Line_Name]"

        Dim overposterLayerProperties As IBasicOverposterLayerProperties4
        overposterLayerProperties = label1.BasicOverposterLayerProperties
        overposterLayerProperties.LineLabelPosition.Above = False
        overposterLayerProperties.LineLabelPosition.OnTop = True
        overposterLayerProperties.LineLabelPosition.Below = False
        overposterLayerProperties.LineLabelPosition.AtStart = True
        overposterLayerProperties.LineLabelPosition.InLine = False
        overposterLayerProperties.LabelWeight = 3
        overposterLayerProperties.FeatureWeight = 3

    End Sub


Thanks
Tags (2)
0 Kudos
2 Replies
LimingWu
New Contributor II
Hi folks,

By instantiating a new LineLabelPosition class, I've made the properties set correctly in label placement properties dialog now.

However, labels are not showing up automatically for my layer. I have to go to the Layer Properties dialog, simply open the Placement Properties dialog and click OK to close it, and click Apply to make the labels show up.

I've searched the forums and found that people had the same problem back in 2003. Since ESRI is so great in helping our community, I wouldn't believe that the problem has not been solved after 10 years. I must have missed something simple. Please help! my code looks like this now:

Private Sub CreateLabels(ByRef layer As IGeoFeatureLayer)

Dim labelClasses As IAnnotateLayerPropertiesCollection
labelClasses = layer.AnnotationProperties

Dim labelClass As IAnnotateLayerProperties = Nothing
labelClasses.QueryItem(0, labelClass, Nothing, Nothing)

Dim label1 As ILabelEngineLayerProperties = labelClass
CType(label1, IAnnotateLayerProperties).Class = "Label at start"
CType(label1, IAnnotateLayerProperties).DisplayAnnotation = True
label1.Expression = "[Line_Name]"

Dim overposterLayerProperties As IBasicOverposterLayerProperties4
overposterLayerProperties = label1.BasicOverposterLayerProperties

Dim label1Position As ILineLabelPosition = New LineLabelPosition()
label1Position.Above = False
label1Position.OnTop = True
label1Position.AtStart = True
overposterLayerProperties.LineLabelPosition = label1Position

overposterLayerProperties.LabelWeight = 3
overposterLayerProperties.FeatureWeight = 3

End Sub


Thanks
0 Kudos
LimingWu
New Contributor II
And the anwser is to set all other properties in LineLabelPosition class explicitly to False.
0 Kudos