HOW TO
The code sample provided can be used to keep the top layer turned on. It is possible to customize it to work with another layer. This essentially disables turning off the layer.
Note:
Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all your map documents open the Normal.mxt ThisDocument code module instead.
Code:
Dim m_pMxDoc As IMxDocument
Dim m_pMap As IMap
Dim m_pLayer As ILayer
Dim WithEvents m_pLyrEvents As FeatureLayer
Private WithEvents m_pActiveViewEvents As Map
Private Function MxDocument_OpenDocument() As Boolean
Set m_pMxDoc = Application.Document
Set m_pMap = m_pMxDoc.FocusMap
Set m_pLyrEvents = m_pMap.Layer(0) 'change this number if you wish to work with a different layer
Set m_pActiveViewEvents = m_pMxDoc.FocusMap
End Function
Private Sub m_pActiveViewEvents_ViewRefreshed(ByVal view As esriCarto.IActiveView, _
ByVal phase As esriCarto.esriViewDrawPhase, ByVal data As Variant, ByVal envelope As esriGeometry.IEnvelope)
Set m_pLayer = m_pLyrEvents
m_pLayer.Visible = True
End Sub
Private Sub m_pLyrEvents_VisibilityChanged(ByVal currentState As Boolean)
Set m_pLayer = m_pLyrEvents
If currentState = False Then
m_pLayer.Visible = True
m_pMxDoc.UpdateContents
Exit Sub
Else
Exit Sub
End If
End Sub
Sub StopListening()
Set m_pLyrEvents = Nothing
Set m_pActiveViewEvents = Nothing
End Sub
Get help from ArcGIS experts
Download the Esri Support App