HOW TO
This document describes one of two ways to mimic the functionality of the Auto-Label dialog box via Avenue's Labeler class. The other alternative is to use the TextPositioner Class, which is covered by the document in the Related Information section.
Code:
aView = av.GetActiveDoc
‘-- Theme to label must be the ACTIVE theme
aTheme = aView.GetActiveThemes.Get(0)
aExt = aView.GetDisplay.ReturnVisExtent
aLabeler = Labeler.Make(aExt)
'-- These weights are the defaults for a line theme.
aLabeler.SetFeatureWeight(#LABEL_WEIGHT_NO)
aLabeler.SetLabelWeight(#LABEL_WEIGHT_HIGH)
aLabeler.RemoveDuplicates(true)
'-- Set the textsymbol for the theme you are labeling
aTextSym = TextSymbol.Make
aTextSym.SetFont(Font.Make("Times","Bold"))
aTextSym.SetSize(8)
aTheme.SetLabelTextSym(aTextSym)
'-- This starts the labeling process and corresponds to
'-- the first status bar you see on the application window.
aLabeler.Load(aTheme)
'-- Get the Labels from the labeler (corresponds to
'-- the second status bar you see on the application window)
'-- and draw them on the view.
'-- The GetAutoLabels request automatically adds
'-- the new labels to the aView's GraphicList
'-- and aTheme's GraphicSet.
aView.GetAutoLabels(aLabeler, false)
Code:
‘Example code below
theView = av.GetActiveDoc
theGraphics=theView.GetGraphics
States1 = theView.FindTheme("States1")
States2 = theView.FindTheme("States2")
States3 = theView.FindTheme("States3")
States1.SetActive(true)
States2.SetActive(true)
States3.SetActive(true)
‘-- Set the textSymbol of all the themes to be labeled,
'-- it needs to be large enough to be useful for all
'-- themes, since that textSymbol is initially used
'-- for all themes. The reason you need to do this is that
'-- there is a bug with setting the textSymbol for any
‘-- other theme to be different that causes ArcView to crash.
aTextSym = TextSymbol.Make
aTextSym.SetFont(Font.Make("Arial","Bold"))
aTextSym.SetSize(12)
States1.SetLabelTextSym(aTextSym)
States2.SetLabelTextSym(aTextSym)
States3.SetLabelTextSym(aTextSym)
‘-- Make the labeler object and set the extent that is to
'-- be labeled. This example uses the entire view's extent.
'-- You might want to use theView.GetDisplay.ReturnVisExtent
‘-- to label just the visible extent of the view.
anExt = theView.ReturnExtent
aLabeler = Labeler.Make(anExt)
‘-- As each of the themes are loaded into the labeler object,
'-- their feature and label weights may need to be set in
'-- order to create the most appropriate result.
aLabeler.SetFeatureWeight(#LABEL_WEIGHT_HIGH)
aLabeler.SetLabelWeight(#LABEL_WEIGHT_HIGH)
aLabeler.RemoveDuplicates(true)
aLabeler.Load(States1)
aLabeler.Load(States2)
aLabeler.Load(States3)
theView.GetAutoLabels(aLabeler, false)
‘-- Due to a known issue, the textSymbols for each theme are not
'-- honored during the label placement process, so here is
'-- a the workaround to this. Note, that the size of labels
‘-- are not accounted for here, so be careful about setting
'-- a theme's labels to be a larger size as conflicts may rise.
aTextSym2 = TextSymbol.Make
aTextSym2.SetFont(Font.Make("Arial","Normal"))
aTextSym2.SetSize(10)
theView.GetDisplay.HookUpSymbol(aTextSym2)
States1.SetLabelTextSym(aTextSym2)
thedeleteList = {}
theGraphics.UnSelectAll
for each sLabel in States1.GetGraphics
thedeleteList.Add(sLabel.clone)
sLabel.SetSelected(true)
end
theGraphics.ClearSelected
aStateGTS = {}
for each oldGL in thedeleteList
aString = oldGL.GetText
aPoint = oldGL.GetBounds.ReturnOrigin
anAngle = oldGL.GetAngle
newGL = GraphicLabel.MakeWithSym ( aString, aPoint, aTextSym2, aStateGTS )
newGL.SetAngle(anAngle)
theGraphics.addbatch(newGL)
end
aTextSym3 = TextSymbol.Make
aTextSym3.SetFont(Font.Make("Arial","Italic"))
aTextSym3.SetSize(10)
aTextSym3.SetColor(Color.GetBlue)
theView.GetDisplay.HookUpSymbol(aTextSym3)
theDeleteList = {}
theGraphics.UnSelectAll
for each s2Label in States3.GetGraphics
theDeleteList.Add(s2Label.Clone)
s2Label.SetSelected(true)
end
for each s3Label in States2.GetGraphics
theDeleteList.Add(s3Label.clone)
s3Label.SetSelected(true)
end
theGraphics.ClearSelected
aState2GTS = {}
for each oldGL in thedeleteList
aString = oldGL.GetText
aPoint = oldGL.GetBounds.ReturnOrigin
anAngle = oldGL.GetAngle
newGL = GraphicLabel.MakeWithSym ( aString, aPoint, aTextSym3, aState2GTS )
newGL.SetAngle(anAngle)
theGraphics.AddBatch(newGL)
end
theGraphics.EndBatch
Article ID:000002587
Get help from ArcGIS experts
Download the Esri Support App