1

I am able to create graphics and add them to the map, but they are getting added as the top-most layer.

The labels (if active) of another layer get hidden due to this. I want to know how to add graphics as the lowest layer in the active map.

EDIT 1: Here is the code which I am using to add graphics to the map

    Dim graphicsContainer As IGraphicsContainer
    graphicsContainer = GetRunningApplication(My.ArcMap.Application.Document.Title).FocusMap
    Dim elem As IElement
    Dim rgbcolor As IRgbColor
    Dim outlineRGBColor As IRgbColor

    elem = Nothing
    rgbcolor = New RgbColor

    If (g.GeometryType) = esriGeometryType.esriGeometryPoint Then
        ' Marker symbols
        Dim simpleMarkerSymbol As ISimpleMarkerSymbol
        simpleMarkerSymbol = New SimpleMarkerSymbol

        'set COlors
        rgbcolor.Blue = 255
        rgbcolor.Red = 0
        rgbcolor.Green = 0

        simpleMarkerSymbol.Color = rgbcolor
        simpleMarkerSymbol.Outline = True
        simpleMarkerSymbol.OutlineColor = rgbcolor 'outlineRGBColor
        If SymbolSize = 0 Then
            simpleMarkerSymbol.Size = 8
        Else
            simpleMarkerSymbol.Size = SymbolSize
        End If
        simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle

        Dim markerElement As IMarkerElement
        markerElement = New MarkerElement
        markerElement.Symbol = simpleMarkerSymbol
        elem = markerElement
    End If

    If g.GeometryType = esriGeometryType.esriGeometryPolyline Or g.GeometryType = esriGeometryType.esriGeometryLine Then
        '  Line elements
        Dim simpleLineSymbol As ISimpleLineSymbol
        simpleLineSymbol = New SimpleLineSymbol

        'set COlors
        rgbcolor.Blue = 0
        rgbcolor.Red = 255
        rgbcolor.Green = 0
        simpleLineSymbol.Color = rgbcolor
        simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid
        If SymbolSize <> 0 Then
            simpleLineSymbol.Width = SymbolSize
        Else
            simpleLineSymbol.Width = 2
        End If

        Dim le As ILineElement
        le = New LineElement
        le.Symbol = simpleLineSymbol
        elem = le  ' Explicit Cast
    End If

    If (g.GeometryType) = esriGeometryType.esriGeometryPolygon Then
        ' Polygon elements
        Dim simpleFillSymbol As ISimpleFillSymbol
        simpleFillSymbol = New SimpleFillSymbol

        'set COlors
        rgbcolor.Blue = 0
        rgbcolor.Red = 0
        rgbcolor.Green = 255
        simpleFillSymbol.Color = rgbcolor
        simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal
        Dim fillShapeElement As IFillShapeElement
        fillShapeElement = New PolygonElement
        fillShapeElement.Symbol = simpleFillSymbol
        elem = fillShapeElement
    End If
  • 1
    You've tagged this as an ArcObjects question, what is your code so far? – Hornbydd Apr 8 '15 at 14:38
  • Graphics typically override automatic labels or affect their placement, regardless of draw order. You may need to explore label weights/rankings. – Chris W Apr 8 '15 at 20:26
  • @Hornbydd I am able to add graphics on map based on geometry (Point, Line, Polygon). The graphics are visible on map as well, its just adding them at lowest level that i am not able to do – Swanand Apr 9 '15 at 10:50
1

When you say "...add graphics as the lowest layer in the active map" Are you trying to add graphics to an annotation group which is associated with a layer? When you turn that layer off then the graphic will disappear too so labels in other layers will show. Whilst that layer is visible the graphic would obscure the labels.

I think @Chris W is on the right track, if you want labels to always show even if you have drawn graphics on top of them then you need to change the properties of the labels for that particular layer.

Below is a sample of VBA that changes these properties for the first layer in the map. Once it has executed any labels covered by a graphic (I tested it with a polygon) should appear.

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

    ' Ensure all features will be labelled
    pAnnotateLayerProperties.LabelWhichFeatures = esriAllFeatures

    ' 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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