Select to view content in your preferred language

VB.NET:: Adding a layer to arcMap

3744
2
09-16-2010 05:54 AM
ChaitanyaKrishna
Emerging Contributor
Hi,
I have been trying to add a layer(.lyr) and i am unable to add it since i am a beginner in vb.net. After running it I can see only the TOC of the layer but not the image.
The code I have used is as follows.
Can someone correct my code.

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click      
'Obtain the object factory interface from the app
        Dim pObjFactory As IObjectFactory = CType(m_pApp, IObjectFactory)

        'Get a reference to the ArcMap document and the focus map
        Dim pMxDoc As IMxDocument = CType(m_pDoc, IMxDocument)
        Dim pMap As IMap = CType(pMxDoc.FocusMap, IMap)
        Call AddLayerFromFile(pMap, "G:\Deepak\map_mumbai_final.jpg.lyr")
End Sub

    Public Sub AddLayerFromFile(ByVal map As ESRI.ArcGIS.Carto.IMap, ByVal layerPathFile As String)
        'Create a new GxLayer.
        Dim gxLayerCls As ESRI.ArcGIS.Catalog.IGxLayer = New ESRI.ArcGIS.Catalog.GxLayer
        Dim gxFile As ESRI.ArcGIS.Catalog.IGxFile = gxLayerCls 'Implicit Cast.

        'Set the path for where the layer file is located on disk.
        gxFile.Path = layerPathFile

        'Test if you have a valid layer and add it to the map.
            map.AddLayer(gxLayerCls.Layer)
    End Sub
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Try refreshing the activeview after adding the layer:

Call AddLayerFromFile(pMap, "G:\Deepak\map_mumbai_final.jpg.lyr")
pMxDoc.UpdateContents 
pMxDoc.ActiveView.Refresh 
0 Kudos
ChaitanyaKrishna
Emerging Contributor
I tried but it not working still.
I have attached the image pf arcmap of what it looks like after the execution.
0 Kudos