Friday 12 April 2019

arcgis 10.2 - Which interface controls 'Place overlapping labels' for a feature layer?


I need to turn on the option to 'Place overlapping labels' for a feature layer via ArcObjects. In the ArcMap UI it is located here:


enter image description here


I can get to most of the labeling options from the IAnnotateLayerProperties, ILabelEngineLayerProperties and IBasicOverposterLayerProperties interfaces.


The option to control overlapping labels seems to be missing.



Answer



The following VBA code demonstrates how to turn that property on:


Public Sub test()

' Get document
Dim pMXDocument As IMxDocument
Set pMXDocument = ThisDocument

' Get map
Dim pMap As IMap
Set pMap = pMXDocument.FocusMap

' Get first layer, assumed this is what you want to label
Dim pLayer As ILayer

Set pLayer = pMap.Layer(0)
Dim pGeoFeatureLayer As IGeoFeatureLayer
Set pGeoFeatureLayer = pLayer

' Ensure labels are visible
pGeoFeatureLayer.DisplayAnnotation = True

' Get Annotation properties collection
Dim pAnnotateLayerPropertiesCollection As IAnnotateLayerPropertiesCollection2
Set pAnnotateLayerPropertiesCollection = pGeoFeatureLayer.AnnotationProperties


' Get the annotation layer property
Dim pAnnotateLayerProperties As IAnnotateLayerProperties
Dim id As Long
pAnnotateLayerPropertiesCollection.QueryItem 0, pAnnotateLayerProperties, id

' Get label engine, do this by QI annotation layer property
Dim pLabelEngineLayerProperties As ILabelEngineLayerProperties2
Set pLabelEngineLayerProperties = pAnnotateLayerProperties


' Set overposter properties
Dim pBasicOverposterLayerProperties As IBasicOverposterLayerProperties4
Set pBasicOverposterLayerProperties = pLabelEngineLayerProperties.BasicOverposterLayerProperties
pBasicOverposterLayerProperties.GenerateUnplacedLabels = True
Dim pOverposterLayerProperties As IOverposterLayerProperties2
Set pOverposterLayerProperties = pLabelEngineLayerProperties.OverposterLayerProperties
pOverposterLayerProperties.TagUnplaced = False

' Refresh display
pMXDocument.ActiveView.Refresh

End Sub

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...