FAQ
ArcObjects でレイヤーの表示/非表示を変更する方法

ナレッジ番号:5291 | 登録日:2023/07/26 | 更新日:2023/12/28

概要

ArcObjects でレイヤーの表示を変更するためのサンプル コードを紹介します。

サンプル コード

アクティブデータフレームのすべてのレイヤーを非表示にする

Dim pMxDocument As IMxDocument = My.ArcMap.Document
Dim pLayer As ILayer
Dim i As Integer

'アクティブなデータフレームを取得します。
Dim pMaps = pMxDocument.Maps
Dim pMap As IMap = My.ArcMap.Document.FocusMap

'全てのレイヤーをループ処理し、非表示に設定します。
For i = 0 To pMap.LayerCount - 1
    pLayer = pMap.Layer(i)
    pLayer.Visible = False
Next i

'ビューを再描画します。
pMxDocument.ActiveView.Refresh()

'コンテンツ ウィンドウを再描画します。
pMxDocument.UpdateContents()

アクティブデータフレームのすべてのレイヤーの表示を切り替える

Dim pMxDocument As IMxDocument = My.ArcMap.Document
Dim pLayer As ILayer
Dim i As Integer

'アクティブなデータフレームを取得します。
Dim pMaps = pMxDocument.Maps
Dim pMap As IMap = My.ArcMap.Document.FocusMap

'全てのレイヤーをループ処理し、表示を切り替えます。
For i = 0 To pMap.LayerCount - 1
    pLayer = pMap.Layer(i)
    If pLayer.Visible Then
        pLayer.Visible = False
    Else
        pLayer.Visible = True
    End If
Next i

'ビューを再描画します。
pMxDocument.ActiveView.Refresh()

'コンテンツ ウィンドウを再描画します。
pMxDocument.UpdateContents()

メタデータ

種類

製品