Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to add a white halo to labels using arcobjects. I think I need to reference the IFormattedTextSymbol interface, but I'm not sure how to implement this into my current code (see below). Thank you for your help.

Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap
' Get the selected layer
Dim pLayer As IGeoFeatureLayer
Set pLayer = pMap.Layer(0)

Dim pFc As IFeatureClass
Dim strOIDName As String
Set pFc = pLayer.FeatureClass
strOIDName = pFc.OIDFieldName

' Get the selected features from the layer
Dim pFSel As IFeatureSelection
Set pFSel = pLayer
Dim pSelSet As ISelectionSet
Set pSelSet = pFSel.SelectionSet
Dim pFCur As IFeatureCursor
pSelSet.Search Nothing, False, pFCur

' Loop through the selected features and create a label
' expression for the selected features

Dim pFeat As IFeature
Dim strSql As String
Set pFeat = pFCur.NextFeature

Do While Not pFeat Is Nothing
   If strSql = "" Then
     strSql = strOIDName & " = " & pFeat.OID
   Else
     strSql = strSql & " or " & strOIDName & " = " & pFeat.OID
   End If
   Set pFeat = pFCur.NextFeature
Loop
Debug.Print strSql

' Get AnnotateLayerPropertiesCollection from layer
Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
Set pAnnoLayerPropsColl = pLayer.AnnotationProperties
Dim pAnnoLayerProps As IAnnotateLayerProperties
pAnnoLayerPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
pAnnoLayerProps.Class = "LabelSel"
pAnnoLayerProps.WhereClause = strSql
Dim aAnnoVBScriptEngine As IAnnotationExpressionEngine
Set aAnnoVBScriptEngine = New AnnotationVBScriptEngine

Dim pTextsymbol As ITextSymbol
Set pTextsymbol = New TextSymbol

Dim pFont As IFontDisp
Set pFont = pTextsymbol.font

Dim pFormattedtxtsym As IFormattedTextSymbol
pFormattedtxtsym.ShadowColor = True

pFont.Bold = True
pFont.size = 10
pFont.Weight = 2
pTextsymbol.font = pFont

Dim pLELayerProps As ILabelEngineLayerProperties
Set pLELayerProps = pAnnoLayerProps
Set pLELayerProps.ExpressionParser = aAnnoVBScriptEngine

pLELayerProps.Expression = "[Longlabel] & vbnewline & [Latlabel] & vbnewline & [Elevlabel] & _ vbnewline &[Driftlabel]"

Set pLELayerProps.Symbol = pTextsymbol

' Display the lables
pLayer.DisplayAnnotation = True
' Refresh the Data Frame
pDoc.ActiveView.Refresh 
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Halos are specified through the IMask interface which the TextSymbol class implements:

Dim pMask As IMask
Dim pMaskFillSymbol As IFillSymbol
Dim pMaskFillColor As IRgbColor

Set pMask = pTextSymbol ' your textsymbol
pMask.MaskStyle = esriMSHalo
pMask.MaskSize = 1  ' halo size

' red halo around text, modify to your desired color
Set pMaskFillSymbol = New SimpleFillSymbol
Set pMaskFillColor = New RgbColor
pMaskFillColor.Red = 255
pMaskFillColor.Green = 0
pMaskFillColor.Blue = 0
pMaskFillSymbol.Color = pMaskFillColor

Set pMask.MaskSymbol = pMaskFillSymbol
share|improve this answer
    
Thanks for your reply. I updated my code. The halo properties are updated now however the label/annotation is not updating. –  artwork21 Jan 19 '11 at 17:38
    
I updated the code slightly (the Dim declarations were missing). –  Petr Krebs Jan 19 '11 at 17:47
    
Not sure what the problem is though. I used your code exactly to every line with only few changes (got rid of IFormattedTextSymbol, added the above snippet after the initialization of the text symbol, changed the label expression to different fields) and works fine.. –  Petr Krebs Jan 19 '11 at 17:50
    
Yes, I too added the Dims and posted the snippet below: –  artwork21 Jan 19 '11 at 17:59
    
below the: "pTextsymbol.font = pFont", but still not sure why the label/annotation is not updating also. –  artwork21 Jan 19 '11 at 18:00
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.