I can set up a handler to catch the VisibilityChanged event of every map layer returned by:

pEnumLayer As IEnumLayer = My.ArcMap.Document.ActiveView.FocusMap.Layers(Nothing, False)

Then with each layer returned this works:

pLayerEvents As ILayerEvents_Event = pMapLayerReturned

Unless the layer is a TopologyLayer. If it is a TopologyLayer it's an invalid cast. It appears that TopologyLayer class doesn't use ILayerEvents. How then can I tell when the visibility of a TopologyLayer changes?


I can see no event listener for TopologyLayer but you can trap when a change in visibility has occurred by listening to the map refresh view event. Below is the VBA code that will achieve this.

You must first run setup() so mapEve object is set and the Topology layer is the top layer.

Dim WithEvents mapEve As Map

Public Sub setup()
    ' Run this procedure to ensure mapEve is initialised
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    Set mapEve = pMxDocument.FocusMap
End Sub

Private Sub mapEve_ViewRefreshed(ByVal View As esriCarto.IActiveView, ByVal phase As esriCarto.esriViewDrawPhase, ByVal Data As Variant, ByVal envelope As esriGeometry.IEnvelope)
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDocument.FocusMap
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0) ' This is the topology layer
    If pLayer.Visible = True Then
        MsgBox "vis on"
        MsgBox "vis off"
    End If
End Sub
  • Thanks for the ideas Hornbydd. This is close to what I need; I just need to limit the "do stuff" to ONLY happen if the specific layer changes visibility. If I cast the ViewRefreshed parameter Data to ILayer, I get the layer which is getting refreshed and can then do stuff only if it is my topology layer. The problem I have now is that a specific layer not only gets refreshed when its visibility changes, it also gets refreshed when it is reordered in the TOC, and this refresh I don't want to fire anything. I'll have to see if I can filter this reorder refresh out somehow... – Dan Jurgella Apr 20 '15 at 18:16

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.