Select to view content in your preferred language

Set Expression to DisplayField

615
3
12-23-2010 12:28 AM
karinweixler
New Contributor II
Hello,

i am trying to migrate VB.net Code from AG 9.3 to AG 10.
In AG 9.3 this Code worked for setting the label options for the DisplayField of a FeatueLayer (it was set as the label field for the labels):
aoiFeatureLayer.DisplayField = "w_Dat_Flurstueck.FlurNr] & ""/"" & [w_Dat_Flurstueck.FlurNr2"

In AG 10 this code is not working anymore.
I found this new Way to set an expression to the DisplayField:

Dim pDEP As IDisplayExpressionProperties
Dim pIDS As IDisplayString
pIDS = aoiFeatureLayer
pDEP = pIDS.ExpressionProperties
pDEP.Expression = "[w_Dat_Flurstueck.FlurNr] & ""/"" & [w_Dat_Flurstueck.FlurNr2]"

The Problem i am having, is that the exrpession for the layer is only set to the (new) Display Field in the Display Tab in the properties of the layer but not to the Label Field in the Labels Tab. Here is still the standard Field as Label Field.
Is there a different way to set the Label Field for the Labels?

Thanks for helping.

Karin
0 Kudos
3 Replies
VivekPrasad
Occasional Contributor
Hello,

i am trying to migrate VB.net Code from AG 9.3 to AG 10.
In AG 9.3 this Code worked for setting the label options for the DisplayField of a FeatueLayer (it was set as the label field for the labels):
aoiFeatureLayer.DisplayField = "w_Dat_Flurstueck.FlurNr] & ""/"" & [w_Dat_Flurstueck.FlurNr2"

In AG 10 this code is not working anymore.
I found this new Way to set an expression to the DisplayField:

Dim pDEP As IDisplayExpressionProperties
Dim pIDS As IDisplayString
pIDS = aoiFeatureLayer
pDEP = pIDS.ExpressionProperties
pDEP.Expression = "[w_Dat_Flurstueck.FlurNr] & ""/"" & [w_Dat_Flurstueck.FlurNr2]"

The Problem i am having, is that the exrpession for the layer is only set to the (new) Display Field in the Display Tab in the properties of the layer but not to the Label Field in the Labels Tab. Here is still the standard Field as Label Field.
Is there a different way to set the Label Field for the Labels?

Thanks for helping.

Karin


Hi,

Please try the below sample code

Sub LabelingFeatures(ByVal pLayer As ILayer, ByVal strFName1 As String, ByVal strFName2 As String)
   
        Dim pGeoLayer As IGeoFeatureLayer
        Set pGeoLayer = pLayer

        Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
        Set pAnnoLayerPropsColl = pGeoLayer.AnnotationProperties

        Dim pAnnoLayerProps As IAnnotateLayerProperties
        pAnnoLayerPropsColl.Clear

        Dim pBOLayerProps As IBasicOverposterLayerProperties
        Set pBOLayerProps = New BasicOverposterLayerProperties

        pBOLayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon
        pBOLayerProps.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape
        pBOLayerProps.FeatureWeight = esriBasicOverposterWeight.esriNoWeight
        pBOLayerProps.LabelWeight = esriBasicOverposterWeight.esriLowWeight

        Dim tSym As ITextSymbol
        Set tSym = New TextSymbol
        Dim font As IFontDisp
        Set font = tSym.font
        font.Bold = False
        font.size = 6
        tSym.font = font

        Dim aLELayerProps As ILabelEngineLayerProperties
        Set aLELayerProps = New LabelEngineLayerProperties

        aLELayerProps.Expression = "[" & strFName1 & "]" & ""/"" & "[" & strFName2 & "]"

       
        Set aLELayerProps.Symbol = tSym
        Set aLELayerProps.BasicOverposterLayerProperties = pBOLayerProps


        Set pAnnoLayerProps = aLELayerProps
        pAnnoLayerProps.Class = "<any Name>"
        'pAnnoLayerProps.WhereClause = pSqlString 'You can filter features by using this statement

        pAnnoLayerPropsColl.Add pAnnoLayerProps

        pGeoLayer.DisplayAnnotation = True
End Sub
0 Kudos
karinweixler
New Contributor II
Thanks a lot! This works just fine!
0 Kudos
VivekPrasad
Occasional Contributor
Thanks a lot! This works just fine!


Thank you! Glad to know that the code helped.
0 Kudos