ajfitzgerald

Zooming to layer with definition query in a nested group

Discussion created by ajfitzgerald on Mar 31, 2011
Latest reply on Apr 11, 2011 by ajfitzgerald
I am trying to create a button on a toolbar that will add a layer files that contain layers that have definition queries and are in a nested group. Using some code snippets I found I was able to find my layer in the nested group and then have it zoom to the layer's extent with the definition query.

I am very new to programming and arcobjects so I don't think I am referencing the layer correctly in  the code snippet that zooms to the layer's extent with the definition query.

below is the code i have so far. The following is a link where I got the function to get the layer in the nested group:

http://forums.esri.com/Thread.asp?c=93&f=992&t=99138

When I execute the code it still zooms to the full extent of the layer and not the extent based on the definition query.

Does anyone know what I am doing wrong?


    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap
    Dim LayerName As String
    LayerName = "Rooms"
    Dim pLayer As ILayer

'this is the function I am using to get the layer i want in the nested group
    Set pLayer = GetLayerByName(pMap, LayerName, True)
   
'I think there is where I am referencing the layer incorrectly
    Dim featureLayer As IFeatureLayer
    Set featureLayer = pLayer
   

    Dim geoDataset As IGeoDataset
    Set geoDataset = featureLayer
    Dim activeView As IActiveView
    Set activeView = pMxDoc.FocusMap
    Dim geoFeatureLayer As IGeoFeatureLayer
    Set geoFeatureLayer = featureLayer
    Dim enumGeometryBind As IEnumGeometryBind
    Set enumGeometryBind = New EnumFeatureGeometry
    enumGeometryBind.BindGeometrySource Nothing, geoFeatureLayer.DisplayFeatureClass
    Dim geoFactory As IGeometryFactory
    Set geoFactory = New GeometryEnvironment
    Dim geometry As IGeometry
    Set geometry = geoFactory.CreateGeometryFromEnumerator(enumGeometryBind)
    activeView.Extent = geometry.Envelope
    activeView.Refresh

Outcomes