1

Is there a method use ArcObjects for .NET to manipulate the "Only show classes that are visible in the current map extent" option for legend items?

The GUI for this functionality is accessible via the legend properties: enter image description here

I have read through the ESRI documentation for the interfaces supported by Legend, and ILegendItem3 but have not found anything relevant.

1
  • 1
    I forget if that limits. Is it the number of feature classes, or the legend items per feature class. Maybe IDynamicLegendItem.AutoVisibility is what you are looking for.
    – travis
    Commented Jul 29, 2013 at 8:12

1 Answer 1

1

Thanks Travis that did the trick.

The documentation ESRI provides for IDynamicLegendItem fails to list any CoClasses that implement, or methods that return this interface. This leaves it unclear how to access an an instance that provides an implementation of this interface.

After some trial and error I found the following technique works:

    Dim doc As IMxDocument = m_application.Document
    Dim map As IMap = doc.FocusMap

    Dim autoVisibility as Boolean= True

    Dim legend As Legend = Nothing

    For i As Integer = 0 To map.MapSurroundCount - 1
        If map.MapSurround(i).Name() = "Legend" Then
            legend = TryCast(map.MapSurround(i), Legend)
        End If
    Next

    If legend IsNot Nothing Then
        For i As Integer = 0 To legend.ItemCount - 1
            Dim item As IDynamicLegendItem = TryCast(legend.Item(i), IDynamicLegendItem)
            If item IsNot Nothing Then
                item.AutoVisibility = autoVisibility 
            End If
        Next
    End If

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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